[tests] initialize client objects inside setUp
All tests from contrib dir inizialize fakeclient at module level. It is bad practice and we should do preparatory steps at setUp method. Change-Id: I2dd2988cd015d1dfb576fe004cb9461b02b55db3
This commit is contained in:
parent
8c204ac1a2
commit
7d8db71964
@ -22,23 +22,23 @@ from novaclient.tests.unit.v2.contrib import fakes
|
||||
from novaclient.v2.contrib import assisted_volume_snapshots as assisted_snaps
|
||||
|
||||
|
||||
extensions = [
|
||||
extension.Extension(assisted_snaps.__name__.split(".")[-1],
|
||||
assisted_snaps),
|
||||
]
|
||||
cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
|
||||
class AssistedVolumeSnapshotsTestCase(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(AssistedVolumeSnapshotsTestCase, self).setUp()
|
||||
extensions = [
|
||||
extension.Extension(assisted_snaps.__name__.split(".")[-1],
|
||||
assisted_snaps),
|
||||
]
|
||||
self.cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
def test_create_snap(self):
|
||||
vs = cs.assisted_volume_snapshots.create('1', {})
|
||||
vs = self.cs.assisted_volume_snapshots.create('1', {})
|
||||
self.assert_request_id(vs, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-assisted-volume-snapshots')
|
||||
self.cs.assert_called('POST', '/os-assisted-volume-snapshots')
|
||||
|
||||
def test_delete_snap(self):
|
||||
vs = cs.assisted_volume_snapshots.delete('x', {})
|
||||
vs = self.cs.assisted_volume_snapshots.delete('x', {})
|
||||
self.assert_request_id(vs, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called(
|
||||
self.cs.assert_called(
|
||||
'DELETE',
|
||||
'/os-assisted-volume-snapshots/x?delete_info={}')
|
||||
|
@ -20,52 +20,52 @@ from novaclient.tests.unit.v2.contrib import fakes
|
||||
from novaclient.v2.contrib import baremetal
|
||||
|
||||
|
||||
extensions = [
|
||||
extension.Extension(baremetal.__name__.split(".")[-1], baremetal),
|
||||
]
|
||||
cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
|
||||
class BaremetalExtensionTest(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(BaremetalExtensionTest, self).setUp()
|
||||
extensions = [
|
||||
extension.Extension(baremetal.__name__.split(".")[-1], baremetal),
|
||||
]
|
||||
self.cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
def test_list_nodes(self):
|
||||
nl = cs.baremetal.list()
|
||||
nl = self.cs.baremetal.list()
|
||||
self.assert_request_id(nl, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-baremetal-nodes')
|
||||
self.cs.assert_called('GET', '/os-baremetal-nodes')
|
||||
for n in nl:
|
||||
self.assertIsInstance(n, baremetal.BareMetalNode)
|
||||
|
||||
def test_get_node(self):
|
||||
n = cs.baremetal.get(1)
|
||||
n = self.cs.baremetal.get(1)
|
||||
self.assert_request_id(n, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-baremetal-nodes/1')
|
||||
self.cs.assert_called('GET', '/os-baremetal-nodes/1')
|
||||
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")
|
||||
n = self.cs.baremetal.create("service_host", 1, 1024, 2048,
|
||||
"aa:bb:cc:dd:ee:ff")
|
||||
self.assert_request_id(n, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-baremetal-nodes')
|
||||
self.cs.assert_called('POST', '/os-baremetal-nodes')
|
||||
self.assertIsInstance(n, baremetal.BareMetalNode)
|
||||
|
||||
def test_delete_node(self):
|
||||
n = cs.baremetal.get(1)
|
||||
ret = cs.baremetal.delete(n)
|
||||
n = self.cs.baremetal.get(1)
|
||||
ret = self.cs.baremetal.delete(n)
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('DELETE', '/os-baremetal-nodes/1')
|
||||
self.cs.assert_called('DELETE', '/os-baremetal-nodes/1')
|
||||
|
||||
def test_node_add_interface(self):
|
||||
i = cs.baremetal.add_interface(1, "bb:cc:dd:ee:ff:aa", 1, 2)
|
||||
i = self.cs.baremetal.add_interface(1, "bb:cc:dd:ee:ff:aa", 1, 2)
|
||||
self.assert_request_id(i, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-baremetal-nodes/1/action')
|
||||
self.cs.assert_called('POST', '/os-baremetal-nodes/1/action')
|
||||
self.assertIsInstance(i, baremetal.BareMetalNodeInterface)
|
||||
|
||||
def test_node_remove_interface(self):
|
||||
ret = cs.baremetal.remove_interface(1, "bb:cc:dd:ee:ff:aa")
|
||||
ret = self.cs.baremetal.remove_interface(1, "bb:cc:dd:ee:ff:aa")
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-baremetal-nodes/1/action')
|
||||
self.cs.assert_called('POST', '/os-baremetal-nodes/1/action')
|
||||
|
||||
def test_node_list_interfaces(self):
|
||||
il = cs.baremetal.list_interfaces(1)
|
||||
il = self.cs.baremetal.list_interfaces(1)
|
||||
self.assert_request_id(il, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-baremetal-nodes/1')
|
||||
self.cs.assert_called('GET', '/os-baremetal-nodes/1')
|
||||
|
@ -19,27 +19,28 @@ from novaclient.tests.unit.v2.contrib import fakes
|
||||
from novaclient.v2.contrib import cells
|
||||
|
||||
|
||||
extensions = [
|
||||
extension.Extension(cells.__name__.split(".")[-1],
|
||||
cells),
|
||||
]
|
||||
cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
|
||||
class CellsExtensionTests(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(CellsExtensionTests, self).setUp()
|
||||
extensions = [
|
||||
extension.Extension(cells.__name__.split(".")[-1],
|
||||
cells),
|
||||
]
|
||||
self.cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
def test_get_cells(self):
|
||||
cell_name = 'child_cell'
|
||||
cell = cs.cells.get(cell_name)
|
||||
cell = self.cs.cells.get(cell_name)
|
||||
self.assert_request_id(cell, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-cells/%s' % cell_name)
|
||||
self.cs.assert_called('GET', '/os-cells/%s' % cell_name)
|
||||
|
||||
def test_get_capacities_for_a_given_cell(self):
|
||||
cell_name = 'child_cell'
|
||||
ca = cs.cells.capacities(cell_name)
|
||||
ca = self.cs.cells.capacities(cell_name)
|
||||
self.assert_request_id(ca, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-cells/%s/capacities' % cell_name)
|
||||
self.cs.assert_called('GET', '/os-cells/%s/capacities' % cell_name)
|
||||
|
||||
def test_get_capacities_for_all_cells(self):
|
||||
ca = cs.cells.capacities()
|
||||
ca = self.cs.cells.capacities()
|
||||
self.assert_request_id(ca, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-cells/capacities')
|
||||
self.cs.assert_called('GET', '/os-cells/capacities')
|
||||
|
@ -19,27 +19,28 @@ from novaclient.tests.unit.v2.contrib import fakes
|
||||
from novaclient.v2.contrib import instance_action
|
||||
|
||||
|
||||
extensions = [
|
||||
extension.Extension(instance_action.__name__.split(".")[-1],
|
||||
instance_action),
|
||||
]
|
||||
cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
|
||||
class InstanceActionExtensionTests(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(InstanceActionExtensionTests, self).setUp()
|
||||
extensions = [
|
||||
extension.Extension(instance_action.__name__.split(".")[-1],
|
||||
instance_action),
|
||||
]
|
||||
self.cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
def test_list_instance_actions(self):
|
||||
server_uuid = '1234'
|
||||
ial = cs.instance_action.list(server_uuid)
|
||||
ial = self.cs.instance_action.list(server_uuid)
|
||||
self.assert_request_id(ial, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called(
|
||||
self.cs.assert_called(
|
||||
'GET', '/servers/%s/os-instance-actions' %
|
||||
server_uuid)
|
||||
|
||||
def test_get_instance_action(self):
|
||||
server_uuid = '1234'
|
||||
request_id = 'req-abcde12345'
|
||||
ia = cs.instance_action.get(server_uuid, request_id)
|
||||
ia = self.cs.instance_action.get(server_uuid, request_id)
|
||||
self.assert_request_id(ia, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called(
|
||||
self.cs.assert_called(
|
||||
'GET', '/servers/%s/os-instance-actions/%s'
|
||||
% (server_uuid, request_id))
|
||||
|
@ -17,18 +17,19 @@ from novaclient.tests.unit.v2 import fakes
|
||||
from novaclient.v2.contrib import list_extensions
|
||||
|
||||
|
||||
extensions = [
|
||||
extension.Extension(list_extensions.__name__.split(".")[-1],
|
||||
list_extensions),
|
||||
]
|
||||
cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
|
||||
class ListExtensionsTests(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(ListExtensionsTests, self).setUp()
|
||||
extensions = [
|
||||
extension.Extension(list_extensions.__name__.split(".")[-1],
|
||||
list_extensions),
|
||||
]
|
||||
self.cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
def test_list_extensions(self):
|
||||
all_exts = cs.list_extensions.show_all()
|
||||
all_exts = self.cs.list_extensions.show_all()
|
||||
self.assert_request_id(all_exts, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/extensions')
|
||||
self.cs.assert_called('GET', '/extensions')
|
||||
self.assertTrue(len(all_exts) > 0)
|
||||
for r in all_exts:
|
||||
self.assertTrue(len(r.summary) > 0)
|
||||
|
@ -16,25 +16,26 @@ from novaclient.tests.unit import utils
|
||||
from novaclient.tests.unit.v2 import fakes
|
||||
from novaclient.v2.contrib import migrations
|
||||
|
||||
extensions = [
|
||||
extension.Extension(migrations.__name__.split(".")[-1],
|
||||
migrations),
|
||||
]
|
||||
cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
|
||||
class MigrationsTest(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(MigrationsTest, self).setUp()
|
||||
self.extensions = [
|
||||
extension.Extension(migrations.__name__.split(".")[-1],
|
||||
migrations),
|
||||
]
|
||||
self.cs = fakes.FakeClient(extensions=self.extensions)
|
||||
|
||||
def test_list_migrations(self):
|
||||
ml = cs.migrations.list()
|
||||
ml = self.cs.migrations.list()
|
||||
self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-migrations')
|
||||
self.cs.assert_called('GET', '/os-migrations')
|
||||
for m in ml:
|
||||
self.assertIsInstance(m, migrations.Migration)
|
||||
self.assertRaises(AttributeError, getattr, m, "migration_type")
|
||||
|
||||
def test_list_migrations_v223(self):
|
||||
cs = fakes.FakeClient(extensions=extensions,
|
||||
cs = fakes.FakeClient(extensions=self.extensions,
|
||||
api_version=api_versions.APIVersion("2.23"))
|
||||
ml = cs.migrations.list()
|
||||
self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST)
|
||||
@ -44,11 +45,11 @@ class MigrationsTest(utils.TestCase):
|
||||
self.assertEqual(m.migration_type, 'live-migration')
|
||||
|
||||
def test_list_migrations_with_filters(self):
|
||||
ml = cs.migrations.list('host1', 'finished', 'child1')
|
||||
ml = self.cs.migrations.list('host1', 'finished', 'child1')
|
||||
self.assert_request_id(ml, fakes.FAKE_REQUEST_ID_LIST)
|
||||
|
||||
cs.assert_called('GET',
|
||||
'/os-migrations?cell_name=child1&host=host1'
|
||||
'&status=finished')
|
||||
self.cs.assert_called(
|
||||
'GET',
|
||||
'/os-migrations?cell_name=child1&host=host1&status=finished')
|
||||
for m in ml:
|
||||
self.assertIsInstance(m, migrations.Migration)
|
||||
|
@ -22,14 +22,15 @@ from novaclient.tests.unit.v2.contrib import fakes
|
||||
from novaclient.v2.contrib import server_external_events as ext_events
|
||||
|
||||
|
||||
extensions = [
|
||||
extension.Extension(ext_events.__name__.split(".")[-1],
|
||||
ext_events),
|
||||
]
|
||||
cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
|
||||
class ServerExternalEventsTestCase(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(ServerExternalEventsTestCase, self).setUp()
|
||||
extensions = [
|
||||
extension.Extension(ext_events.__name__.split(".")[-1],
|
||||
ext_events),
|
||||
]
|
||||
self.cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
def test_external_event(self):
|
||||
events = [{'server_uuid': 'fake-uuid1',
|
||||
'name': 'test-event',
|
||||
@ -39,7 +40,7 @@ class ServerExternalEventsTestCase(utils.TestCase):
|
||||
'name': 'test-event',
|
||||
'status': 'completed',
|
||||
'tag': 'tag'}]
|
||||
result = cs.server_external_events.create(events)
|
||||
result = self.cs.server_external_events.create(events)
|
||||
self.assert_request_id(result, fakes.FAKE_REQUEST_ID_LIST)
|
||||
self.assertEqual(events, result)
|
||||
cs.assert_called('POST', '/os-server-external-events')
|
||||
self.cs.assert_called('POST', '/os-server-external-events')
|
||||
|
@ -19,32 +19,34 @@ from novaclient.tests.unit.v2.contrib import fakes
|
||||
from novaclient.v2.contrib import tenant_networks
|
||||
|
||||
|
||||
extensions = [
|
||||
extension.Extension(tenant_networks.__name__.split(".")[-1],
|
||||
tenant_networks),
|
||||
]
|
||||
cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
|
||||
class TenantNetworkExtensionTests(utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TenantNetworkExtensionTests, self).setUp()
|
||||
extensions = [
|
||||
extension.Extension(tenant_networks.__name__.split(".")[-1],
|
||||
tenant_networks),
|
||||
]
|
||||
self.cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
def test_list_tenant_networks(self):
|
||||
nets = cs.tenant_networks.list()
|
||||
nets = self.cs.tenant_networks.list()
|
||||
self.assert_request_id(nets, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-tenant-networks')
|
||||
self.cs.assert_called('GET', '/os-tenant-networks')
|
||||
self.assertTrue(len(nets) > 0)
|
||||
|
||||
def test_get_tenant_network(self):
|
||||
net = cs.tenant_networks.get(1)
|
||||
net = self.cs.tenant_networks.get(1)
|
||||
self.assert_request_id(net, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('GET', '/os-tenant-networks/1')
|
||||
self.cs.assert_called('GET', '/os-tenant-networks/1')
|
||||
|
||||
def test_create_tenant_networks(self):
|
||||
net = cs.tenant_networks.create(label="net",
|
||||
cidr="10.0.0.0/24")
|
||||
net = self.cs.tenant_networks.create(label="net",
|
||||
cidr="10.0.0.0/24")
|
||||
self.assert_request_id(net, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('POST', '/os-tenant-networks')
|
||||
self.cs.assert_called('POST', '/os-tenant-networks')
|
||||
|
||||
def test_delete_tenant_networks(self):
|
||||
ret = cs.tenant_networks.delete(1)
|
||||
ret = self.cs.tenant_networks.delete(1)
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
cs.assert_called('DELETE', '/os-tenant-networks/1')
|
||||
self.cs.assert_called('DELETE', '/os-tenant-networks/1')
|
||||
|
Loading…
Reference in New Issue
Block a user