Browse Source

Fix wrong assertions in unit tests

Change-Id: I54dff4d5ed513690d0fae65de47a1a9c23aebbd4
Closes-Bug: #1840601
(cherry picked from commit 8ea5e37338)
tags/19.0.3
Takashi NATSUME 2 months ago
parent
commit
88b2206f2d

+ 1
- 1
nova/tests/unit/cmd/test_baseproxy.py View File

@@ -63,7 +63,7 @@ class BaseProxyTestCase(test.NoDBTestCase):
63 63
                    mock_exists):
64 64
         baseproxy.proxy('0.0.0.0', '6080')
65 65
         mock_log.assert_called_once_with(baseproxy.CONF, 'nova')
66
-        mock_gmr.mock_assert_called_once_with(version)
66
+        mock_gmr.assert_called_once_with(version, conf=baseproxy.CONF)
67 67
         mock_init.assert_called_once_with(
68 68
             listen_host='0.0.0.0', listen_port='6080', source_is_ipv6=False,
69 69
             cert='self.pem', key=None, ssl_only=False,

+ 8
- 6
nova/tests/unit/virt/ironic/test_driver.py View File

@@ -1919,9 +1919,10 @@ class IronicDriverTestCase(test.NoDBTestCase):
1919 1919
         mock_sp.side_effect = [ironic_exception.BadRequest(), None]
1920 1920
 
1921 1921
         self._test_power_off(timeout=30)
1922
-        mock_sp.assert_has_calls([mock.call(node.uuid, 'off', soft=True,
1923
-                                            timeout=30).
1924
-                                  mock.call(node.uuid, 'off')])
1922
+        expected_calls = [mock.call(node.uuid, 'off', soft=True, timeout=30),
1923
+                          mock.call(node.uuid, 'off')]
1924
+        self.assertEqual(len(expected_calls), mock_sp.call_count)
1925
+        mock_sp.assert_has_calls(expected_calls)
1925 1926
 
1926 1927
     @mock.patch.object(ironic_driver.IronicDriver,
1927 1928
                        '_validate_instance_and_node')
@@ -1931,9 +1932,10 @@ class IronicDriverTestCase(test.NoDBTestCase):
1931 1932
         fake_validate.side_effect = [node, node]
1932 1933
 
1933 1934
         self._test_power_off(timeout=30)
1934
-        mock_sp.assert_has_calls([mock.call(node.uuid, 'off', soft=True,
1935
-                                            timeout=30).
1936
-                                  mock.call(node.uuid, 'off')])
1935
+        expected_calls = [mock.call(node.uuid, 'off', soft=True, timeout=30),
1936
+                          mock.call(node.uuid, 'off')]
1937
+        self.assertEqual(len(expected_calls), mock_sp.call_count)
1938
+        mock_sp.assert_has_calls(expected_calls)
1937 1939
 
1938 1940
     @mock.patch.object(FAKE_CLIENT.node, 'vif_attach')
1939 1941
     def test_plug_vifs_with_port(self, mock_vatt):

+ 12
- 9
nova/tests/unit/virt/vmwareapi/test_vmops.py View File

@@ -2830,15 +2830,16 @@ class VMwareVMOpsTestCase(test.NoDBTestCase):
2830 2830
         self._vmops.attach_interface(self._context, self._instance,
2831 2831
                                      self._image_meta, self._network_values)
2832 2832
         mock_get_vm_ref.assert_called_once_with(self._session, self._instance)
2833
-        mock_get_attach_port_index(self._session, 'fake-ref')
2833
+        mock_get_attach_port_index.assert_called_once_with(self._session,
2834
+                                                           'fake-ref')
2834 2835
         mock_get_network_attach_config_spec.assert_called_once_with(
2835 2836
             self._session.vim.client.factory, vif_info, 1,
2836 2837
             extra_specs.vif_limits)
2837 2838
         mock_reconfigure_vm.assert_called_once_with(self._session,
2838 2839
                                                     'fake-ref',
2839 2840
                                                     'fake-attach-spec')
2840
-        _network_api.update_instance_vnic_index(mock.ANY,
2841
-            self._instance, self._network_values, 1)
2841
+        _network_api.update_instance_vnic_index.assert_called_once_with(
2842
+            mock.ANY, self._instance, self._network_values, 1)
2842 2843
 
2843 2844
     @mock.patch.object(vif, 'get_network_device', return_value='device')
2844 2845
     @mock.patch.object(vm_util, 'reconfigure_vm')
@@ -2859,14 +2860,15 @@ class VMwareVMOpsTestCase(test.NoDBTestCase):
2859 2860
             self._vmops.detach_interface(self._context, self._instance,
2860 2861
                                          self._network_values)
2861 2862
         mock_get_vm_ref.assert_called_once_with(self._session, self._instance)
2862
-        mock_get_detach_port_index(self._session, 'fake-ref')
2863
+        mock_get_detach_port_index.assert_called_once_with(self._session,
2864
+                                                           'fake-ref', None)
2863 2865
         mock_get_network_detach_config_spec.assert_called_once_with(
2864 2866
             self._session.vim.client.factory, 'device', 1)
2865 2867
         mock_reconfigure_vm.assert_called_once_with(self._session,
2866 2868
                                                     'fake-ref',
2867 2869
                                                     'fake-detach-spec')
2868
-        _network_api.update_instance_vnic_index(mock.ANY,
2869
-            self._instance, self._network_values, None)
2870
+        _network_api.update_instance_vnic_index.assert_called_once_with(
2871
+            mock.ANY, self._instance, self._network_values, None)
2870 2872
 
2871 2873
     @mock.patch.object(vm_util, 'get_vm_ref', return_value='fake-ref')
2872 2874
     def test_get_mks_console(self, mock_get_vm_ref):
@@ -2937,12 +2939,13 @@ class VMwareVMOpsTestCase(test.NoDBTestCase):
2937 2939
                                      self._image_meta,
2938 2940
                                      self._network_values)
2939 2941
         mock_get_vm_ref.assert_called_once_with(self._session, self._instance)
2940
-        mock_get_attach_port_index(self._session, 'fake-ref')
2942
+        mock_get_attach_port_index.assert_called_once_with(self._session,
2943
+                                                           'fake-ref')
2941 2944
         mock_get_network_attach_config_spec.assert_called_once_with(
2942 2945
             self._session.vim.client.factory, vif_info, 1,
2943 2946
             extra_specs.vif_limits)
2944 2947
         mock_reconfigure_vm.assert_called_once_with(self._session,
2945 2948
                                                     'fake-ref',
2946 2949
                                                     'fake-attach-spec')
2947
-        _network_api.update_instance_vnic_index(mock.ANY,
2948
-            self._instance, self._network_values, 1)
2950
+        _network_api.update_instance_vnic_index.assert_called_once_with(
2951
+            mock.ANY, self._instance, self._network_values, 1)

Loading…
Cancel
Save