]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fixes tests using called_once_ without assert
authorMiguel Angel Ajo <mangelajo@redhat.com>
Mon, 31 Mar 2014 13:50:55 +0000 (15:50 +0200)
committerMiguel Angel Ajo <mangelajo@redhat.com>
Wed, 2 Apr 2014 19:34:18 +0000 (21:34 +0200)
A few tests were using mock's called_once, or called_once_with_args
instead of assert_called_once or assert_called_once_with_args. Those
methods return a bool that needs to be actively checked.

The tests are fixed to avoid them from passing if the call condition
is not met.

Change-Id: I21e5257b26b2a08cc8f0b108233d1d5cc0b97b89
Closes-bug: #1297875

neutron/tests/unit/agent/linux/test_async_process.py
neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py
neutron/tests/unit/test_db_migration.py
neutron/tests/unit/test_dhcp_agent.py
neutron/tests/unit/test_metadata_agent.py
neutron/tests/unit/test_post_mortem_debug.py

index d56ad38b9ef3696faca683aa906083a40cf35478..c26236b9a1601a664ff4fabb6f2a8319ed732de1 100644 (file)
@@ -244,7 +244,7 @@ class TestAsyncProcess(base.BaseTestCase):
         self.proc._kill_event = True
         with mock.patch.object(self.proc, '_kill') as mock_kill:
             self.proc.stop()
-        mock_kill.called_once()
+        mock_kill.assert_called_once_with()
 
     def test_stop_raises_exception_if_already_started(self):
         with testtools.ExpectedException(async_process.AsyncProcessException):
index f27f173ede96d078b4238920686d5c980bb4632d..085b02ea1665a2a934e1379144779883b4ccbbfb 100644 (file)
@@ -689,7 +689,7 @@ class TestOvsNeutronAgent(base.BaseTestCase):
                 self.agent.daemon_loop()
         mock_get_pm.assert_called_with(True, 'sudo',
                                        constants.DEFAULT_OVSDBMON_RESPAWN)
-        mock_loop.called_once()
+        mock_loop.assert_called_once_with(polling_manager=mock.ANY)
 
     def test_setup_tunnel_port_error_negative(self):
         with contextlib.nested(
index 9147a6701251eb9f82a50e1188f6a4c668f0bfc1..2cd489a1e5831f1794ababdf763b7c67a2c8f15d 100644 (file)
@@ -181,5 +181,5 @@ class TestCli(base.BaseTestCase):
                 mock_open.return_value.__exit__ = mock.Mock()
 
                 cli.update_head_file(mock.sentinel.config)
-                mock_open.write.called_once_with('a')
+                mock_open.return_value.write.assert_called_once_with('a')
             fc.assert_called_once_with(mock.sentinel.config)
index 1275e64febbbb8054aaeab778d47dd36c987fed3..58836e8e206d5693ba1064b7a47bcd7bab24f53f 100644 (file)
@@ -718,7 +718,7 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
         self.plugin.get_network_info.return_value = network
         with mock.patch.object(self.dhcp, 'disable_dhcp_helper') as disable:
             self.dhcp.refresh_dhcp_helper(network.id)
-            disable.called_once_with_args(network.id)
+            disable.assert_called_once_with(network.id)
             self.assertFalse(self.cache.called)
             self.assertFalse(self.call_driver.called)
             self.cache.assert_has_calls(
@@ -1299,14 +1299,14 @@ class TestDeviceManager(base.BaseTestCase):
         expected = ('dhcp1ae5f96c-c527-5079-82ea-371a01645457-12345678-1234-'
                     '5678-1234567890ab')
 
-        with mock.patch('socket.gethostbyname') as get_host:
+        with mock.patch('socket.gethostname') as get_host:
             with mock.patch('uuid.uuid5') as uuid5:
                 uuid5.return_value = '1ae5f96c-c527-5079-82ea-371a01645457'
                 get_host.return_value = 'localhost'
 
                 dh = dhcp.DeviceManager(cfg.CONF, cfg.CONF.root_helper, None)
-                uuid5.called_once_with(uuid.NAMESPACE_DNS, 'localhost')
                 self.assertEqual(dh.get_device_id(fake_net), expected)
+                uuid5.assert_called_once_with(uuid.NAMESPACE_DNS, 'localhost')
 
     def _get_device_manager_with_mock_device(self, conf, device):
             dh = dhcp.DeviceManager(conf, cfg.CONF.root_helper, None)
index a87cdfd3f9d2192e90b8554817b6a198c0a59c7d..6f7f926acd06042749d52a6c9c07ea28ce644fb1 100644 (file)
@@ -319,12 +319,12 @@ class TestUnixDomainWSGIServer(base.BaseTestCase):
         with mock.patch.object(agent, 'logging') as logging:
             self.server._run('app', 'sock')
 
-            self.eventlet.wsgi.server.called_once_with(
+            self.eventlet.wsgi.server.assert_called_once_with(
                 'sock',
                 'app',
-                self.server.pool,
-                agent.UnixDomainHttpProtocol,
-                mock.ANY
+                protocol=agent.UnixDomainHttpProtocol,
+                log=mock.ANY,
+                custom_pool=self.server.pool
             )
             self.assertTrue(len(logging.mock_calls))
 
index ffef668bb05dd6727f219787c43c5b03373b80e8..0379342423ea2c0582bc762b4a15078ac12504e8 100644 (file)
@@ -38,8 +38,10 @@ class TestTesttoolsExceptionHandler(base.BaseTestCase):
                                        return_value=mock.Mock()):
                     post_mortem_debug.exception_handler(exc_info)
 
-        mock_print_exception.called_once_with(*exc_info)
-        mock_post_mortem.called_once()
+        # traceback will become post_mortem_debug.FilteredTraceback
+        filtered_exc_info = (exc_info[0], exc_info[1], mock.ANY)
+        mock_print_exception.assert_called_once_with(*filtered_exc_info)
+        mock_post_mortem.assert_called_once_with(mock.ANY)
 
 
 class TestFilteredTraceback(base.BaseTestCase):