Utilizes assertIsNone and assertIsNotNone

Using assertEqual/assertNotEqual to test if an element
is or is not None is too python2.4.
Our unit testing framework supports assertIsNone and assertIsNotNone
which were created for these types of tests.

Partial-bug: #1230028

Change-Id: Ie0bddae642f7973ee8b0e00164415f8d87de387e
This commit is contained in:
Zhongyue Luo 2013-10-09 09:44:01 +08:00
parent 3a7dad7c5d
commit 3be9a97380
22 changed files with 53 additions and 56 deletions

View File

@ -528,7 +528,7 @@ class TestFirewallDBPlugin(FirewallPluginDbTestCase):
self.plugin.get_firewall_policy,
ctx, fwp_id)
fw_rule = self.plugin.get_firewall_rule(ctx, fr_id)
self.assertEqual(fw_rule['firewall_policy_id'], None)
self.assertIsNone(fw_rule['firewall_policy_id'])
def test_delete_firewall_policy_with_firewall_association(self):
attrs = self._get_test_firewall_attrs()

View File

@ -209,7 +209,7 @@ class TestLinuxBridgeManager(base.BaseTestCase):
vn_id = constants.MAX_VXLAN_VNI
self.assertEqual(self.lbm.get_vxlan_device_name(vn_id),
"vxlan-" + str(vn_id))
self.assertEqual(self.lbm.get_vxlan_device_name(vn_id + 1), None)
self.assertIsNone(self.lbm.get_vxlan_device_name(vn_id + 1))
def test_get_all_neutron_bridges(self):
br_list = ["br-int", "brq1", "brq2", "br-ex"]
@ -256,8 +256,7 @@ class TestLinuxBridgeManager(base.BaseTestCase):
get_if_fn.return_value = ["tap1", "tap2", "tap3"]
self.assertEqual(self.lbm.get_bridge_for_tap_device("tap1"),
"br-int")
self.assertEqual(self.lbm.get_bridge_for_tap_device("tap4"),
None)
self.assertIsNone(self.lbm.get_bridge_for_tap_device("tap4"))
def test_is_device_on_bridge(self):
self.assertTrue(not self.lbm.is_device_on_bridge(""))

View File

@ -95,7 +95,7 @@ class TestLinuxBridgeSecurityGroupsDB(LinuxBridgeSecurityGroupsTestCase):
def test_security_group_get_port_from_device_with_no_port(self):
port_dict = lb_db.get_port_from_device('bad_device_id')
self.assertEqual(None, port_dict)
self.assertIsNone(port_dict)
class TestLinuxBridgeSecurityGroupsDBXML(TestLinuxBridgeSecurityGroupsDB):

View File

@ -218,7 +218,7 @@ class PositiveRPCWrapperValidConfigTestCase(base.BaseTestCase):
self.drv._server = mock.MagicMock()
def test_no_exception_on_correct_configuration(self):
self.assertNotEqual(self.drv, None)
self.assertIsNotNone(self.drv)
def test_plug_host_into_network(self):
tenant_id = 'ten-1'

View File

@ -82,7 +82,7 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase,
def test_security_group_get_port_from_device_with_no_port(self):
plugin = manager.NeutronManager.get_plugin()
port_dict = plugin.callbacks.get_port_from_device('bad_device_id')
self.assertEqual(None, port_dict)
self.assertIsNone(port_dict)
class TestMl2SecurityGroupsXML(TestMl2SecurityGroups):

View File

@ -133,7 +133,7 @@ class GreTypeTest(base.BaseTestCase):
self.driver.release_segment(self.session, segment)
alloc = self.driver.get_gre_allocation(self.session,
segment[api.SEGMENTATION_ID])
self.assertEqual(None, alloc)
self.assertIsNone(alloc)
def test_allocate_tenant_segment(self):
tunnel_ids = set()
@ -146,7 +146,7 @@ class GreTypeTest(base.BaseTestCase):
tunnel_ids.add(segment[api.SEGMENTATION_ID])
segment = self.driver.allocate_tenant_segment(self.session)
self.assertEqual(None, segment)
self.assertIsNone(segment)
segment = {api.NETWORK_TYPE: 'gre',
api.PHYSICAL_NETWORK: 'None',

View File

@ -155,7 +155,7 @@ class VxlanTypeTest(base.BaseTestCase):
tunnel_ids.add(segment[api.SEGMENTATION_ID])
segment = self.driver.allocate_tenant_segment(self.session)
self.assertEqual(None, segment)
self.assertIsNone(segment)
segment = {api.NETWORK_TYPE: 'vxlan',
api.PHYSICAL_NETWORK: 'None',

View File

@ -96,7 +96,7 @@ class TestMlnxSecurityGroupsDB(MlnxSecurityGroupsTestCase):
def test_security_group_get_port_from_device_with_no_port(self):
port_dict = mlnx_db.get_port_from_device('bad_device_id')
self.assertEqual(None, port_dict)
self.assertIsNone(port_dict)
class TestMlnxSecurityGroupsDBXML(TestMlnxSecurityGroupsDB):

View File

@ -77,7 +77,7 @@ class NECPluginV2DBTest(NECPluginV2DBTestBase):
self.assertEqual(tenant.quantum_id, q)
tenant_none = ndb.get_ofc_item(self.session, 'ofc_tenant', n)
self.assertEqual(None, tenant_none)
self.assertIsNone(tenant_none)
def testb_get_ofc_id(self):
"""test get OFC d."""
@ -87,7 +87,7 @@ class NECPluginV2DBTest(NECPluginV2DBTestBase):
self.assertEqual(tenant_id, o)
tenant_none = ndb.get_ofc_item(self.session, 'ofc_tenant', n)
self.assertEqual(None, tenant_none)
self.assertIsNone(tenant_none)
def testb_exists_ofc_item(self):
"""test get OFC d."""
@ -97,7 +97,7 @@ class NECPluginV2DBTest(NECPluginV2DBTestBase):
self.assertTrue(ret)
tenant_none = ndb.get_ofc_item(self.session, 'ofc_tenant', n)
self.assertEqual(None, tenant_none)
self.assertIsNone(tenant_none)
def testc_find_ofc_item(self):
"""test find OFC item."""
@ -108,7 +108,7 @@ class NECPluginV2DBTest(NECPluginV2DBTestBase):
self.assertEqual(tenant.quantum_id, q)
tenant_none = ndb.find_ofc_item(self.session, 'ofc_tenant', n)
self.assertEqual(None, tenant_none)
self.assertIsNone(tenant_none)
def testc_del_ofc_item(self):
"""test delete OFC item."""
@ -118,10 +118,10 @@ class NECPluginV2DBTest(NECPluginV2DBTestBase):
tenant_none = ndb.get_ofc_item(self.session,
'ofc_tenant', q)
self.assertEqual(None, tenant_none)
self.assertIsNone(tenant_none)
tenant_none = ndb.find_ofc_item(self.session,
'ofc_tenant', o)
self.assertEqual(None, tenant_none)
self.assertIsNone(tenant_none)
def _compare_portinfo(self, portinfo, expected):
self.assertEqual(portinfo.id, expected['port_id'])
@ -157,7 +157,7 @@ class NECPluginV2DBTest(NECPluginV2DBTestBase):
nonexist_id = uuidutils.generate_uuid()
portinfo_none = ndb.get_portinfo(self.session, nonexist_id)
self.assertEqual(None, portinfo_none)
self.assertIsNone(portinfo_none)
def testf_del_portinfo(self):
"""test delete portinfo."""
@ -167,7 +167,7 @@ class NECPluginV2DBTest(NECPluginV2DBTestBase):
self.assertEqual(portinfo.id, params['port_id'])
ndb.del_portinfo(self.session, params['port_id'])
portinfo_none = ndb.get_portinfo(self.session, params['port_id'])
self.assertEqual(None, portinfo_none)
self.assertIsNone(portinfo_none)
class NECPluginV2DBOldMappingTest(NECPluginV2DBTestBase):
@ -187,7 +187,7 @@ class NECPluginV2DBOldMappingTest(NECPluginV2DBTestBase):
self.assertEqual(ret.ofc_id, o)
self.assertEqual(ret.quantum_id, q)
ret = ndb.get_ofc_item(self.session, 'ofc_tenant', q, self.OLD)
self.assertEqual(ret, None)
self.assertIsNone(ret)
def test_add_ofc_item_old(self):
o, q, n = self.get_ofc_item_random_params()
@ -196,7 +196,7 @@ class NECPluginV2DBOldMappingTest(NECPluginV2DBTestBase):
self.assertEqual(ret.quantum_id, q)
ret = ndb.get_ofc_item(self.session, 'ofc_tenant', q, self.NEW)
self.assertEqual(ret, None)
self.assertIsNone(ret)
ret = ndb.get_ofc_item(self.session, 'ofc_tenant', q, self.OLD)
self.assertEqual(ret.id, o)
self.assertEqual(ret.quantum_id, q)
@ -260,9 +260,9 @@ class NECPluginV2DBOldMappingTest(NECPluginV2DBTestBase):
ndb.del_ofc_item(self.session, 'ofc_tenant', q, mode)
ret = ndb.get_ofc_item(self.session, 'ofc_tenant', q, self.NEW)
self.assertEqual(ret, None)
self.assertIsNone(ret)
ret = ndb.get_ofc_item(self.session, 'ofc_tenant', q, self.OLD)
self.assertEqual(ret, None)
self.assertIsNone(ret)
def test_delete_ofc_item_new(self):
self._check_delete_ofc_item(self.NEW)

View File

@ -1017,7 +1017,7 @@ class TestNiciraQoSQueue(NiciraPluginV2TestCase):
return_value={"uuid": "fake_queue"}):
with self.qos_queue(name='fake_lqueue', min=34, max=44,
qos_marking='trusted', default=False) as q:
self.assertEqual(q['qos_queue']['dscp'], None)
self.assertIsNone(q['qos_queue']['dscp'])
self.assertTrue(log.called)
def test_create_qos_queue_name_exceeds_40_chars(self):
@ -1113,7 +1113,7 @@ class TestNiciraQoSQueue(NiciraPluginV2TestCase):
device_id = "00fff4d0-e4a8-4a3a-8906-4c4cdafb59f1"
res = self._create_port('json', net1['network']['id'])
port = self.deserialize('json', res)
self.assertEqual(port['port'][ext_qos.QUEUE], None)
self.assertIsNone(port['port'][ext_qos.QUEUE])
data = {'port': {'device_id': device_id}}
req = self.new_update_request('ports', data,

View File

@ -99,7 +99,7 @@ class TestOpenvswitchSecurityGroups(OpenvswitchSecurityGroupsTestCase,
def test_security_group_get_port_from_device_with_no_port(self):
plugin = manager.NeutronManager.get_plugin()
port_dict = plugin.callbacks.get_port_from_device('bad_device_id')
self.assertEqual(None, port_dict)
self.assertIsNone(port_dict)
class TestOpenvswitchSecurityGroupsXML(TestOpenvswitchSecurityGroups):

View File

@ -91,7 +91,7 @@ class TestRyuSecurityGroups(RyuSecurityGroupsTestCase,
def test_security_group_get_port_from_device_with_no_port(self):
plugin = manager.NeutronManager.get_plugin()
port_dict = plugin.callbacks.get_port_from_device('bad_device_id')
self.assertEqual(None, port_dict)
self.assertIsNone(port_dict)
class TestRyuSecurityGroupsXML(TestRyuSecurityGroups):

View File

@ -38,7 +38,7 @@ class RequestTestCase(base.BaseTestCase):
def test_content_type_missing(self):
request = wsgi.Request.blank('/tests/123', method='POST')
request.body = "<body />"
self.assertEqual(None, request.get_content_type())
self.assertIsNone(request.get_content_type())
def test_content_type_with_charset(self):
request = wsgi.Request.blank('/tests/123')
@ -113,13 +113,13 @@ class RequestTestCase(base.BaseTestCase):
# the best match locale should be None
request.headers['Accept-Language'] = 'unknown-language'
language = request.best_match_language()
self.assertEqual(language, None)
self.assertIsNone(language)
request.headers['Accept-Language'] = ''
language = request.best_match_language()
self.assertEqual(language, None)
self.assertIsNone(language)
request.headers.pop('Accept-Language')
language = request.best_match_language()
self.assertEqual(language, None)
self.assertIsNone(language)
class ResourceTestCase(base.BaseTestCase):

View File

@ -508,7 +508,7 @@ class TestAttributes(base.BaseTestCase):
'f3eeab00-8367-4524-b662-55e64d4cacb5']]
for uuid_list in valid_uuid_lists:
msg = attributes._validate_uuid_list(uuid_list)
self.assertEqual(msg, None)
self.assertIsNone(msg)
def test_validate_dict_type(self):
for value in (None, True, '1', []):

View File

@ -100,12 +100,12 @@ class TestVlanRangeVerifyValid(UtilTestParseVlanRanges):
return plugin_utils.verify_vlan_range(vlan_range)
def test_range_valid_ranges(self):
self.assertEqual(self.verify_range((1, 2)), None)
self.assertEqual(self.verify_range((1, 1999)), None)
self.assertEqual(self.verify_range((100, 100)), None)
self.assertEqual(self.verify_range((100, 200)), None)
self.assertEqual(self.verify_range((4001, 4094)), None)
self.assertEqual(self.verify_range((1, 4094)), None)
self.assertIsNone(self.verify_range((1, 2)))
self.assertIsNone(self.verify_range((1, 1999)))
self.assertIsNone(self.verify_range((100, 100)))
self.assertIsNone(self.verify_range((100, 200)))
self.assertIsNone(self.verify_range((4001, 4094)))
self.assertIsNone(self.verify_range((1, 4094)))
def check_one_vlan_invalid(self, bad_range, which):
expected_msg = self._vrange_invalid_vlan(bad_range, which)

View File

@ -31,7 +31,7 @@ class ConfigurationTest(base.BaseTestCase):
self.assertEqual('', cfg.CONF.api_extensions_path)
self.assertEqual('policy.json', cfg.CONF.policy_file)
self.assertEqual('keystone', cfg.CONF.auth_strategy)
self.assertEqual(None, cfg.CONF.core_plugin)
self.assertIsNone(cfg.CONF.core_plugin)
self.assertEqual(0, len(cfg.CONF.service_plugins))
self.assertEqual('fa:16:3e:00:00:00', cfg.CONF.base_mac)
self.assertEqual(16, cfg.CONF.mac_generation_retries)

View File

@ -2211,8 +2211,7 @@ class TestNetworksV2(NeutronDbPluginV2TestCase):
self.assertEqual(1, len(res['networks']))
self.assertEqual(res['networks'][0]['name'],
net1['network']['name'])
self.assertEqual(None,
res['networks'][0].get('id'))
self.assertIsNone(res['networks'][0].get('id'))
def test_list_networks_with_parameters_invalid_values(self):
with contextlib.nested(self.network(name='net1',
@ -3003,7 +3002,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
req = self.new_update_request('subnets', data,
subnet['subnet']['id'])
res = self.deserialize(self.fmt, req.get_response(self.api))
self.assertEqual(None, data['subnet']['gateway_ip'])
self.assertIsNone(data['subnet']['gateway_ip'])
def test_update_subnet(self):
with self.subnet() as subnet:

View File

@ -262,7 +262,7 @@ class TestL3GwModeMixin(base.BaseTestCase):
def test_make_router_dict_no_ext_gw(self):
self._reset_ext_gw()
router_dict = self.target_object._make_router_dict(self.router)
self.assertEqual(None, router_dict[l3.EXTERNAL_GW_INFO])
self.assertIsNone(router_dict[l3.EXTERNAL_GW_INFO])
def test_make_router_dict_with_ext_gw(self):
router_dict = self.target_object._make_router_dict(self.router)

View File

@ -400,7 +400,7 @@ class ExtraRouteDBTestCaseBase(object):
s['subnet']['network_id'])
body = self._show('routers', r['router']['id'])
gw_info = body['router']['external_gateway_info']
self.assertEqual(gw_info, None)
self.assertIsNone(gw_info)
def test_router_list_with_sort(self):
with contextlib.nested(self.router(name='router1'),

View File

@ -946,7 +946,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
s['subnet']['network_id'])
body = self._show('routers', r['router']['id'])
gw_info = body['router']['external_gateway_info']
self.assertEqual(gw_info, None)
self.assertIsNone(gw_info)
def test_router_add_gateway_tenant_ctx(self):
with self.router(tenant_id='noadmin',
@ -966,7 +966,7 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
s['subnet']['network_id'])
body = self._show('routers', r['router']['id'])
gw_info = body['router']['external_gateway_info']
self.assertEqual(gw_info, None)
self.assertIsNone(gw_info)
def test_router_add_gateway_invalid_network_returns_404(self):
with self.router() as r:
@ -1245,8 +1245,8 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
p['port']['fixed_ips'][0]['subnet_id']}}
with self.floatingip_no_assoc(private_sub) as fip:
body = self._show('floatingips', fip['floatingip']['id'])
self.assertEqual(body['floatingip']['port_id'], None)
self.assertEqual(body['floatingip']['fixed_ip_address'], None)
self.assertIsNone(body['floatingip']['port_id'])
self.assertIsNone(body['floatingip']['fixed_ip_address'])
port_id = p['port']['id']
ip_address = p['port']['fixed_ips'][0]['ip_address']
@ -1281,10 +1281,9 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
def assert_no_assoc(fip):
body = self._show('floatingips',
fip['floatingip']['id'])
self.assertEqual(body['floatingip']['port_id'],
None)
self.assertIsNone(body['floatingip']['port_id'])
self.assertIsNone(
body['floatingip']['fixed_ip_address'], None)
body['floatingip']['fixed_ip_address'])
assert_no_assoc(fip1)
assert_no_assoc(fip2)
@ -1341,9 +1340,9 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
body = self._show('floatingips', fip['floatingip']['id'])
self.assertEqual(body['floatingip']['id'],
fip['floatingip']['id'])
self.assertEqual(body['floatingip']['port_id'], None)
self.assertEqual(body['floatingip']['fixed_ip_address'], None)
self.assertEqual(body['floatingip']['router_id'], None)
self.assertIsNone(body['floatingip']['port_id'])
self.assertIsNone(body['floatingip']['fixed_ip_address'])
self.assertIsNone(body['floatingip']['router_id'])
def test_two_fips_one_port_invalid_return_409(self):
with self.floatingip_with_assoc() as fip1:

View File

@ -345,7 +345,7 @@ class TestIPDevice(base.BaseTestCase):
def test_eq_other_is_none(self):
dev1 = ip_lib.IPDevice('tap0', 'sudo', 'ns1')
self.assertNotEqual(dev1, None)
self.assertIsNotNone(dev1)
def test_str(self):
self.assertEqual(str(ip_lib.IPDevice('tap0')), 'tap0')

View File

@ -269,7 +269,7 @@ class RouterServiceInsertionTestCase(base.BaseTestCase):
def test_router_create_no_service_type_id(self):
router = self._router_create()
self.assertEqual(router.get('service_type_id'), None)
self.assertIsNone(router.get('service_type_id'))
def test_router_create_with_service_type_id(self):
router = self._router_create(self._service_type_id)