From: Kevin Benton Date: Mon, 19 May 2014 06:58:58 +0000 (+0000) Subject: Fix non-existent 'assert' calls to mocks X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0ff8536c0d9b95172c42b1a01d292df58ed2e573;p=openstack-build%2Fneutron-build.git Fix non-existent 'assert' calls to mocks Fixes calls to non-existent 'assert' methods called on mock objects. Closes-Bug: #1320774 Change-Id: I7eab28fc9b23cbb39d5507ff3e8004a493c90bed --- diff --git a/neutron/tests/unit/agent/linux/test_async_process.py b/neutron/tests/unit/agent/linux/test_async_process.py index c26236b9a..ea4243030 100644 --- a/neutron/tests/unit/agent/linux/test_async_process.py +++ b/neutron/tests/unit/agent/linux/test_async_process.py @@ -73,7 +73,7 @@ class TestAsyncProcess(base.BaseTestCase): kill.assert_has_calls(mock.call(respawning=True)) sleep.assert_has_calls(mock.call(self.proc.respawn_interval)) - spawn.assert_called_once() + spawn.assert_called_once_with() def _test__watch_process(self, callback, kill_event): self.proc._kill_event = kill_event @@ -84,7 +84,7 @@ class TestAsyncProcess(base.BaseTestCase): self.proc._watch_process(callback, kill_event) if not kill_event.ready(): - func.assert_called_once() + func.assert_called_once_with() def test__watch_process_exits_on_callback_failure(self): self._test__watch_process(lambda: False, eventlet.event.Event()) @@ -128,7 +128,7 @@ class TestAsyncProcess(base.BaseTestCase): with mock.patch.object(self.proc, '_spawn') as mock_start: self.proc.start() - mock_start.assert_called_once() + mock_start.assert_called_once_with() def test__iter_queue_returns_empty_list_for_empty_queue(self): result = list(self.proc._iter_queue(eventlet.queue.LightQueue())) @@ -170,9 +170,9 @@ class TestAsyncProcess(base.BaseTestCase): else: self.assertIsNone(self.proc._kill_event) - mock_kill_event.send.assert_called_once() + mock_kill_event.send.assert_called_once_with() if pid: - mock_kill_process.assert_called_once(pid) + mock_kill_process.assert_called_once_with(pid) def test__kill_when_respawning_does_not_clear_kill_event(self): self._test__kill(True) diff --git a/neutron/tests/unit/cisco/test_nexus_plugin.py b/neutron/tests/unit/cisco/test_nexus_plugin.py index ab41b22ea..6cf54ab84 100644 --- a/neutron/tests/unit/cisco/test_nexus_plugin.py +++ b/neutron/tests/unit/cisco/test_nexus_plugin.py @@ -194,7 +194,7 @@ class TestCiscoNexusPlugin(base.BaseTestCase): # Create a provider network new_net_dict = self._cisco_nexus_plugin.create_network( self.providernet, self.attachment1) - mock_db.assert_called_once() + self.assertEqual(mock_db.call_count, 1) for attr in NET_ATTRS: self.assertEqual(new_net_dict[attr], self.providernet[attr]) # Delete the provider network diff --git a/neutron/tests/unit/ibm/test_sdnve_agent.py b/neutron/tests/unit/ibm/test_sdnve_agent.py index aef694cb7..3b33d901e 100644 --- a/neutron/tests/unit/ibm/test_sdnve_agent.py +++ b/neutron/tests/unit/ibm/test_sdnve_agent.py @@ -106,9 +106,9 @@ class TestSdnveNeutronAgent(base.BaseTestCase): kwargs = {} kwargs['info'] = {'new_controller': '10.10.10.1'} self.agent.info_update('dummy', **kwargs) - run_vsctl_func.assert_called_one_with(['set-controller', - 'br_int', - 'tcp:10.10.10.1']) + run_vsctl_func.assert_called_once_with(['set-controller', + 'br_int', + 'tcp:10.10.10.1']) def test_get_info(self): with mock.patch.object(self.agent.int_br, diff --git a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py index eb10caaf0..c367710f8 100644 --- a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py +++ b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py @@ -396,10 +396,11 @@ class TestLinuxBridgeManager(base.BaseTestCase): with mock.patch.object(utils, 'execute') as exec_fn: exec_fn.return_value = False self.assertEqual(self.lbm.ensure_vlan("eth0", "1"), "eth0.1") - exec_fn.assert_called_twice() + # FIXME(kevinbenton): validate the params to the exec_fn calls + self.assertEqual(exec_fn.call_count, 2) exec_fn.return_value = True self.assertIsNone(self.lbm.ensure_vlan("eth0", "1")) - exec_fn.assert_called_once() + self.assertEqual(exec_fn.call_count, 3) def test_ensure_vxlan(self): seg_id = "12345678" diff --git a/neutron/tests/unit/midonet/test_midonet_lib.py b/neutron/tests/unit/midonet/test_midonet_lib.py index f9e42990a..46532066e 100644 --- a/neutron/tests/unit/midonet/test_midonet_lib.py +++ b/neutron/tests/unit/midonet/test_midonet_lib.py @@ -88,12 +88,11 @@ class MidoClientTestCase(testtools.TestCase): dhcp_call = mock.call.add_bridge_dhcp(bridge, gateway_ip, cidr, host_rts=host_rts, - dns_servers=dns_servers) + dns_nservers=dns_servers) self.client.create_dhcp(bridge, gateway_ip, cidr, host_rts=host_rts, dns_servers=dns_servers) - - bridge.assert_has_call(dhcp_call) + self.mock_api.assert_has_calls([dhcp_call]) def test_delete_dhcp(self): diff --git a/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py b/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py index 934e0b1e7..7daffce19 100644 --- a/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py +++ b/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py @@ -255,7 +255,7 @@ class TestFwaasL3AgentRpcCallback(base.BaseTestCase): routers, ri.router['tenant_id']) mock_get_firewalls_for_tenant.assert_called_once_with(ctx) - mock_driver_update_firewall.assert_called_once( + mock_driver_update_firewall.assert_called_once_with( routers, fake_firewall_list[0]) @@ -299,7 +299,7 @@ class TestFwaasL3AgentRpcCallback(base.BaseTestCase): routers, ri.router['tenant_id']) mock_get_firewalls_for_tenant.assert_called_once_with(ctx) - mock_driver_delete_firewall.assert_called_once( + mock_driver_delete_firewall.assert_called_once_with( routers, fake_firewall_list[0]) diff --git a/neutron/tests/unit/test_dhcp_agent.py b/neutron/tests/unit/test_dhcp_agent.py index 5978874cf..c36cd5d17 100644 --- a/neutron/tests/unit/test_dhcp_agent.py +++ b/neutron/tests/unit/test_dhcp_agent.py @@ -366,7 +366,7 @@ class TestDhcpAgent(base.BaseTestCase): with mock.patch.object(dhcp, 'LOG') as log: self.assertRaises(SystemExit, dhcp.DeviceManager, cfg.CONF, 'sudo', None) - log.error.assert_called_once() + self.assertEqual(log.error.call_count, 1) class TestLogArgs(base.BaseTestCase): @@ -1330,7 +1330,7 @@ class TestDeviceManager(base.BaseTestCase): network = FakeV4Network() dh._set_default_route(network, 'tap-name') - device.route.get_gateway.assert_called_once() + self.assertEqual(device.route.get_gateway.call_count, 1) self.assertFalse(device.route.delete_gateway.called) device.route.add_gateway.assert_called_once_with('192.168.0.1') @@ -1344,7 +1344,7 @@ class TestDeviceManager(base.BaseTestCase): network.namespace = 'qdhcp-1234' dh._set_default_route(network, 'tap-name') - device.route.get_gateway.assert_called_once() + self.assertEqual(device.route.get_gateway.call_count, 1) self.assertFalse(device.route.delete_gateway.called) self.assertFalse(device.route.add_gateway.called) @@ -1358,7 +1358,7 @@ class TestDeviceManager(base.BaseTestCase): network.namespace = 'qdhcp-1234' dh._set_default_route(network, 'tap-name') - device.route.get_gateway.assert_called_once() + self.assertEqual(device.route.get_gateway.call_count, 1) device.route.delete_gateway.assert_called_once_with('192.168.0.1') self.assertFalse(device.route.add_gateway.called) @@ -1372,7 +1372,7 @@ class TestDeviceManager(base.BaseTestCase): network.namespace = 'qdhcp-1234' dh._set_default_route(network, 'tap-name') - device.route.get_gateway.assert_called_once() + self.assertEqual(device.route.get_gateway.call_count, 1) device.route.delete_gateway.assert_called_once_with('192.168.0.1') self.assertFalse(device.route.add_gateway.called) @@ -1385,7 +1385,7 @@ class TestDeviceManager(base.BaseTestCase): network = FakeV4Network() dh._set_default_route(network, 'tap-name') - device.route.get_gateway.assert_called_once() + self.assertEqual(device.route.get_gateway.call_count, 1) self.assertFalse(device.route.delete_gateway.called) self.assertFalse(device.route.add_gateway.called) @@ -1398,7 +1398,7 @@ class TestDeviceManager(base.BaseTestCase): network = FakeV4Network() dh._set_default_route(network, 'tap-name') - device.route.get_gateway.assert_called_once() + self.assertEqual(device.route.get_gateway.call_count, 1) self.assertFalse(device.route.delete_gateway.called) device.route.add_gateway.assert_called_once_with('192.168.0.1') @@ -1415,7 +1415,7 @@ class TestDeviceManager(base.BaseTestCase): network.subnets = [subnet2, FakeV4Subnet()] dh._set_default_route(network, 'tap-name') - device.route.get_gateway.assert_called_once() + self.assertEqual(device.route.get_gateway.call_count, 1) self.assertFalse(device.route.delete_gateway.called) device.route.add_gateway.assert_called_once_with('192.168.1.1') diff --git a/neutron/tests/unit/test_l3_agent.py b/neutron/tests/unit/test_l3_agent.py index 1b3f231ed..1b7473280 100644 --- a/neutron/tests/unit/test_l3_agent.py +++ b/neutron/tests/unit/test_l3_agent.py @@ -421,7 +421,7 @@ class TestBasicRouterOperations(base.BaseTestCase): del router[l3_constants.INTERFACE_KEY] del router['gw_port'] agent.process_router(ri) - self.send_arp.assert_called_once() + self.assertEqual(self.send_arp.call_count, 1) self.assertFalse(agent.process_router_floating_ip_addresses.called) self.assertFalse(agent.process_router_floating_ip_nat_rules.called) @@ -582,7 +582,7 @@ class TestBasicRouterOperations(base.BaseTestCase): if r not in ri.iptables_manager.ipv4['nat'].rules] self.assertEqual(len(nat_rules_delta), 2) self._verify_snat_rules(nat_rules_delta, router) - self.send_arp.assert_called_once() + self.assertEqual(self.send_arp.call_count, 1) def test_process_router_snat_enabled(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -604,7 +604,7 @@ class TestBasicRouterOperations(base.BaseTestCase): if r not in orig_nat_rules] self.assertEqual(len(nat_rules_delta), 2) self._verify_snat_rules(nat_rules_delta, router) - self.send_arp.assert_called_once() + self.assertEqual(self.send_arp.call_count, 1) def test_process_router_interface_added(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -634,7 +634,8 @@ class TestBasicRouterOperations(base.BaseTestCase): if r not in orig_nat_rules] self.assertEqual(len(nat_rules_delta), 1) self._verify_snat_rules(nat_rules_delta, router) - self.send_arp.assert_called_once() + # send_arp is called both times process_router is called + self.assertEqual(self.send_arp.call_count, 2) def test_process_router_interface_removed(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -656,7 +657,8 @@ class TestBasicRouterOperations(base.BaseTestCase): if r not in ri.iptables_manager.ipv4['nat'].rules] self.assertEqual(len(nat_rules_delta), 1) self._verify_snat_rules(nat_rules_delta, router, negate=True) - self.send_arp.assert_called_once() + # send_arp is called both times process_router is called + self.assertEqual(self.send_arp.call_count, 2) def test_process_router_internal_network_added_unexpected_error(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) diff --git a/neutron/tests/unit/test_linux_interface.py b/neutron/tests/unit/test_linux_interface.py index 010409731..51de4c2a7 100644 --- a/neutron/tests/unit/test_linux_interface.py +++ b/neutron/tests/unit/test_linux_interface.py @@ -401,7 +401,7 @@ class TestBridgeInterfaceDriver(TestBase): with mock.patch('neutron.agent.linux.interface.LOG.debug') as log: br = interface.BridgeInterfaceDriver(self.conf) br.unplug('tap0') - log.assert_called_once() + self.assertEqual(log.call_count, 1) self.ip_dev.assert_has_calls([mock.call('tap0', 'sudo', None), mock.call().link.delete()])