assertTrue(isinstance) replace by assertIsInstance

some of tests use different method of assertTrue(isinstance(A, B))
or assertEqual(type(A), B). The correct way is to use
assertIsInstance(A, B) provided by testtools

Closes-Bug: #1268480
Change-Id: Ie3b3e49ea3cc4357a65605ad54ff4ee1fbde12c7
This commit is contained in:
lizheming 2014-01-15 10:42:19 +08:00
parent 1a20d2964d
commit 40e433469d
29 changed files with 135 additions and 137 deletions

View File

@ -186,8 +186,8 @@ class ClientTest(utils.TestCase):
cs = novaclient.v3.client.Client("user", "password", "project_id",
auth_url="foo/v2",
extensions=extensions)
self.assertTrue(isinstance(getattr(cs, fake_attribute_name1, None),
fakes.FakeManager))
self.assertIsInstance(getattr(cs, fake_attribute_name1, None),
fakes.FakeManager)
self.assertFalse(hasattr(cs, fake_attribute_name2))
@mock.patch.object(novaclient.client.HTTPClient, 'authenticate')

View File

@ -33,18 +33,18 @@ class BaremetalExtensionTest(utils.TestCase):
nl = cs.baremetal.list()
cs.assert_called('GET', '/os-baremetal-nodes')
for n in nl:
self.assertTrue(isinstance(n, baremetal.BareMetalNode))
self.assertIsInstance(n, baremetal.BareMetalNode)
def test_get_node(self):
n = cs.baremetal.get(1)
cs.assert_called('GET', '/os-baremetal-nodes/1')
self.assertTrue(isinstance(n, baremetal.BareMetalNode))
self.assertIsInstance(n, baremetal.BareMetalNode)
def test_create_node(self):
n = cs.baremetal.create("service_host", 1, 1024, 2048,
"aa:bb:cc:dd:ee:ff")
cs.assert_called('POST', '/os-baremetal-nodes')
self.assertTrue(isinstance(n, baremetal.BareMetalNode))
self.assertIsInstance(n, baremetal.BareMetalNode)
def test_delete_node(self):
n = cs.baremetal.get(1)
@ -54,7 +54,7 @@ class BaremetalExtensionTest(utils.TestCase):
def test_node_add_interface(self):
i = cs.baremetal.add_interface(1, "bb:cc:dd:ee:ff:aa", 1, 2)
cs.assert_called('POST', '/os-baremetal-nodes/1/action')
self.assertTrue(isinstance(i, baremetal.BareMetalNodeInterface))
self.assertIsInstance(i, baremetal.BareMetalNodeInterface)
def test_node_remove_interface(self):
cs.baremetal.remove_interface(1, "bb:cc:dd:ee:ff:aa")

View File

@ -28,7 +28,7 @@ class MigrationsTest(utils.TestCase):
ml = cs.migrations.list()
cs.assert_called('GET', '/os-migrations')
for m in ml:
self.assertTrue(isinstance(m, migrations.Migration))
self.assertIsInstance(m, migrations.Migration)
def test_list_migrations_with_filters(self):
ml = cs.migrations.list('host1', 'finished', 'child1')
@ -37,4 +37,4 @@ class MigrationsTest(utils.TestCase):
'/os-migrations?cell_name=child1&host=host1'
'&status=finished')
for m in ml:
self.assertTrue(isinstance(m, migrations.Migration))
self.assertIsInstance(m, migrations.Migration)

View File

@ -34,14 +34,14 @@ class AgentsTest(utils.TestCase):
ags = self.cs.agents.list()
self.cs.assert_called('GET', '/os-agents')
for a in ags:
self.assertTrue(isinstance(a, self.agent_type))
self.assertIsInstance(a, self.agent_type)
self.assertEqual(a.hypervisor, 'kvm')
def test_list_agents_with_hypervisor(self):
ags = self.cs.agents.list('xen')
self.cs.assert_called('GET', '/os-agents?hypervisor=xen')
for a in ags:
self.assertTrue(isinstance(a, self.agent_type))
self.assertIsInstance(a, self.agent_type)
self.assertEqual(a.hypervisor, 'xen')
def test_agents_create(self):

View File

@ -34,31 +34,31 @@ class AggregatesTest(utils.TestCase):
result = self.cs.aggregates.list()
self.cs.assert_called('GET', '/os-aggregates')
for aggregate in result:
self.assertTrue(isinstance(aggregate, aggregates.Aggregate))
self.assertIsInstance(aggregate, aggregates.Aggregate)
def test_create_aggregate(self):
body = {"aggregate": {"name": "test", "availability_zone": "nova1"}}
aggregate = self.cs.aggregates.create("test", "nova1")
self.cs.assert_called('POST', '/os-aggregates', body)
self.assertTrue(isinstance(aggregate, aggregates.Aggregate))
self.assertIsInstance(aggregate, aggregates.Aggregate)
def test_get(self):
aggregate = self.cs.aggregates.get("1")
self.cs.assert_called('GET', '/os-aggregates/1')
self.assertTrue(isinstance(aggregate, aggregates.Aggregate))
self.assertIsInstance(aggregate, aggregates.Aggregate)
aggregate2 = self.cs.aggregates.get(aggregate)
self.cs.assert_called('GET', '/os-aggregates/1')
self.assertTrue(isinstance(aggregate2, aggregates.Aggregate))
self.assertIsInstance(aggregate2, aggregates.Aggregate)
def test_get_details(self):
aggregate = self.cs.aggregates.get_details("1")
self.cs.assert_called('GET', '/os-aggregates/1')
self.assertTrue(isinstance(aggregate, aggregates.Aggregate))
self.assertIsInstance(aggregate, aggregates.Aggregate)
aggregate2 = self.cs.aggregates.get_details(aggregate)
self.cs.assert_called('GET', '/os-aggregates/1')
self.assertTrue(isinstance(aggregate2, aggregates.Aggregate))
self.assertIsInstance(aggregate2, aggregates.Aggregate)
def test_update(self):
aggregate = self.cs.aggregates.get("1")
@ -67,11 +67,11 @@ class AggregatesTest(utils.TestCase):
result1 = aggregate.update(values)
self.cs.assert_called('PUT', '/os-aggregates/1', body)
self.assertTrue(isinstance(result1, aggregates.Aggregate))
self.assertIsInstance(result1, aggregates.Aggregate)
result2 = self.cs.aggregates.update(2, values)
self.cs.assert_called('PUT', '/os-aggregates/2', body)
self.assertTrue(isinstance(result2, aggregates.Aggregate))
self.assertIsInstance(result2, aggregates.Aggregate)
def test_update_with_availability_zone(self):
aggregate = self.cs.aggregates.get("1")
@ -80,7 +80,7 @@ class AggregatesTest(utils.TestCase):
result3 = self.cs.aggregates.update(aggregate, values)
self.cs.assert_called('PUT', '/os-aggregates/1', body)
self.assertTrue(isinstance(result3, aggregates.Aggregate))
self.assertIsInstance(result3, aggregates.Aggregate)
def test_add_host(self):
aggregate = self.cs.aggregates.get("1")
@ -89,15 +89,15 @@ class AggregatesTest(utils.TestCase):
result1 = aggregate.add_host(host)
self.cs.assert_called('POST', '/os-aggregates/1/action', body)
self.assertTrue(isinstance(result1, aggregates.Aggregate))
self.assertIsInstance(result1, aggregates.Aggregate)
result2 = self.cs.aggregates.add_host("2", host)
self.cs.assert_called('POST', '/os-aggregates/2/action', body)
self.assertTrue(isinstance(result2, aggregates.Aggregate))
self.assertIsInstance(result2, aggregates.Aggregate)
result3 = self.cs.aggregates.add_host(aggregate, host)
self.cs.assert_called('POST', '/os-aggregates/1/action', body)
self.assertTrue(isinstance(result3, aggregates.Aggregate))
self.assertIsInstance(result3, aggregates.Aggregate)
def test_remove_host(self):
aggregate = self.cs.aggregates.get("1")
@ -106,15 +106,15 @@ class AggregatesTest(utils.TestCase):
result1 = aggregate.remove_host(host)
self.cs.assert_called('POST', '/os-aggregates/1/action', body)
self.assertTrue(isinstance(result1, aggregates.Aggregate))
self.assertIsInstance(result1, aggregates.Aggregate)
result2 = self.cs.aggregates.remove_host("2", host)
self.cs.assert_called('POST', '/os-aggregates/2/action', body)
self.assertTrue(isinstance(result2, aggregates.Aggregate))
self.assertIsInstance(result2, aggregates.Aggregate)
result3 = self.cs.aggregates.remove_host(aggregate, host)
self.cs.assert_called('POST', '/os-aggregates/1/action', body)
self.assertTrue(isinstance(result3, aggregates.Aggregate))
self.assertIsInstance(result3, aggregates.Aggregate)
def test_set_metadata(self):
aggregate = self.cs.aggregates.get("1")
@ -123,15 +123,15 @@ class AggregatesTest(utils.TestCase):
result1 = aggregate.set_metadata(metadata)
self.cs.assert_called('POST', '/os-aggregates/1/action', body)
self.assertTrue(isinstance(result1, aggregates.Aggregate))
self.assertIsInstance(result1, aggregates.Aggregate)
result2 = self.cs.aggregates.set_metadata(2, metadata)
self.cs.assert_called('POST', '/os-aggregates/2/action', body)
self.assertTrue(isinstance(result2, aggregates.Aggregate))
self.assertIsInstance(result2, aggregates.Aggregate)
result3 = self.cs.aggregates.set_metadata(aggregate, metadata)
self.cs.assert_called('POST', '/os-aggregates/1/action', body)
self.assertTrue(isinstance(result3, aggregates.Aggregate))
self.assertIsInstance(result3, aggregates.Aggregate)
def test_delete_aggregate(self):
aggregate = self.cs.aggregates.list()[0]

View File

@ -46,8 +46,7 @@ class AvailabilityZoneTest(utils.TestCase):
self.cs.assert_called('GET', '/os-availability-zone')
for zone in zones:
self.assertTrue(isinstance(zone,
self.availability_zone_type))
self.assertIsInstance(zone, self.availability_zone_type)
self.assertEqual(2, len(zones))
@ -67,8 +66,7 @@ class AvailabilityZoneTest(utils.TestCase):
self.cs.assert_called('GET', '/os-availability-zone/detail')
for zone in zones:
self.assertTrue(isinstance(zone,
self.availability_zone_type))
self.assertIsInstance(zone, self.availability_zone_type)
self.assertEqual(3, len(zones))

View File

@ -31,9 +31,9 @@ class CertsTest(utils.TestCase):
def test_create_cert(self):
cert = self.cs.certs.create()
self.cs.assert_called('POST', '/os-certificates')
self.assertTrue(isinstance(cert, certs.Certificate))
self.assertIsInstance(cert, certs.Certificate)
def test_get_root_cert(self):
cert = self.cs.certs.get()
self.cs.assert_called('GET', '/os-certificates/root')
self.assertTrue(isinstance(cert, certs.Certificate))
self.assertIsInstance(cert, certs.Certificate)

View File

@ -24,14 +24,14 @@ class CloudpipeTest(utils.TestCase):
def test_list_cloudpipes(self):
cp = cs.cloudpipe.list()
cs.assert_called('GET', '/os-cloudpipe')
[self.assertTrue(isinstance(c, cloudpipe.Cloudpipe)) for c in cp]
[self.assertIsInstance(c, cloudpipe.Cloudpipe) for c in cp]
def test_create(self):
project = "test"
cp = cs.cloudpipe.create(project)
body = {'cloudpipe': {'project_id': project}}
cs.assert_called('POST', '/os-cloudpipe', body)
self.assertTrue(isinstance(cp, str))
self.assertIsInstance(cp, str)
def test_update(self):
cs.cloudpipe.update("192.168.1.1", 2345)

View File

@ -27,7 +27,7 @@ class FlavorAccessTest(utils.TestCase):
kwargs = {'flavor': cs.flavors.get(2)}
r = cs.flavor_access.list(**kwargs)
cs.assert_called('GET', '/flavors/2/os-flavor-access')
[self.assertTrue(isinstance(a, flavor_access.FlavorAccess)) for a in r]
[self.assertIsInstance(a, flavor_access.FlavorAccess) for a in r]
def test_add_tenant_access(self):
flavor = cs.flavors.get(2)
@ -41,7 +41,7 @@ class FlavorAccessTest(utils.TestCase):
}
cs.assert_called('POST', '/flavors/2/action', body)
[self.assertTrue(isinstance(a, flavor_access.FlavorAccess)) for a in r]
[self.assertIsInstance(a, flavor_access.FlavorAccess) for a in r]
def test_remove_tenant_access(self):
flavor = cs.flavors.get(2)
@ -55,4 +55,4 @@ class FlavorAccessTest(utils.TestCase):
}
cs.assert_called('POST', '/flavors/2/action', body)
[self.assertTrue(isinstance(a, flavor_access.FlavorAccess)) for a in r]
[self.assertIsInstance(a, flavor_access.FlavorAccess) for a in r]

View File

@ -35,36 +35,36 @@ class FlavorsTest(utils.TestCase):
fl = self.cs.flavors.list()
self.cs.assert_called('GET', '/flavors/detail')
for flavor in fl:
self.assertTrue(isinstance(flavor, self.flavor_type))
self.assertIsInstance(flavor, self.flavor_type)
def test_list_flavors_undetailed(self):
fl = self.cs.flavors.list(detailed=False)
self.cs.assert_called('GET', '/flavors')
for flavor in fl:
self.assertTrue(isinstance(flavor, self.flavor_type))
self.assertIsInstance(flavor, self.flavor_type)
def test_list_flavors_is_public_none(self):
fl = self.cs.flavors.list(is_public=None)
self.cs.assert_called('GET', '/flavors/detail?is_public=None')
for flavor in fl:
self.assertTrue(isinstance(flavor, self.flavor_type))
self.assertIsInstance(flavor, self.flavor_type)
def test_list_flavors_is_public_false(self):
fl = self.cs.flavors.list(is_public=False)
self.cs.assert_called('GET', '/flavors/detail?is_public=False')
for flavor in fl:
self.assertTrue(isinstance(flavor, self.flavor_type))
self.assertIsInstance(flavor, self.flavor_type)
def test_list_flavors_is_public_true(self):
fl = self.cs.flavors.list(is_public=True)
self.cs.assert_called('GET', '/flavors/detail')
for flavor in fl:
self.assertTrue(isinstance(flavor, self.flavor_type))
self.assertIsInstance(flavor, self.flavor_type)
def test_get_flavor_details(self):
f = self.cs.flavors.get(1)
self.cs.assert_called('GET', '/flavors/1')
self.assertTrue(isinstance(f, self.flavor_type))
self.assertIsInstance(f, self.flavor_type)
self.assertEqual(f.ram, 256)
self.assertEqual(f.disk, 10)
self.assertEqual(f.ephemeral, 10)
@ -73,7 +73,7 @@ class FlavorsTest(utils.TestCase):
def test_get_flavor_details_alphanum_id(self):
f = self.cs.flavors.get('aa1')
self.cs.assert_called('GET', '/flavors/aa1')
self.assertTrue(isinstance(f, self.flavor_type))
self.assertIsInstance(f, self.flavor_type)
self.assertEqual(f.ram, 128)
self.assertEqual(f.disk, 0)
self.assertEqual(f.ephemeral, 0)
@ -82,7 +82,7 @@ class FlavorsTest(utils.TestCase):
def test_get_flavor_details_diablo(self):
f = self.cs.flavors.get(3)
self.cs.assert_called('GET', '/flavors/3')
self.assertTrue(isinstance(f, self.flavor_type))
self.assertIsInstance(f, self.flavor_type)
self.assertEqual(f.ram, 256)
self.assertEqual(f.disk, 10)
self.assertEqual(f.ephemeral, 'N/A')
@ -123,7 +123,7 @@ class FlavorsTest(utils.TestCase):
False)
self.cs.assert_called('POST', '/flavors', body)
self.assertTrue(isinstance(f, self.flavor_type))
self.assertIsInstance(f, self.flavor_type)
def test_create_with_id_as_string(self):
flavor_id = 'foobar'
@ -135,7 +135,7 @@ class FlavorsTest(utils.TestCase):
1.0, False)
self.cs.assert_called('POST', '/flavors', body)
self.assertTrue(isinstance(f, self.flavor_type))
self.assertIsInstance(f, self.flavor_type)
def test_create_ephemeral_ispublic_defaults(self):
f = self.cs.flavors.create("flavorcreate", 512, 1, 10, 1234)
@ -144,7 +144,7 @@ class FlavorsTest(utils.TestCase):
1.0, True)
self.cs.assert_called('POST', '/flavors', body)
self.assertTrue(isinstance(f, self.flavor_type))
self.assertIsInstance(f, self.flavor_type)
def test_invalid_parameters_create(self):
self.assertRaises(exceptions.CommandError, self.cs.flavors.create,

View File

@ -28,8 +28,8 @@ class FloatingIPDNSDomainTest(utils.TestCase):
self.assertEqual(len(domainlist), 2)
for entry in domainlist:
self.assertTrue(isinstance(entry,
floating_ip_dns.FloatingIPDNSDomain))
self.assertIsInstance(entry,
floating_ip_dns.FloatingIPDNSDomain)
self.assertEqual(domainlist[1].domain, 'example.com')
@ -61,8 +61,8 @@ class FloatingIPDNSEntryTest(utils.TestCase):
self.assertEqual(len(entries), 2)
for entry in entries:
self.assertTrue(isinstance(entry,
floating_ip_dns.FloatingIPDNSEntry))
self.assertIsInstance(entry,
floating_ip_dns.FloatingIPDNSEntry)
self.assertEqual(entries[1].dns_entry['name'], 'host2')
self.assertEqual(entries[1].dns_entry['ip'], self.testip)
@ -70,7 +70,7 @@ class FloatingIPDNSEntryTest(utils.TestCase):
def test_get_dns_entry_by_name(self):
entry = cs.dns_entries.get(self.testdomain,
self.testname)
self.assertTrue(isinstance(entry, floating_ip_dns.FloatingIPDNSEntry))
self.assertIsInstance(entry, floating_ip_dns.FloatingIPDNSEntry)
self.assertEqual(entry.name, self.testname)
def test_create_entry(self):

View File

@ -27,5 +27,5 @@ class TestFloatingIPPools(utils.TestCase):
def test_list_floating_ips(self):
fl = cs.floating_ip_pools.list()
cs.assert_called('GET', '/os-floating-ip-pools')
[self.assertTrue(isinstance(f, floating_ip_pools.FloatingIPPool))
[self.assertIsInstance(f, floating_ip_pools.FloatingIPPool)
for f in fl]

View File

@ -27,7 +27,7 @@ class FloatingIPsTest(utils.TestCase):
def test_list_floating_ips(self):
fl = cs.floating_ips.list()
cs.assert_called('GET', '/os-floating-ips')
[self.assertTrue(isinstance(f, floating_ips.FloatingIP)) for f in fl]
[self.assertIsInstance(f, floating_ips.FloatingIP) for f in fl]
def test_delete_floating_ip(self):
fl = cs.floating_ips.list()[0]
@ -42,10 +42,10 @@ class FloatingIPsTest(utils.TestCase):
fl = cs.floating_ips.create()
cs.assert_called('POST', '/os-floating-ips')
self.assertEqual(fl.pool, None)
self.assertTrue(isinstance(fl, floating_ips.FloatingIP))
self.assertIsInstance(fl, floating_ips.FloatingIP)
def test_create_floating_ip_with_pool(self):
fl = cs.floating_ips.create('foo')
cs.assert_called('POST', '/os-floating-ips')
self.assertEqual(fl.pool, 'nova')
self.assertTrue(isinstance(fl, floating_ips.FloatingIP))
self.assertIsInstance(fl, floating_ips.FloatingIP)

View File

@ -26,13 +26,13 @@ class FloatingIPsBulkTest(utils.TestCase):
def test_list_floating_ips_bulk(self):
fl = cs.floating_ips_bulk.list()
cs.assert_called('GET', '/os-floating-ips-bulk')
[self.assertTrue(isinstance(f, floating_ips_bulk.FloatingIP))
[self.assertIsInstance(f, floating_ips_bulk.FloatingIP)
for f in fl]
def test_list_floating_ips_bulk_host_filter(self):
fl = cs.floating_ips_bulk.list('testHost')
cs.assert_called('GET', '/os-floating-ips-bulk/testHost')
[self.assertTrue(isinstance(f, floating_ips_bulk.FloatingIP))
[self.assertIsInstance(f, floating_ips_bulk.FloatingIP)
for f in fl]
def test_create_floating_ips_bulk(self):

View File

@ -31,31 +31,31 @@ class FpingTest(utils.TestCase):
fl = cs.fping.list()
cs.assert_called('GET', '/os-fping')
for f in fl:
self.assertTrue(isinstance(f, fping.Fping))
self.assertIsInstance(f, fping.Fping)
self.assertEqual(f.project_id, "fake-project")
self.assertEqual(f.alive, True)
def test_list_fpings_all_tenants(self):
fl = cs.fping.list(all_tenants=True)
for f in fl:
self.assertTrue(isinstance(f, fping.Fping))
self.assertIsInstance(f, fping.Fping)
cs.assert_called('GET', '/os-fping?all_tenants=1')
def test_list_fpings_exclude(self):
fl = cs.fping.list(exclude=['1'])
for f in fl:
self.assertTrue(isinstance(f, fping.Fping))
self.assertIsInstance(f, fping.Fping)
cs.assert_called('GET', '/os-fping?exclude=1')
def test_list_fpings_include(self):
fl = cs.fping.list(include=['1'])
for f in fl:
self.assertTrue(isinstance(f, fping.Fping))
self.assertIsInstance(f, fping.Fping)
cs.assert_called('GET', '/os-fping?include=1')
def test_get_fping(self):
f = cs.fping.get(1)
cs.assert_called('GET', '/os-fping/1')
self.assertTrue(isinstance(f, fping.Fping))
self.assertIsInstance(f, fping.Fping)
self.assertEqual(f.project_id, "fake-project")
self.assertEqual(f.alive, True)

View File

@ -24,18 +24,18 @@ class HostsTest(utils.TestCase):
def test_describe_resource(self):
hs = cs.hosts.get('host')
cs.assert_called('GET', '/os-hosts/host')
[self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
[self.assertIsInstance(h, hosts.Host) for h in hs]
def test_list_host(self):
hs = cs.hosts.list()
cs.assert_called('GET', '/os-hosts')
[self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
[self.assertIsInstance(h, hosts.Host) for h in hs]
[self.assertEqual(h.zone, 'nova1') for h in hs]
def test_list_host_with_zone(self):
hs = cs.hosts.list('nova')
cs.assert_called('GET', '/os-hosts?zone=nova')
[self.assertTrue(isinstance(h, hosts.Host)) for h in hs]
[self.assertIsInstance(h, hosts.Host) for h in hs]
[self.assertEqual(h.zone, 'nova') for h in hs]
def test_update_enable(self):
@ -43,14 +43,14 @@ class HostsTest(utils.TestCase):
values = {"status": "enabled"}
result = host.update(values)
cs.assert_called('PUT', '/os-hosts/sample_host', values)
self.assertTrue(isinstance(result, hosts.Host))
self.assertIsInstance(result, hosts.Host)
def test_update_maintenance(self):
host = cs.hosts.get('sample_host')[0]
values = {"maintenance_mode": "enable"}
result = host.update(values)
cs.assert_called('PUT', '/os-hosts/sample_host', values)
self.assertTrue(isinstance(result, hosts.Host))
self.assertIsInstance(result, hosts.Host)
def test_update_both(self):
host = cs.hosts.get('sample_host')[0]
@ -58,7 +58,7 @@ class HostsTest(utils.TestCase):
"maintenance_mode": "enable"}
result = host.update(values)
cs.assert_called('PUT', '/os-hosts/sample_host', values)
self.assertTrue(isinstance(result, hosts.Host))
self.assertIsInstance(result, hosts.Host)
def test_host_startup(self):
host = cs.hosts.get('sample_host')[0]

View File

@ -24,12 +24,12 @@ class ImagesTest(utils.TestCase):
def test_list_images(self):
il = cs.images.list()
cs.assert_called('GET', '/images/detail')
[self.assertTrue(isinstance(i, images.Image)) for i in il]
[self.assertIsInstance(i, images.Image) for i in il]
def test_list_images_undetailed(self):
il = cs.images.list(detailed=False)
cs.assert_called('GET', '/images')
[self.assertTrue(isinstance(i, images.Image)) for i in il]
[self.assertIsInstance(i, images.Image) for i in il]
def test_list_images_with_limit(self):
il = cs.images.list(limit=4)
@ -38,7 +38,7 @@ class ImagesTest(utils.TestCase):
def test_get_image_details(self):
i = cs.images.get(1)
cs.assert_called('GET', '/images/1')
self.assertTrue(isinstance(i, images.Image))
self.assertIsInstance(i, images.Image)
self.assertEqual(i.id, 1)
self.assertEqual(i.name, 'CentOS 5.2')

View File

@ -32,13 +32,13 @@ class KeypairsTest(utils.TestCase):
def test_get_keypair(self):
kp = self.cs.keypairs.get('test')
self.cs.assert_called('GET', '/%s/test' % self.keypair_prefix)
self.assertTrue(isinstance(kp, keypairs.Keypair))
self.assertIsInstance(kp, keypairs.Keypair)
self.assertEqual(kp.name, 'test')
def test_list_keypairs(self):
kps = self.cs.keypairs.list()
self.cs.assert_called('GET', '/%s' % self.keypair_prefix)
[self.assertTrue(isinstance(kp, keypairs.Keypair)) for kp in kps]
[self.assertIsInstance(kp, keypairs.Keypair) for kp in kps]
def test_delete_keypair(self):
kp = self.cs.keypairs.list()[0]
@ -52,9 +52,9 @@ class KeypairsTest(utils.TestCase):
def test_create_keypair(self):
kp = self.cs.keypairs.create("foo")
self.cs.assert_called('POST', '/%s' % self.keypair_prefix)
self.assertTrue(isinstance(kp, keypairs.Keypair))
self.assertIsInstance(kp, keypairs.Keypair)
def test_import_keypair(self):
kp = self.cs.keypairs.create("foo", "fake-public-key")
self.cs.assert_called('POST', '/%s' % self.keypair_prefix)
self.assertTrue(isinstance(kp, keypairs.Keypair))
self.assertIsInstance(kp, keypairs.Keypair)

View File

@ -24,12 +24,12 @@ class LimitsTest(utils.TestCase):
def test_get_limits(self):
obj = cs.limits.get()
cs.assert_called('GET', '/limits')
self.assertTrue(isinstance(obj, limits.Limits))
self.assertIsInstance(obj, limits.Limits)
def test_get_limits_for_a_tenant(self):
obj = cs.limits.get(tenant_id=1234)
cs.assert_called('GET', '/limits?tenant_id=1234')
self.assertTrue(isinstance(obj, limits.Limits))
self.assertIsInstance(obj, limits.Limits)
def test_absolute_limits(self):
obj = cs.limits.get()

View File

@ -24,12 +24,12 @@ class NetworksTest(utils.TestCase):
def test_list_networks(self):
fl = cs.networks.list()
cs.assert_called('GET', '/os-networks')
[self.assertTrue(isinstance(f, networks.Network)) for f in fl]
[self.assertIsInstance(f, networks.Network) for f in fl]
def test_get_network(self):
f = cs.networks.get(1)
cs.assert_called('GET', '/os-networks/1')
self.assertTrue(isinstance(f, networks.Network))
self.assertIsInstance(f, networks.Network)
def test_delete(self):
cs.networks.delete('networkdelete')
@ -39,7 +39,7 @@ class NetworksTest(utils.TestCase):
f = cs.networks.create(label='foo')
cs.assert_called('POST', '/os-networks',
{'network': {'label': 'foo'}})
self.assertTrue(isinstance(f, networks.Network))
self.assertIsInstance(f, networks.Network)
def test_create_allparams(self):
params = {
@ -62,7 +62,7 @@ class NetworksTest(utils.TestCase):
f = cs.networks.create(**params)
cs.assert_called('POST', '/os-networks', {'network': params})
self.assertTrue(isinstance(f, networks.Network))
self.assertIsInstance(f, networks.Network)
def test_associate_project(self):
cs.networks.associate_project('networktest')

View File

@ -24,7 +24,7 @@ class SecurityGroupsTest(utils.TestCase):
sgs = cs.security_groups.list(search_opts=search_opts)
cs.assert_called('GET', path)
for sg in sgs:
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
self.assertIsInstance(sg, security_groups.SecurityGroup)
def test_list_security_groups_all_tenants_on(self):
self._do_test_list_security_groups(
@ -41,7 +41,7 @@ class SecurityGroupsTest(utils.TestCase):
def test_get_security_groups(self):
sg = cs.security_groups.get(1)
cs.assert_called('GET', '/os-security-groups/1')
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
self.assertIsInstance(sg, security_groups.SecurityGroup)
self.assertEqual('1', str(sg))
def test_delete_security_group(self):
@ -56,13 +56,13 @@ class SecurityGroupsTest(utils.TestCase):
def test_create_security_group(self):
sg = cs.security_groups.create("foo", "foo barr")
cs.assert_called('POST', '/os-security-groups')
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
self.assertIsInstance(sg, security_groups.SecurityGroup)
def test_update_security_group(self):
sg = cs.security_groups.list()[0]
secgroup = cs.security_groups.update(sg, "update", "update")
cs.assert_called('PUT', '/os-security-groups/1')
self.assertTrue(isinstance(secgroup, security_groups.SecurityGroup))
self.assertIsInstance(secgroup, security_groups.SecurityGroup)
def test_refresh_security_group(self):
sg = cs.security_groups.get(1)

View File

@ -29,23 +29,23 @@ class ServersTest(utils.TestCase):
def test_list_servers(self):
sl = cs.servers.list()
cs.assert_called('GET', '/servers/detail')
[self.assertTrue(isinstance(s, servers.Server)) for s in sl]
[self.assertIsInstance(s, servers.Server) for s in sl]
def test_list_servers_undetailed(self):
sl = cs.servers.list(detailed=False)
cs.assert_called('GET', '/servers')
[self.assertTrue(isinstance(s, servers.Server)) for s in sl]
[self.assertIsInstance(s, servers.Server) for s in sl]
def test_list_servers_with_marker_limit(self):
sl = cs.servers.list(marker=1234, limit=2)
cs.assert_called('GET', '/servers/detail?limit=2&marker=1234')
for s in sl:
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_get_server_details(self):
s = cs.servers.get(1234)
cs.assert_called('GET', '/servers/1234')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
self.assertEqual(s.id, 1234)
self.assertEqual(s.status, 'BUILD')
@ -70,7 +70,7 @@ class ServersTest(utils.TestCase):
}
)
cs.assert_called('POST', '/servers')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_create_server_boot_from_volume_with_nics(self):
old_boot = cs.servers._boot
@ -100,7 +100,7 @@ class ServersTest(utils.TestCase):
nics=nics
)
cs.assert_called('POST', '/os-volumes_boot')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
test_create_server_from_volume()
@ -117,7 +117,7 @@ class ServersTest(utils.TestCase):
},
)
cs.assert_called('POST', '/servers')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_create_server_userdata_unicode(self):
s = cs.servers.create(
@ -133,7 +133,7 @@ class ServersTest(utils.TestCase):
},
)
cs.assert_called('POST', '/servers')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_create_server_userdata_utf8(self):
s = cs.servers.create(
@ -149,7 +149,7 @@ class ServersTest(utils.TestCase):
},
)
cs.assert_called('POST', '/servers')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def _create_disk_config(self, disk_config):
s = cs.servers.create(
@ -159,7 +159,7 @@ class ServersTest(utils.TestCase):
disk_config=disk_config
)
cs.assert_called('POST', '/servers')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
# verify disk config param was used in the request:
last_request = cs.client.callstack[-1]

View File

@ -34,7 +34,7 @@ class ServicesTest(utils.TestCase):
svs = self.cs.services.list()
self.cs.assert_called('GET', '/os-services')
for s in svs:
self.assertTrue(isinstance(s, self._get_service_type()))
self.assertIsInstance(s, self._get_service_type())
self.assertEqual(s.binary, 'nova-compute')
self.assertEqual(s.host, 'host1')
@ -42,7 +42,7 @@ class ServicesTest(utils.TestCase):
svs = self.cs.services.list(host='host2')
self.cs.assert_called('GET', '/os-services?host=host2')
for s in svs:
self.assertTrue(isinstance(s, self._get_service_type()))
self.assertIsInstance(s, self._get_service_type())
self.assertEqual(s.binary, 'nova-compute')
self.assertEqual(s.host, 'host2')
@ -50,7 +50,7 @@ class ServicesTest(utils.TestCase):
svs = self.cs.services.list(binary='nova-cert')
self.cs.assert_called('GET', '/os-services?binary=nova-cert')
for s in svs:
self.assertTrue(isinstance(s, self._get_service_type()))
self.assertIsInstance(s, self._get_service_type())
self.assertEqual(s.binary, 'nova-cert')
self.assertEqual(s.host, 'host1')
@ -59,7 +59,7 @@ class ServicesTest(utils.TestCase):
self.cs.assert_called('GET',
'/os-services?host=host2&binary=nova-cert')
for s in svs:
self.assertTrue(isinstance(s, self._get_service_type()))
self.assertIsInstance(s, self._get_service_type())
self.assertEqual(s.binary, 'nova-cert')
self.assertEqual(s.host, 'host2')
@ -74,14 +74,14 @@ class ServicesTest(utils.TestCase):
service = self.cs.services.enable('host1', 'nova-cert')
values = self._update_body("host1", "nova-cert")
self.cs.assert_called('PUT', '/os-services/enable', values)
self.assertTrue(isinstance(service, self._get_service_type()))
self.assertIsInstance(service, self._get_service_type())
self.assertEqual(service.status, 'enabled')
def test_services_disable(self):
service = self.cs.services.disable('host1', 'nova-cert')
values = self._update_body("host1", "nova-cert")
self.cs.assert_called('PUT', '/os-services/disable', values)
self.assertTrue(isinstance(service, self._get_service_type()))
self.assertIsInstance(service, self._get_service_type())
self.assertEqual(service.status, 'disabled')
def test_services_disable_log_reason(self):
@ -90,5 +90,5 @@ class ServicesTest(utils.TestCase):
values = self._update_body("compute1", "nova-compute",
"disable bad host")
self.cs.assert_called('PUT', '/os-services/disable-log-reason', values)
self.assertTrue(isinstance(service, self._get_service_type()))
self.assertIsInstance(service, self._get_service_type())
self.assertEqual(service.status, 'disabled')

View File

@ -39,7 +39,7 @@ class UsageTest(utils.TestCase):
("start=%s&" % now.isoformat()) +
("end=%s&" % now.isoformat()) +
("detailed=%s" % int(bool(detailed))))
[self.assertTrue(isinstance(u, usage.Usage)) for u in usages]
[self.assertIsInstance(u, usage.Usage) for u in usages]
def test_usage_list_detailed(self):
self.test_usage_list(True)
@ -52,4 +52,4 @@ class UsageTest(utils.TestCase):
"/os-simple-tenant-usage/tenantfoo?" +
("start=%s&" % now.isoformat()) +
("end=%s" % now.isoformat()))
self.assertTrue(isinstance(u, usage.Usage))
self.assertIsInstance(u, usage.Usage)

View File

@ -26,18 +26,18 @@ class VolumesTest(utils.TestCase):
def test_list_servers(self):
vl = cs.volumes.list()
cs.assert_called('GET', '/volumes/detail')
[self.assertTrue(isinstance(v, volumes.Volume)) for v in vl]
[self.assertIsInstance(v, volumes.Volume) for v in vl]
def test_list_volumes_undetailed(self):
vl = cs.volumes.list(detailed=False)
cs.assert_called('GET', '/volumes')
[self.assertTrue(isinstance(v, volumes.Volume)) for v in vl]
[self.assertIsInstance(v, volumes.Volume) for v in vl]
def test_get_volume_details(self):
vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
v = cs.volumes.get(vol_id)
cs.assert_called('GET', '/volumes/%s' % vol_id)
self.assertTrue(isinstance(v, volumes.Volume))
self.assertIsInstance(v, volumes.Volume)
self.assertEqual(v.id, vol_id)
def test_create_volume(self):
@ -47,7 +47,7 @@ class VolumesTest(utils.TestCase):
display_description="My volume desc",
)
cs.assert_called('POST', '/volumes')
self.assertTrue(isinstance(v, volumes.Volume))
self.assertIsInstance(v, volumes.Volume)
def test_delete_volume(self):
vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
@ -66,7 +66,7 @@ class VolumesTest(utils.TestCase):
device='/dev/vdb'
)
cs.assert_called('POST', '/servers/1234/os-volume_attachments')
self.assertTrue(isinstance(v, volumes.Volume))
self.assertIsInstance(v, volumes.Volume)
def test_update_server_volume(self):
vol_id = '15e59938-07d5-11e1-90e3-e3dffe0c5983'
@ -76,17 +76,17 @@ class VolumesTest(utils.TestCase):
new_volume_id=vol_id
)
cs.assert_called('PUT', '/servers/1234/os-volume_attachments/Work')
self.assertTrue(isinstance(v, volumes.Volume))
self.assertIsInstance(v, volumes.Volume)
def test_get_server_volume(self):
v = cs.volumes.get_server_volume(1234, 'Work')
cs.assert_called('GET', '/servers/1234/os-volume_attachments/Work')
self.assertTrue(isinstance(v, volumes.Volume))
self.assertIsInstance(v, volumes.Volume)
def test_list_server_volumes(self):
vl = cs.volumes.get_server_volumes(1234)
cs.assert_called('GET', '/servers/1234/os-volume_attachments')
[self.assertTrue(isinstance(v, volumes.Volume)) for v in vl]
[self.assertIsInstance(v, volumes.Volume) for v in vl]
def test_delete_server_volume(self):
cs.volumes.delete_server_volume(1234, 'Work')

View File

@ -29,8 +29,8 @@ class FlavorAccessTest(utils.TestCase):
r = cs.flavor_access.list(**kwargs)
cs.assert_called('GET', '/flavors/2/flavor-access')
for access_list in r:
self.assertTrue(isinstance(access_list,
flavor_access.FlavorAccess))
self.assertIsInstance(access_list,
flavor_access.FlavorAccess)
def test_add_tenant_access(self):
flavor = cs.flavors.get(2)
@ -45,7 +45,7 @@ class FlavorAccessTest(utils.TestCase):
cs.assert_called('POST', '/flavors/2/action', body)
for a in r:
self.assertTrue(isinstance(a, flavor_access.FlavorAccess))
self.assertIsInstance(a, flavor_access.FlavorAccess)
def test_remove_tenant_access(self):
flavor = cs.flavors.get(2)
@ -60,4 +60,4 @@ class FlavorAccessTest(utils.TestCase):
cs.assert_called('POST', '/flavors/2/action', body)
for a in r:
self.assertTrue(isinstance(a, flavor_access.FlavorAccess))
self.assertIsInstance(a, flavor_access.FlavorAccess)

View File

@ -26,20 +26,20 @@ class HostsTest(utils.TestCase):
hs = cs.hosts.get('host')
cs.assert_called('GET', '/os-hosts/host')
for h in hs:
self.assertTrue(isinstance(h, hosts.Host))
self.assertIsInstance(h, hosts.Host)
def test_list_host(self):
hs = cs.hosts.list()
cs.assert_called('GET', '/os-hosts')
for h in hs:
self.assertTrue(isinstance(h, hosts.Host))
self.assertIsInstance(h, hosts.Host)
self.assertEqual(h.zone, 'nova1')
def test_list_host_with_zone(self):
hs = cs.hosts.list('nova')
cs.assert_called('GET', '/os-hosts?zone=nova')
for h in hs:
self.assertTrue(isinstance(h, hosts.Host))
self.assertIsInstance(h, hosts.Host)
self.assertEqual(h.zone, 'nova')
def test_update_enable(self):
@ -47,14 +47,14 @@ class HostsTest(utils.TestCase):
values = {"status": "enabled"}
result = host.update(values)
cs.assert_called('PUT', '/os-hosts/sample_host', {"host": values})
self.assertTrue(isinstance(result, hosts.Host))
self.assertIsInstance(result, hosts.Host)
def test_update_maintenance(self):
host = cs.hosts.get('sample_host')[0]
values = {"maintenance_mode": "enable"}
result = host.update(values)
cs.assert_called('PUT', '/os-hosts/sample_host', {"host": values})
self.assertTrue(isinstance(result, hosts.Host))
self.assertIsInstance(result, hosts.Host)
def test_update_both(self):
host = cs.hosts.get('sample_host')[0]
@ -62,7 +62,7 @@ class HostsTest(utils.TestCase):
"maintenance_mode": "enable"}
result = host.update(values)
cs.assert_called('PUT', '/os-hosts/sample_host', {"host": values})
self.assertTrue(isinstance(result, hosts.Host))
self.assertIsInstance(result, hosts.Host)
def test_host_startup(self):
host = cs.hosts.get('sample_host')[0]

View File

@ -27,13 +27,13 @@ class ImagesTest(utils.TestCase):
il = cs.images.list()
cs.assert_called('GET', '/v1/images/detail')
for i in il:
self.assertTrue(isinstance(i, images.Image))
self.assertIsInstance(i, images.Image)
def test_list_images_undetailed(self):
il = cs.images.list(detailed=False)
cs.assert_called('GET', '/v1/images')
for i in il:
self.assertTrue(isinstance(i, images.Image))
self.assertIsInstance(i, images.Image)
def test_list_images_with_limit(self):
il = cs.images.list(limit=4)
@ -42,7 +42,7 @@ class ImagesTest(utils.TestCase):
def test_get_image_details(self):
i = cs.images.get(1)
cs.assert_called('HEAD', '/v1/images/1')
self.assertTrue(isinstance(i, images.Image))
self.assertIsInstance(i, images.Image)
self.assertEqual(i.id, '1')
self.assertEqual(i.name, 'CentOS 5.2')

View File

@ -30,24 +30,24 @@ class ServersTest(utils.TestCase):
sl = cs.servers.list()
cs.assert_called('GET', '/servers/detail')
for s in sl:
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_list_servers_undetailed(self):
sl = cs.servers.list(detailed=False)
cs.assert_called('GET', '/servers')
for s in sl:
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_list_servers_with_marker_limit(self):
sl = cs.servers.list(marker=1234, limit=2)
cs.assert_called('GET', '/servers/detail?limit=2&marker=1234')
for s in sl:
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_get_server_details(self):
s = cs.servers.get(1234)
cs.assert_called('GET', '/servers/1234')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
self.assertEqual(s.id, 1234)
self.assertEqual(s.status, 'BUILD')
@ -72,7 +72,7 @@ class ServersTest(utils.TestCase):
}
)
cs.assert_called('POST', '/servers')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_create_server_userdata_file_object(self):
s = cs.servers.create(
@ -87,7 +87,7 @@ class ServersTest(utils.TestCase):
},
)
cs.assert_called('POST', '/servers')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_create_server_userdata_unicode(self):
s = cs.servers.create(
@ -103,7 +103,7 @@ class ServersTest(utils.TestCase):
},
)
cs.assert_called('POST', '/servers')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_create_server_userdata_utf8(self):
s = cs.servers.create(
@ -119,7 +119,7 @@ class ServersTest(utils.TestCase):
},
)
cs.assert_called('POST', '/servers')
self.assertTrue(isinstance(s, servers.Server))
self.assertIsInstance(s, servers.Server)
def test_update_server(self):
s = cs.servers.get(1234)