From bdddb0bf1215fd5408e3a96ec4e3c73a1d34f2d1 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Fri, 6 Sep 2013 15:29:38 +0800 Subject: [PATCH] Utilizes assertNotIn Using assertTrue and the 'not in' operator to test if an element is in a sequence is too python2.4. Our unit testing framework supports assertNotIn which was created for these types of tests. Fixes bug #1230028 Change-Id: Ibaf6c73c514b9ad27f8f37eb3f1043e31dbfdcc1 --- neutron/tests/unit/_test_extension_portbindings.py | 4 ++-- neutron/tests/unit/nicira/test_nicira_plugin.py | 6 +++--- neutron/tests/unit/test_extensions.py | 8 ++++---- neutron/tests/unit/test_iptables_manager.py | 2 +- neutron/tests/unit/test_neutron_context.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/neutron/tests/unit/_test_extension_portbindings.py b/neutron/tests/unit/_test_extension_portbindings.py index 41fb2d6b707..3995fb91181 100644 --- a/neutron/tests/unit/_test_extension_portbindings.py +++ b/neutron/tests/unit/_test_extension_portbindings.py @@ -45,8 +45,8 @@ class PortBindingsTestCase(test_db_plugin.NeutronDbPluginV2TestCase): def _check_response_no_portbindings(self, port): self.assertTrue('status' in port) - self.assertFalse(portbindings.VIF_TYPE in port) - self.assertFalse(portbindings.CAPABILITIES in port) + self.assertNotIn(portbindings.VIF_TYPE, port) + self.assertNotIn(portbindings.CAPABILITIES, port) def _get_non_admin_context(self): return context.Context(user_id=None, diff --git a/neutron/tests/unit/nicira/test_nicira_plugin.py b/neutron/tests/unit/nicira/test_nicira_plugin.py index bfb14d49c05..dbbbf8f1d12 100644 --- a/neutron/tests/unit/nicira/test_nicira_plugin.py +++ b/neutron/tests/unit/nicira/test_nicira_plugin.py @@ -1138,7 +1138,7 @@ class TestNiciraQoSQueue(NiciraPluginV2TestCase): tenant_id='not_admin', set_context=True) port = self.deserialize('json', res) - self.assertEqual(ext_qos.QUEUE not in port['port'], True) + self.assertNotIn(ext_qos.QUEUE, port['port']) def test_dscp_value_out_of_range(self): body = {'qos_queue': {'tenant_id': 'admin', 'dscp': '64', @@ -1172,7 +1172,7 @@ class TestNiciraQoSQueue(NiciraPluginV2TestCase): neutron_context = context.Context('', 'not_admin') port = self._update('ports', port['port']['id'], data, neutron_context=neutron_context) - self.assertFalse(ext_qos.QUEUE in port['port']) + self.assertNotIn(ext_qos.QUEUE, port['port']) def test_rxtx_factor(self): with self.qos_queue(max=10) as q1: @@ -1438,7 +1438,7 @@ class TestNiciraMultiProviderNetworks(NiciraPluginV2TestCase): network = self.deserialize(self.fmt, net_req.get_response(self.api)) for provider_field in [pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK, pnet.SEGMENTATION_ID]: - self.assertTrue(provider_field not in network['network']) + self.assertNotIn(provider_field, network['network']) tz = network['network'][mpnet.SEGMENTS][0] self.assertEqual(tz[pnet.NETWORK_TYPE], 'vlan') self.assertEqual(tz[pnet.PHYSICAL_NETWORK], 'physnet1') diff --git a/neutron/tests/unit/test_extensions.py b/neutron/tests/unit/test_extensions.py index 9d50f989b38..f9e16106752 100644 --- a/neutron/tests/unit/test_extensions.py +++ b/neutron/tests/unit/test_extensions.py @@ -439,7 +439,7 @@ class ExtensionManagerTest(base.BaseTestCase): ext_mgr.add_extension(ext_stubs.StubExtension("valid_extension")) self.assertTrue('valid_extension' in ext_mgr.extensions) - self.assertFalse('invalid_extension' in ext_mgr.extensions) + self.assertNotIn('invalid_extension', ext_mgr.extensions) class PluginAwareExtensionManagerTest(base.BaseTestCase): @@ -454,7 +454,7 @@ class PluginAwareExtensionManagerTest(base.BaseTestCase): ext_mgr.add_extension(ext_stubs.StubExtension("e3")) self.assertTrue("e1" in ext_mgr.extensions) - self.assertFalse("e2" in ext_mgr.extensions) + self.assertNotIn("e2", ext_mgr.extensions) self.assertTrue("e3" in ext_mgr.extensions) def test_extensions_are_not_loaded_for_plugins_unaware_of_extensions(self): @@ -469,7 +469,7 @@ class PluginAwareExtensionManagerTest(base.BaseTestCase): ext_mgr = extensions.PluginAwareExtensionManager('', plugin_info) ext_mgr.add_extension(ext_stubs.StubExtension("e1")) - self.assertFalse("e1" in ext_mgr.extensions) + self.assertNotIn("e1", ext_mgr.extensions) def test_extensions_not_loaded_for_plugin_without_expected_interface(self): @@ -482,7 +482,7 @@ class PluginAwareExtensionManagerTest(base.BaseTestCase): ext_mgr.add_extension( ext_stubs.ExtensionExpectingPluginInterface("supported_extension")) - self.assertFalse("e1" in ext_mgr.extensions) + self.assertNotIn("e1", ext_mgr.extensions) def test_extensions_are_loaded_for_plugin_with_expected_interface(self): diff --git a/neutron/tests/unit/test_iptables_manager.py b/neutron/tests/unit/test_iptables_manager.py index 0fda076770f..fda9a3e4710 100644 --- a/neutron/tests/unit/test_iptables_manager.py +++ b/neutron/tests/unit/test_iptables_manager.py @@ -561,4 +561,4 @@ class IptablesManagerStateLessTestCase(base.BaseTestCase): self.iptables = (iptables_manager.IptablesManager(state_less=True)) def test_nat_not_found(self): - self.assertFalse('nat' in self.iptables.ipv4) + self.assertNotIn('nat', self.iptables.ipv4) diff --git a/neutron/tests/unit/test_neutron_context.py b/neutron/tests/unit/test_neutron_context.py index 88a0e30d619..24b257b0ef5 100644 --- a/neutron/tests/unit/test_neutron_context.py +++ b/neutron/tests/unit/test_neutron_context.py @@ -48,7 +48,7 @@ class TestNeutronContext(base.BaseTestCase): self.assertIsNone(cxt_dict['user_id']) self.assertIsNone(cxt_dict['tenant_id']) self.assertIsNotNone(cxt.session) - self.assertFalse('session' in cxt_dict) + self.assertNotIn('session', cxt_dict) def test_neutron_context_admin_without_session_to_dict(self): cxt = context.get_admin_context_without_session()