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
(cherry picked from commit
c6c4a20777921dc1b21e80edb96ccd957a054c68)
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):
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(
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)
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(
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)
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))
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):