diff --git a/openstackclient/tests/common/test_extension.py b/openstackclient/tests/common/test_extension.py index 0736a3e54d..17a3b492dd 100644 --- a/openstackclient/tests/common/test_extension.py +++ b/openstackclient/tests/common/test_extension.py @@ -11,7 +11,6 @@ # under the License. # -import copy import mock from openstackclient.common import extension @@ -29,26 +28,38 @@ class TestExtension(utils.TestCommand): def setUp(self): super(TestExtension, self).setUp() - self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client( + identity_client = identity_fakes.FakeIdentityv2Client( endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN, ) - self.identity_extensions_mock = ( - self.app.client_manager.identity.extensions) + self.app.client_manager.identity = identity_client + self.identity_extensions_mock = identity_client.extensions self.identity_extensions_mock.reset_mock() - self.app.client_manager.compute = compute_fakes.FakeComputev2Client( + compute_client = compute_fakes.FakeComputev2Client( endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN, ) + self.app.client_manager.compute = compute_client + compute_client.list_extensions = mock.Mock() + self.compute_extensions_mock = compute_client.list_extensions + self.compute_extensions_mock.reset_mock() - self.app.client_manager.volume = volume_fakes.FakeVolumeClient( + volume_client = volume_fakes.FakeVolumeClient( endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN, ) + self.app.client_manager.volume = volume_client + volume_client.list_extensions = mock.Mock() + self.volume_extensions_mock = volume_client.list_extensions + self.volume_extensions_mock.reset_mock() - network_client = network_fakes.FakeNetworkV2Client() + network_client = network_fakes.FakeNetworkV2Client( + endpoint=fakes.AUTH_URL, + token=fakes.AUTH_TOKEN, + ) self.app.client_manager.network = network_client + network_client.extensions = mock.Mock() self.network_extensions_mock = network_client.extensions self.network_extensions_mock.reset_mock() @@ -59,38 +70,21 @@ class TestExtensionList(TestExtension): long_columns = ('Name', 'Namespace', 'Description', 'Alias', 'Updated', 'Links') + volume_extension = volume_fakes.FakeExtension.create_one_extension() + identity_extension = identity_fakes.FakeExtension.create_one_extension() + compute_extension = compute_fakes.FakeExtension.create_one_extension() + network_extension = network_fakes.FakeExtension.create_one_extension() + def setUp(self): super(TestExtensionList, self).setUp() self.identity_extensions_mock.list.return_value = [ - fakes.FakeResource( - None, - copy.deepcopy(identity_fakes.EXTENSION), - loaded=True, - ), - ] - - self.app.client_manager.compute.list_extensions = mock.Mock() - self.compute_extensions_mock = ( - self.app.client_manager.compute.list_extensions) + self.identity_extension] self.compute_extensions_mock.show_all.return_value = [ - fakes.FakeResource( - None, - copy.deepcopy(compute_fakes.EXTENSION), - loaded=True, - ), - ] - - self.app.client_manager.volume.list_extensions = mock.Mock() - self.volume_extensions_mock = ( - self.app.client_manager.volume.list_extensions) + self.compute_extension] self.volume_extensions_mock.show_all.return_value = [ - fakes.FakeResource( - None, - copy.deepcopy(volume_fakes.EXTENSION), - loaded=True, - ), - ] + self.volume_extension] + self.network_extensions_mock.return_value = [self.network_extension] # Get the command object to test self.cmd = extension.ListExtension(self.app, None) @@ -115,24 +109,24 @@ class TestExtensionList(TestExtension): verifylist = [] datalist = ( ( - identity_fakes.extension_name, - identity_fakes.extension_alias, - identity_fakes.extension_description, + self.identity_extension.name, + self.identity_extension.alias, + self.identity_extension.description, ), ( - compute_fakes.extension_name, - compute_fakes.extension_alias, - compute_fakes.extension_description, + self.compute_extension.name, + self.compute_extension.alias, + self.compute_extension.description, ), ( - volume_fakes.extension_name, - volume_fakes.extension_alias, - volume_fakes.extension_description, + self.volume_extension.name, + self.volume_extension.alias, + self.volume_extension.description, ), ( - network_fakes.extension_name, - network_fakes.extension_alias, - network_fakes.extension_description, + self.network_extension.name, + self.network_extension.alias, + self.network_extension.description, ), ) self._test_extension_list_helper(arglist, verifylist, datalist) @@ -150,36 +144,36 @@ class TestExtensionList(TestExtension): ] datalist = ( ( - identity_fakes.extension_name, - identity_fakes.extension_namespace, - identity_fakes.extension_description, - identity_fakes.extension_alias, - identity_fakes.extension_updated, - identity_fakes.extension_links, + self.identity_extension.name, + self.identity_extension.namespace, + self.identity_extension.description, + self.identity_extension.alias, + self.identity_extension.updated, + self.identity_extension.links, ), ( - compute_fakes.extension_name, - compute_fakes.extension_namespace, - compute_fakes.extension_description, - compute_fakes.extension_alias, - compute_fakes.extension_updated, - compute_fakes.extension_links, + self.compute_extension.name, + self.compute_extension.namespace, + self.compute_extension.description, + self.compute_extension.alias, + self.compute_extension.updated, + self.compute_extension.links, ), ( - volume_fakes.extension_name, - volume_fakes.extension_namespace, - volume_fakes.extension_description, - volume_fakes.extension_alias, - volume_fakes.extension_updated, - volume_fakes.extension_links, + self.volume_extension.name, + self.volume_extension.namespace, + self.volume_extension.description, + self.volume_extension.alias, + self.volume_extension.updated, + self.volume_extension.links, ), ( - network_fakes.extension_name, - network_fakes.extension_namespace, - network_fakes.extension_description, - network_fakes.extension_alias, - network_fakes.extension_updated, - network_fakes.extension_links, + self.network_extension.name, + self.network_extension.namespace, + self.network_extension.description, + self.network_extension.alias, + self.network_extension.updated, + self.network_extension.links, ), ) self._test_extension_list_helper(arglist, verifylist, datalist, True) @@ -196,9 +190,9 @@ class TestExtensionList(TestExtension): ('identity', True), ] datalist = (( - identity_fakes.extension_name, - identity_fakes.extension_alias, - identity_fakes.extension_description, + self.identity_extension.name, + self.identity_extension.alias, + self.identity_extension.description, ), ) self._test_extension_list_helper(arglist, verifylist, datalist) self.identity_extensions_mock.list.assert_called_with() @@ -212,9 +206,9 @@ class TestExtensionList(TestExtension): ] datalist = ( ( - network_fakes.extension_name, - network_fakes.extension_alias, - network_fakes.extension_description, + self.network_extension.name, + self.network_extension.alias, + self.network_extension.description, ), ) self._test_extension_list_helper(arglist, verifylist, datalist) @@ -228,9 +222,9 @@ class TestExtensionList(TestExtension): ('compute', True), ] datalist = (( - compute_fakes.extension_name, - compute_fakes.extension_alias, - compute_fakes.extension_description, + self.compute_extension.name, + self.compute_extension.alias, + self.compute_extension.description, ), ) self._test_extension_list_helper(arglist, verifylist, datalist) self.compute_extensions_mock.show_all.assert_called_with() @@ -243,9 +237,9 @@ class TestExtensionList(TestExtension): ('volume', True), ] datalist = (( - volume_fakes.extension_name, - volume_fakes.extension_alias, - volume_fakes.extension_description, + self.volume_extension.name, + self.volume_extension.alias, + self.volume_extension.description, ), ) self._test_extension_list_helper(arglist, verifylist, datalist) self.volume_extensions_mock.show_all.assert_called_with() diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index c9e2025dc0..9682eec470 100644 --- a/openstackclient/tests/compute/v2/fakes.py +++ b/openstackclient/tests/compute/v2/fakes.py @@ -24,26 +24,6 @@ from openstackclient.tests.network.v2 import fakes as network_fakes from openstackclient.tests import utils from openstackclient.tests.volume.v2 import fakes as volume_fakes - -extension_name = 'Multinic' -extension_namespace = 'http://docs.openstack.org/compute/ext/'\ - 'multinic/api/v1.1' -extension_description = 'Multiple network support' -extension_updated = '2014-01-07T12:00:0-00:00' -extension_alias = 'NMN' -extension_links = '[{"href":'\ - '"https://github.com/openstack/compute-api", "type":'\ - ' "text/html", "rel": "describedby"}]' - -EXTENSION = { - 'name': extension_name, - 'namespace': extension_namespace, - 'description': extension_description, - 'updated': extension_updated, - 'alias': extension_alias, - 'links': extension_links, -} - floating_ip_num = 100 fix_ip_num = 100 injected_file_num = 100 @@ -259,6 +239,42 @@ class FakeAgent(object): return agents +class FakeExtension(object): + """Fake one or more extension.""" + + @staticmethod + def create_one_extension(attrs=None): + """Create a fake extension. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with name, namespace, etc. + """ + attrs = attrs or {} + + # Set default attributes. + extension_info = { + 'name': 'name-' + uuid.uuid4().hex, + 'namespace': ( + 'http://docs.openstack.org/compute/ext/multinic/api/v1.1'), + 'description': 'description-' + uuid.uuid4().hex, + 'updated': '2014-01-07T12:00:0-00:00', + 'alias': 'NMN', + 'links': ('[{"href":' + '"https://github.com/openstack/compute-api", "type":' + ' "text/html", "rel": "describedby"}]') + } + + # Overwrite default attributes. + extension_info.update(attrs) + + extension = fakes.FakeResource( + info=copy.deepcopy(extension_info), + loaded=True) + return extension + + class FakeHypervisor(object): """Fake one or more hypervisor.""" diff --git a/openstackclient/tests/identity/v2_0/fakes.py b/openstackclient/tests/identity/v2_0/fakes.py index b37bd9da2f..b80938729a 100644 --- a/openstackclient/tests/identity/v2_0/fakes.py +++ b/openstackclient/tests/identity/v2_0/fakes.py @@ -13,7 +13,9 @@ # under the License. # +import copy import mock +import uuid from openstackclient.tests import fakes from openstackclient.tests import utils @@ -106,26 +108,6 @@ ENDPOINT = { 'service_id': endpoint_service_id, } -extension_name = 'OpenStack Keystone User CRUD' -extension_namespace = 'http://docs.openstack.org/identity/'\ - 'api/ext/OS-KSCRUD/v1.0' -extension_description = 'OpenStack extensions to Keystone v2.0 API'\ - ' enabling User Operations.' -extension_updated = '2013-07-07T12:00:0-00:00' -extension_alias = 'OS-KSCRUD' -extension_links = '[{"href":'\ - '"https://github.com/openstack/identity-api", "type":'\ - ' "text/html", "rel": "describedby"}]' - -EXTENSION = { - 'name': extension_name, - 'namespace': extension_namespace, - 'description': extension_description, - 'updated': extension_updated, - 'alias': extension_alias, - 'links': extension_links, -} - class FakeIdentityv2Client(object): @@ -166,3 +148,39 @@ class TestIdentityv2(utils.TestCommand): endpoint=fakes.AUTH_URL, token=fakes.AUTH_TOKEN, ) + + +class FakeExtension(object): + """Fake one or more extension.""" + + @staticmethod + def create_one_extension(attrs=None): + """Create a fake extension. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with name, namespace, etc. + """ + attrs = attrs or {} + + # Set default attributes. + extension_info = { + 'name': 'name-' + uuid.uuid4().hex, + 'namespace': ('http://docs.openstack.org/identity/' + 'api/ext/OS-KSCRUD/v1.0'), + 'description': 'description-' + uuid.uuid4().hex, + 'updated': '2013-07-07T12:00:0-00:00', + 'alias': 'OS-KSCRUD', + 'links': ('[{"href":' + '"https://github.com/openstack/identity-api", "type":' + ' "text/html", "rel": "describedby"}]') + } + + # Overwrite default attributes. + extension_info.update(attrs) + + extension = fakes.FakeResource( + info=copy.deepcopy(extension_info), + loaded=True) + return extension diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py index ccbe395b7c..9efbe8c608 100644 --- a/openstackclient/tests/network/v2/fakes.py +++ b/openstackclient/tests/network/v2/fakes.py @@ -19,12 +19,6 @@ import uuid from openstackclient.tests import fakes from openstackclient.tests import utils -extension_name = 'Matrix' -extension_namespace = 'http://docs.openstack.org/network/' -extension_description = 'Simulated reality' -extension_updated = '2013-07-09T12:00:0-00:00' -extension_alias = 'Dystopian' -extension_links = '[{"href":''"https://github.com/os/network", "type"}]' QUOTA = { "subnet": 10, @@ -42,21 +36,11 @@ QUOTA = { } -def create_extension(): - extension = mock.Mock() - extension.name = extension_name - extension.namespace = extension_namespace - extension.description = extension_description - extension.updated = extension_updated - extension.alias = extension_alias - extension.links = extension_links - return extension - - class FakeNetworkV2Client(object): def __init__(self, **kwargs): - self.extensions = mock.Mock(return_value=[create_extension()]) + self.extensions = mock.Mock() + self.extensions.resource_class = fakes.FakeResource(None, {}) class TestNetworkV2(utils.TestCommand): @@ -240,6 +224,39 @@ class FakeIPAvailability(object): return network_ip_availabilities +class FakeExtension(object): + """Fake one or more extension.""" + + @staticmethod + def create_one_extension(attrs=None): + """Create a fake extension. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with name, namespace, etc. + """ + attrs = attrs or {} + + # Set default attributes. + extension_info = { + 'name': 'name-' + uuid.uuid4().hex, + 'namespace': 'http://docs.openstack.org/network/', + 'description': 'description-' + uuid.uuid4().hex, + 'updated': '2013-07-09T12:00:0-00:00', + 'alias': 'Dystopian', + 'links': '[{"href":''"https://github.com/os/network", "type"}]', + } + + # Overwrite default attributes. + extension_info.update(attrs) + + extension = fakes.FakeResource( + info=copy.deepcopy(extension_info), + loaded=True) + return extension + + class FakeNetwork(object): """Fake one or more networks.""" diff --git a/openstackclient/tests/volume/v2/fakes.py b/openstackclient/tests/volume/v2/fakes.py index e61fe8aaca..3571890a41 100644 --- a/openstackclient/tests/volume/v2/fakes.py +++ b/openstackclient/tests/volume/v2/fakes.py @@ -211,26 +211,6 @@ IMAGE = { 'name': image_name } -extension_name = 'SchedulerHints' -extension_namespace = 'http://docs.openstack.org/'\ - 'block-service/ext/scheduler-hints/api/v2' -extension_description = 'Pass arbitrary key/value'\ - 'pairs to the scheduler.' -extension_updated = '2013-04-18T00:00:00+00:00' -extension_alias = 'OS-SCH-HNT' -extension_links = '[{"href":'\ - '"https://github.com/openstack/block-api", "type":'\ - ' "text/html", "rel": "describedby"}]' - -EXTENSION = { - 'name': extension_name, - 'namespace': extension_namespace, - 'description': extension_description, - 'updated': extension_updated, - 'alias': extension_alias, - 'links': extension_links, -} - class FakeTransferClient(object): @@ -379,6 +359,8 @@ class FakeVolumeClient(object): def __init__(self, **kwargs): self.volumes = mock.Mock() self.volumes.resource_class = fakes.FakeResource(None, {}) + self.extensions = mock.Mock() + self.extensions.resource_class = fakes.FakeResource(None, {}) self.volume_snapshots = mock.Mock() self.volume_snapshots.resource_class = fakes.FakeResource(None, {}) self.backups = mock.Mock() @@ -643,6 +625,42 @@ class FakeBackup(object): return backups +class FakeExtension(object): + """Fake one or more extension.""" + + @staticmethod + def create_one_extension(attrs=None): + """Create a fake extension. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with name, namespace, etc. + """ + attrs = attrs or {} + + # Set default attributes. + extension_info = { + 'name': 'name-' + uuid.uuid4().hex, + 'namespace': ('http://docs.openstack.org/' + 'block-service/ext/scheduler-hints/api/v2'), + 'description': 'description-' + uuid.uuid4().hex, + 'updated': '2013-04-18T00:00:00+00:00', + 'alias': 'OS-SCH-HNT', + 'links': ('[{"href":' + '"https://github.com/openstack/block-api", "type":' + ' "text/html", "rel": "describedby"}]'), + } + + # Overwrite default attributes. + extension_info.update(attrs) + + extension = fakes.FakeResource( + info=copy.deepcopy(extension_info), + loaded=True) + return extension + + class FakeQos(object): """Fake one or more Qos specification."""