summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/common/test_extension.py157
-rw-r--r--openstackclient/tests/compute/v2/fakes.py58
-rw-r--r--openstackclient/tests/compute/v2/test_security_group.py127
-rw-r--r--openstackclient/tests/identity/v3/test_consumer.py78
-rw-r--r--openstackclient/tests/identity/v3/test_identity_provider.py80
-rw-r--r--openstackclient/tests/identity/v3/test_mappings.py70
-rw-r--r--openstackclient/tests/identity/v3/test_oauth.py80
-rw-r--r--openstackclient/tests/identity/v3/test_service_provider.py82
-rw-r--r--openstackclient/tests/identity/v3/test_unscoped_saml.py44
-rw-r--r--openstackclient/tests/network/v2/fakes.py37
-rw-r--r--openstackclient/tests/network/v2/test_security_group.py278
-rw-r--r--openstackclient/tests/network/v2/test_subnet_pool.py206
-rw-r--r--openstackclient/tests/utils.py24
-rw-r--r--openstackclient/tests/volume/v2/fakes.py20
14 files changed, 883 insertions, 458 deletions
diff --git a/openstackclient/tests/common/test_extension.py b/openstackclient/tests/common/test_extension.py
index 66532827..0736a3e5 100644
--- a/openstackclient/tests/common/test_extension.py
+++ b/openstackclient/tests/common/test_extension.py
@@ -12,13 +12,16 @@
#
import copy
+import mock
from openstackclient.common import extension
from openstackclient.tests import fakes
from openstackclient.tests import utils
+from openstackclient.tests.compute.v2 import fakes as compute_fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.network.v2 import fakes as network_fakes
+from openstackclient.tests.volume.v2 import fakes as volume_fakes
class TestExtension(utils.TestCommand):
@@ -34,6 +37,16 @@ class TestExtension(utils.TestCommand):
self.app.client_manager.identity.extensions)
self.identity_extensions_mock.reset_mock()
+ self.app.client_manager.compute = compute_fakes.FakeComputev2Client(
+ endpoint=fakes.AUTH_URL,
+ token=fakes.AUTH_TOKEN,
+ )
+
+ self.app.client_manager.volume = volume_fakes.FakeVolumeClient(
+ endpoint=fakes.AUTH_URL,
+ token=fakes.AUTH_TOKEN,
+ )
+
network_client = network_fakes.FakeNetworkV2Client()
self.app.client_manager.network = network_client
self.network_extensions_mock = network_client.extensions
@@ -43,6 +56,8 @@ class TestExtension(utils.TestCommand):
class TestExtensionList(TestExtension):
columns = ('Name', 'Alias', 'Description')
+ long_columns = ('Name', 'Namespace', 'Description', 'Alias', 'Updated',
+ 'Links')
def setUp(self):
super(TestExtensionList, self).setUp()
@@ -55,12 +70,33 @@ class TestExtensionList(TestExtension):
),
]
+ self.app.client_manager.compute.list_extensions = mock.Mock()
+ self.compute_extensions_mock = (
+ self.app.client_manager.compute.list_extensions)
+ 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.volume_extensions_mock.show_all.return_value = [
+ fakes.FakeResource(
+ None,
+ copy.deepcopy(volume_fakes.EXTENSION),
+ loaded=True,
+ ),
+ ]
+
# Get the command object to test
self.cmd = extension.ListExtension(self.app, None)
- def test_extension_list_no_options(self):
- arglist = []
- verifylist = []
+ def _test_extension_list_helper(self, arglist, verifylist,
+ expected_data, long=False):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# In base command class Lister in cliff, abstract method take_action()
@@ -68,10 +104,15 @@ class TestExtensionList(TestExtension):
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
- # no args should output from all services
- self.identity_extensions_mock.list.assert_called_with()
+ if long:
+ self.assertEqual(self.long_columns, columns)
+ else:
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(expected_data, tuple(data))
- self.assertEqual(self.columns, columns)
+ def test_extension_list_no_options(self):
+ arglist = []
+ verifylist = []
datalist = (
(
identity_fakes.extension_name,
@@ -79,12 +120,26 @@ class TestExtensionList(TestExtension):
identity_fakes.extension_description,
),
(
+ compute_fakes.extension_name,
+ compute_fakes.extension_alias,
+ compute_fakes.extension_description,
+ ),
+ (
+ volume_fakes.extension_name,
+ volume_fakes.extension_alias,
+ volume_fakes.extension_description,
+ ),
+ (
network_fakes.extension_name,
network_fakes.extension_alias,
network_fakes.extension_description,
),
)
- self.assertEqual(datalist, tuple(data))
+ self._test_extension_list_helper(arglist, verifylist, datalist)
+ self.identity_extensions_mock.list.assert_called_with()
+ self.compute_extensions_mock.show_all.assert_called_with()
+ self.volume_extensions_mock.show_all.assert_called_with()
+ self.network_extensions_mock.assert_called_with()
def test_extension_list_long(self):
arglist = [
@@ -93,19 +148,6 @@ class TestExtensionList(TestExtension):
verifylist = [
('long', True),
]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- # no args should output from all services
- self.identity_extensions_mock.list.assert_called_with()
-
- collist = ('Name', 'Namespace', 'Description', 'Alias', 'Updated',
- 'Links')
- self.assertEqual(collist, columns)
datalist = (
(
identity_fakes.extension_name,
@@ -116,6 +158,22 @@ class TestExtensionList(TestExtension):
identity_fakes.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,
+ ),
+ (
+ volume_fakes.extension_name,
+ volume_fakes.extension_namespace,
+ volume_fakes.extension_description,
+ volume_fakes.extension_alias,
+ volume_fakes.extension_updated,
+ volume_fakes.extension_links,
+ ),
+ (
network_fakes.extension_name,
network_fakes.extension_namespace,
network_fakes.extension_description,
@@ -124,7 +182,11 @@ class TestExtensionList(TestExtension):
network_fakes.extension_links,
),
)
- self.assertEqual(datalist, tuple(data))
+ self._test_extension_list_helper(arglist, verifylist, datalist, True)
+ self.identity_extensions_mock.list.assert_called_with()
+ self.compute_extensions_mock.show_all.assert_called_with()
+ self.volume_extensions_mock.show_all.assert_called_with()
+ self.network_extensions_mock.assert_called_with()
def test_extension_list_identity(self):
arglist = [
@@ -133,22 +195,13 @@ class TestExtensionList(TestExtension):
verifylist = [
('identity', True),
]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- self.identity_extensions_mock.list.assert_called_with()
-
- self.assertEqual(self.columns, columns)
datalist = ((
identity_fakes.extension_name,
identity_fakes.extension_alias,
identity_fakes.extension_description,
), )
- self.assertEqual(datalist, tuple(data))
+ self._test_extension_list_helper(arglist, verifylist, datalist)
+ self.identity_extensions_mock.list.assert_called_with()
def test_extension_list_network(self):
arglist = [
@@ -157,13 +210,6 @@ class TestExtensionList(TestExtension):
verifylist = [
('network', True),
]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.network_extensions_mock.assert_called_with()
-
- self.assertEqual(self.columns, columns)
datalist = (
(
network_fakes.extension_name,
@@ -171,4 +217,35 @@ class TestExtensionList(TestExtension):
network_fakes.extension_description,
),
)
- self.assertEqual(datalist, tuple(data))
+ self._test_extension_list_helper(arglist, verifylist, datalist)
+ self.network_extensions_mock.assert_called_with()
+
+ def test_extension_list_compute(self):
+ arglist = [
+ '--compute',
+ ]
+ verifylist = [
+ ('compute', True),
+ ]
+ datalist = ((
+ compute_fakes.extension_name,
+ compute_fakes.extension_alias,
+ compute_fakes.extension_description,
+ ), )
+ self._test_extension_list_helper(arglist, verifylist, datalist)
+ self.compute_extensions_mock.show_all.assert_called_with()
+
+ def test_extension_list_volume(self):
+ arglist = [
+ '--volume',
+ ]
+ verifylist = [
+ ('volume', True),
+ ]
+ datalist = ((
+ volume_fakes.extension_name,
+ volume_fakes.extension_alias,
+ volume_fakes.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 f735fe42..26d3a283 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -333,7 +333,9 @@ class FakeSecurityGroup(object):
security_group_attrs.update(attrs)
# Set default methods.
- security_group_methods = {}
+ security_group_methods = {
+ 'keys': ['id', 'name', 'description', 'tenant_id', 'rules'],
+ }
# Overwrite default methods.
security_group_methods.update(methods)
@@ -369,7 +371,7 @@ class FakeSecurityGroupRule(object):
"""Fake one or more security group rules."""
@staticmethod
- def create_one_security_group_rule(attrs={}, methods={}):
+ def create_one_security_group_rule(attrs=None, methods=None):
"""Create a fake security group rule.
:param Dictionary attrs:
@@ -379,6 +381,11 @@ class FakeSecurityGroupRule(object):
:return:
A FakeResource object, with id, etc.
"""
+ if attrs is None:
+ attrs = {}
+ if methods is None:
+ methods = {}
+
# Set default attributes.
security_group_rule_attrs = {
'from_port': -1,
@@ -406,7 +413,7 @@ class FakeSecurityGroupRule(object):
return security_group_rule
@staticmethod
- def create_security_group_rules(attrs={}, methods={}, count=2):
+ def create_security_group_rules(attrs=None, methods=None, count=2):
"""Create multiple fake security group rules.
:param Dictionary attrs:
@@ -501,42 +508,21 @@ class FakeServer(object):
return mock.MagicMock(side_effect=servers)
-class FakeFlavorResource(fakes.FakeResource):
- """Fake flavor object's methods to help test.
-
- The flavor object has three methods to get, set, unset its properties.
- Need to fake them, otherwise the functions to be tested won't run properly.
- """
-
- def __init__(self, manager=None, info={}, loaded=False, methods={}):
- super(FakeFlavorResource, self).__init__(manager, info,
- loaded, methods)
- # Fake properties.
- self._keys = {'property': 'value'}
-
- def set_keys(self, args):
- self._keys.update(args)
-
- def unset_keys(self, keys):
- for key in keys:
- self._keys.pop(key, None)
-
- def get_keys(self):
- return self._keys
-
-
class FakeFlavor(object):
"""Fake one or more flavors."""
@staticmethod
- def create_one_flavor(attrs={}):
+ def create_one_flavor(attrs=None):
"""Create a fake flavor.
:param Dictionary attrs:
A dictionary with all attributes
:return:
- A FakeFlavorResource object, with id, name, ram, vcpus, properties
+ A FakeResource object, with id, name, ram, vcpus, properties
"""
+ if attrs is None:
+ attrs = {}
+
# Set default attributes.
flavor_info = {
'id': 'flavor-id-' + uuid.uuid4().hex,
@@ -554,7 +540,15 @@ class FakeFlavor(object):
# Overwrite default attributes.
flavor_info.update(attrs)
- flavor = FakeFlavorResource(info=copy.deepcopy(flavor_info),
+ # Set default methods.
+ flavor_methods = {
+ 'set_keys': None,
+ 'unset_keys': None,
+ 'get_keys': {'property': 'value'},
+ }
+
+ flavor = fakes.FakeResource(info=copy.deepcopy(flavor_info),
+ methods=flavor_methods,
loaded=True)
# Set attributes with special mappings in nova client.
@@ -573,7 +567,7 @@ class FakeFlavor(object):
:param int count:
The number of flavors to fake
:return:
- A list of FakeFlavorResource objects faking the flavors
+ A list of FakeResource objects faking the flavors
"""
flavors = []
for i in range(0, count):
@@ -589,7 +583,7 @@ class FakeFlavor(object):
list. Otherwise create one.
:param List flavors:
- A list of FakeFlavorResource objects faking flavors
+ A list of FakeResource objects faking flavors
:param int count:
The number of flavors to fake
:return:
diff --git a/openstackclient/tests/compute/v2/test_security_group.py b/openstackclient/tests/compute/v2/test_security_group.py
deleted file mode 100644
index 01e27b82..00000000
--- a/openstackclient/tests/compute/v2/test_security_group.py
+++ /dev/null
@@ -1,127 +0,0 @@
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-#
-
-import copy
-
-from openstackclient.compute.v2 import security_group
-from openstackclient.tests.compute.v2 import fakes as compute_fakes
-from openstackclient.tests import fakes
-from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
-
-
-security_group_id = '11'
-security_group_name = 'wide-open'
-security_group_description = 'nothing but net'
-
-SECURITY_GROUP = {
- 'id': security_group_id,
- 'name': security_group_name,
- 'description': security_group_description,
- 'tenant_id': identity_fakes.project_id,
-}
-
-
-class FakeSecurityGroupResource(fakes.FakeResource):
-
- def get_keys(self):
- return {'property': 'value'}
-
-
-class TestSecurityGroup(compute_fakes.TestComputev2):
-
- def setUp(self):
- super(TestSecurityGroup, self).setUp()
-
- # Get a shortcut compute client security_groups mock
- self.secgroups_mock = self.app.client_manager.compute.security_groups
- self.secgroups_mock.reset_mock()
-
- # Get a shortcut identity client projects mock
- self.projects_mock = self.app.client_manager.identity.projects
- self.projects_mock.reset_mock()
-
-
-class TestSecurityGroupCreate(TestSecurityGroup):
-
- columns = (
- 'description',
- 'id',
- 'name',
- 'tenant_id',
- )
- data = (
- security_group_description,
- security_group_id,
- security_group_name,
- identity_fakes.project_id,
- )
-
- def setUp(self):
- super(TestSecurityGroupCreate, self).setUp()
-
- self.secgroups_mock.create.return_value = FakeSecurityGroupResource(
- None,
- copy.deepcopy(SECURITY_GROUP),
- loaded=True,
- )
-
- # Get the command object to test
- self.cmd = security_group.CreateSecurityGroup(self.app, None)
-
- def test_security_group_create_no_options(self):
- arglist = [
- security_group_name,
- ]
- verifylist = [
- ('name', security_group_name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class ShowOne in cliff, abstract method take_action()
- # returns a two-part tuple with a tuple of column names and a tuple of
- # data to be shown.
- columns, data = self.cmd.take_action(parsed_args)
-
- # SecurityGroupManager.create(name, description)
- self.secgroups_mock.create.assert_called_with(
- security_group_name,
- security_group_name,
- )
-
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
- def test_security_group_create_description(self):
- arglist = [
- security_group_name,
- '--description', security_group_description,
- ]
- verifylist = [
- ('name', security_group_name),
- ('description', security_group_description),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class ShowOne in cliff, abstract method take_action()
- # returns a two-part tuple with a tuple of column names and a tuple of
- # data to be shown.
- columns, data = self.cmd.take_action(parsed_args)
-
- # SecurityGroupManager.create(name, description)
- self.secgroups_mock.create.assert_called_with(
- security_group_name,
- security_group_description,
- )
-
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
diff --git a/openstackclient/tests/identity/v3/test_consumer.py b/openstackclient/tests/identity/v3/test_consumer.py
index 4d15d5d8..4a8cf087 100644
--- a/openstackclient/tests/identity/v3/test_consumer.py
+++ b/openstackclient/tests/identity/v3/test_consumer.py
@@ -136,45 +136,6 @@ class TestConsumerList(TestOAuth1):
self.assertEqual(datalist, tuple(data))
-class TestConsumerShow(TestOAuth1):
-
- def setUp(self):
- super(TestConsumerShow, self).setUp()
-
- consumer_no_secret = copy.deepcopy(identity_fakes.OAUTH_CONSUMER)
- del consumer_no_secret['secret']
- self.consumers_mock.get.return_value = fakes.FakeResource(
- None,
- consumer_no_secret,
- loaded=True,
- )
-
- # Get the command object to test
- self.cmd = consumer.ShowConsumer(self.app, None)
-
- def test_consumer_show(self):
- arglist = [
- identity_fakes.consumer_id,
- ]
- verifylist = [
- ('consumer', identity_fakes.consumer_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- columns, data = self.cmd.take_action(parsed_args)
-
- self.consumers_mock.get.assert_called_with(
- identity_fakes.consumer_id,
- )
-
- collist = ('description', 'id')
- self.assertEqual(collist, columns)
- datalist = (
- identity_fakes.consumer_description,
- identity_fakes.consumer_id,
- )
- self.assertEqual(datalist, data)
-
-
class TestConsumerSet(TestOAuth1):
def setUp(self):
@@ -217,3 +178,42 @@ class TestConsumerSet(TestOAuth1):
**kwargs
)
self.assertIsNone(result)
+
+
+class TestConsumerShow(TestOAuth1):
+
+ def setUp(self):
+ super(TestConsumerShow, self).setUp()
+
+ consumer_no_secret = copy.deepcopy(identity_fakes.OAUTH_CONSUMER)
+ del consumer_no_secret['secret']
+ self.consumers_mock.get.return_value = fakes.FakeResource(
+ None,
+ consumer_no_secret,
+ loaded=True,
+ )
+
+ # Get the command object to test
+ self.cmd = consumer.ShowConsumer(self.app, None)
+
+ def test_consumer_show(self):
+ arglist = [
+ identity_fakes.consumer_id,
+ ]
+ verifylist = [
+ ('consumer', identity_fakes.consumer_id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.consumers_mock.get.assert_called_with(
+ identity_fakes.consumer_id,
+ )
+
+ collist = ('description', 'id')
+ self.assertEqual(collist, columns)
+ datalist = (
+ identity_fakes.consumer_description,
+ identity_fakes.consumer_id,
+ )
+ self.assertEqual(datalist, data)
diff --git a/openstackclient/tests/identity/v3/test_identity_provider.py b/openstackclient/tests/identity/v3/test_identity_provider.py
index 1ee7aade..465e79ba 100644
--- a/openstackclient/tests/identity/v3/test_identity_provider.py
+++ b/openstackclient/tests/identity/v3/test_identity_provider.py
@@ -310,46 +310,6 @@ class TestIdentityProviderList(TestIdentityProvider):
self.assertEqual(datalist, tuple(data))
-class TestIdentityProviderShow(TestIdentityProvider):
-
- def setUp(self):
- super(TestIdentityProviderShow, self).setUp()
-
- ret = fakes.FakeResource(
- None,
- copy.deepcopy(identity_fakes.IDENTITY_PROVIDER),
- loaded=True,
- )
- self.identity_providers_mock.get.return_value = ret
- # Get the command object to test
- self.cmd = identity_provider.ShowIdentityProvider(self.app, None)
-
- def test_identity_provider_show(self):
- arglist = [
- identity_fakes.idp_id,
- ]
- verifylist = [
- ('identity_provider', identity_fakes.idp_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.identity_providers_mock.get.assert_called_with(
- identity_fakes.idp_id,
- )
-
- collist = ('description', 'enabled', 'id', 'remote_ids')
- self.assertEqual(collist, columns)
- datalist = (
- identity_fakes.idp_description,
- True,
- identity_fakes.idp_id,
- identity_fakes.formatted_idp_remote_ids
- )
- self.assertEqual(datalist, data)
-
-
class TestIdentityProviderSet(TestIdentityProvider):
columns = (
@@ -627,3 +587,43 @@ class TestIdentityProviderSet(TestIdentityProvider):
# neither --enable nor --disable was specified
self.assertIsNone(columns)
self.assertIsNone(data)
+
+
+class TestIdentityProviderShow(TestIdentityProvider):
+
+ def setUp(self):
+ super(TestIdentityProviderShow, self).setUp()
+
+ ret = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.IDENTITY_PROVIDER),
+ loaded=True,
+ )
+ self.identity_providers_mock.get.return_value = ret
+ # Get the command object to test
+ self.cmd = identity_provider.ShowIdentityProvider(self.app, None)
+
+ def test_identity_provider_show(self):
+ arglist = [
+ identity_fakes.idp_id,
+ ]
+ verifylist = [
+ ('identity_provider', identity_fakes.idp_id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.identity_providers_mock.get.assert_called_with(
+ identity_fakes.idp_id,
+ )
+
+ collist = ('description', 'enabled', 'id', 'remote_ids')
+ self.assertEqual(collist, columns)
+ datalist = (
+ identity_fakes.idp_description,
+ True,
+ identity_fakes.idp_id,
+ identity_fakes.formatted_idp_remote_ids
+ )
+ self.assertEqual(datalist, data)
diff --git a/openstackclient/tests/identity/v3/test_mappings.py b/openstackclient/tests/identity/v3/test_mappings.py
index 106a419c..b9e3b1d5 100644
--- a/openstackclient/tests/identity/v3/test_mappings.py
+++ b/openstackclient/tests/identity/v3/test_mappings.py
@@ -145,41 +145,6 @@ class TestMappingList(TestMapping):
self.assertEqual(datalist, data)
-class TestMappingShow(TestMapping):
-
- def setUp(self):
- super(TestMappingShow, self).setUp()
-
- self.mapping_mock.get.return_value = fakes.FakeResource(
- None,
- copy.deepcopy(identity_fakes.MAPPING_RESPONSE),
- loaded=True
- )
-
- self.cmd = mapping.ShowMapping(self.app, None)
-
- def test_mapping_show(self):
- arglist = [
- identity_fakes.mapping_id
- ]
- verifylist = [
- ('mapping', identity_fakes.mapping_id)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.mapping_mock.get.assert_called_with(
- identity_fakes.mapping_id)
-
- collist = ('id', 'rules')
- self.assertEqual(collist, columns)
-
- datalist = (identity_fakes.mapping_id,
- identity_fakes.MAPPING_RULES)
- self.assertEqual(datalist, data)
-
-
class TestMappingSet(TestMapping):
def setUp(self):
@@ -242,3 +207,38 @@ class TestMappingSet(TestMapping):
exceptions.CommandError,
self.cmd.take_action,
parsed_args)
+
+
+class TestMappingShow(TestMapping):
+
+ def setUp(self):
+ super(TestMappingShow, self).setUp()
+
+ self.mapping_mock.get.return_value = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.MAPPING_RESPONSE),
+ loaded=True
+ )
+
+ self.cmd = mapping.ShowMapping(self.app, None)
+
+ def test_mapping_show(self):
+ arglist = [
+ identity_fakes.mapping_id
+ ]
+ verifylist = [
+ ('mapping', identity_fakes.mapping_id)
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.mapping_mock.get.assert_called_with(
+ identity_fakes.mapping_id)
+
+ collist = ('id', 'rules')
+ self.assertEqual(collist, columns)
+
+ datalist = (identity_fakes.mapping_id,
+ identity_fakes.MAPPING_RULES)
+ self.assertEqual(datalist, data)
diff --git a/openstackclient/tests/identity/v3/test_oauth.py b/openstackclient/tests/identity/v3/test_oauth.py
index dba6d034..d3cf3655 100644
--- a/openstackclient/tests/identity/v3/test_oauth.py
+++ b/openstackclient/tests/identity/v3/test_oauth.py
@@ -32,52 +32,52 @@ class TestOAuth1(identity_fakes.TestOAuth1):
self.roles_mock.reset_mock()
-class TestRequestTokenCreate(TestOAuth1):
+class TestAccessTokenCreate(TestOAuth1):
def setUp(self):
- super(TestRequestTokenCreate, self).setUp()
-
- self.request_tokens_mock.create.return_value = fakes.FakeResource(
- None,
- copy.deepcopy(identity_fakes.OAUTH_REQUEST_TOKEN),
- loaded=True,
- )
+ super(TestAccessTokenCreate, self).setUp()
- self.projects_mock.get.return_value = fakes.FakeResource(
+ self.access_tokens_mock.create.return_value = fakes.FakeResource(
None,
- copy.deepcopy(identity_fakes.PROJECT),
+ copy.deepcopy(identity_fakes.OAUTH_ACCESS_TOKEN),
loaded=True,
)
- self.cmd = token.CreateRequestToken(self.app, None)
+ self.cmd = token.CreateAccessToken(self.app, None)
- def test_create_request_tokens(self):
+ def test_create_access_tokens(self):
arglist = [
'--consumer-key', identity_fakes.consumer_id,
'--consumer-secret', identity_fakes.consumer_secret,
- '--project', identity_fakes.project_id,
+ '--request-key', identity_fakes.request_token_id,
+ '--request-secret', identity_fakes.request_token_secret,
+ '--verifier', identity_fakes.oauth_verifier_pin,
]
verifylist = [
('consumer_key', identity_fakes.consumer_id),
('consumer_secret', identity_fakes.consumer_secret),
- ('project', identity_fakes.project_id),
+ ('request_key', identity_fakes.request_token_id),
+ ('request_secret', identity_fakes.request_token_secret),
+ ('verifier', identity_fakes.oauth_verifier_pin),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
- self.request_tokens_mock.create.assert_called_with(
+ self.access_tokens_mock.create.assert_called_with(
identity_fakes.consumer_id,
identity_fakes.consumer_secret,
- identity_fakes.project_id,
+ identity_fakes.request_token_id,
+ identity_fakes.request_token_secret,
+ identity_fakes.oauth_verifier_pin,
)
collist = ('expires', 'id', 'key', 'secret')
self.assertEqual(collist, columns)
datalist = (
- identity_fakes.request_token_expires,
- identity_fakes.request_token_id,
- identity_fakes.request_token_id,
- identity_fakes.request_token_secret,
+ identity_fakes.access_token_expires,
+ identity_fakes.access_token_id,
+ identity_fakes.access_token_id,
+ identity_fakes.access_token_secret,
)
self.assertEqual(datalist, data)
@@ -123,51 +123,51 @@ class TestRequestTokenAuthorize(TestOAuth1):
self.assertEqual(datalist, data)
-class TestAccessTokenCreate(TestOAuth1):
+class TestRequestTokenCreate(TestOAuth1):
def setUp(self):
- super(TestAccessTokenCreate, self).setUp()
+ super(TestRequestTokenCreate, self).setUp()
- self.access_tokens_mock.create.return_value = fakes.FakeResource(
+ self.request_tokens_mock.create.return_value = fakes.FakeResource(
None,
- copy.deepcopy(identity_fakes.OAUTH_ACCESS_TOKEN),
+ copy.deepcopy(identity_fakes.OAUTH_REQUEST_TOKEN),
loaded=True,
)
- self.cmd = token.CreateAccessToken(self.app, None)
+ self.projects_mock.get.return_value = fakes.FakeResource(
+ None,
+ copy.deepcopy(identity_fakes.PROJECT),
+ loaded=True,
+ )
- def test_create_access_tokens(self):
+ self.cmd = token.CreateRequestToken(self.app, None)
+
+ def test_create_request_tokens(self):
arglist = [
'--consumer-key', identity_fakes.consumer_id,
'--consumer-secret', identity_fakes.consumer_secret,
- '--request-key', identity_fakes.request_token_id,
- '--request-secret', identity_fakes.request_token_secret,
- '--verifier', identity_fakes.oauth_verifier_pin,
+ '--project', identity_fakes.project_id,
]
verifylist = [
('consumer_key', identity_fakes.consumer_id),
('consumer_secret', identity_fakes.consumer_secret),
- ('request_key', identity_fakes.request_token_id),
- ('request_secret', identity_fakes.request_token_secret),
- ('verifier', identity_fakes.oauth_verifier_pin),
+ ('project', identity_fakes.project_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
- self.access_tokens_mock.create.assert_called_with(
+ self.request_tokens_mock.create.assert_called_with(
identity_fakes.consumer_id,
identity_fakes.consumer_secret,
- identity_fakes.request_token_id,
- identity_fakes.request_token_secret,
- identity_fakes.oauth_verifier_pin,
+ identity_fakes.project_id,
)
collist = ('expires', 'id', 'key', 'secret')
self.assertEqual(collist, columns)
datalist = (
- identity_fakes.access_token_expires,
- identity_fakes.access_token_id,
- identity_fakes.access_token_id,
- identity_fakes.access_token_secret,
+ identity_fakes.request_token_expires,
+ identity_fakes.request_token_id,
+ identity_fakes.request_token_id,
+ identity_fakes.request_token_secret,
)
self.assertEqual(datalist, data)
diff --git a/openstackclient/tests/identity/v3/test_service_provider.py b/openstackclient/tests/identity/v3/test_service_provider.py
index b1285b10..80d60c5a 100644
--- a/openstackclient/tests/identity/v3/test_service_provider.py
+++ b/openstackclient/tests/identity/v3/test_service_provider.py
@@ -241,47 +241,6 @@ class TestServiceProviderList(TestServiceProvider):
self.assertEqual(tuple(data), datalist)
-class TestServiceProviderShow(TestServiceProvider):
-
- def setUp(self):
- super(TestServiceProviderShow, self).setUp()
-
- ret = fakes.FakeResource(
- None,
- copy.deepcopy(service_fakes.SERVICE_PROVIDER),
- loaded=True,
- )
- self.service_providers_mock.get.return_value = ret
- # Get the command object to test
- self.cmd = service_provider.ShowServiceProvider(self.app, None)
-
- def test_service_provider_show(self):
- arglist = [
- service_fakes.sp_id,
- ]
- verifylist = [
- ('service_provider', service_fakes.sp_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.service_providers_mock.get.assert_called_with(
- service_fakes.sp_id,
- )
-
- collist = ('auth_url', 'description', 'enabled', 'id', 'sp_url')
- self.assertEqual(collist, columns)
- datalist = (
- service_fakes.sp_auth_url,
- service_fakes.sp_description,
- True,
- service_fakes.sp_id,
- service_fakes.service_provider_url
- )
- self.assertEqual(data, datalist)
-
-
class TestServiceProviderSet(TestServiceProvider):
columns = (
@@ -420,3 +379,44 @@ class TestServiceProviderSet(TestServiceProvider):
# was set.
self.assertIsNone(columns)
self.assertIsNone(data)
+
+
+class TestServiceProviderShow(TestServiceProvider):
+
+ def setUp(self):
+ super(TestServiceProviderShow, self).setUp()
+
+ ret = fakes.FakeResource(
+ None,
+ copy.deepcopy(service_fakes.SERVICE_PROVIDER),
+ loaded=True,
+ )
+ self.service_providers_mock.get.return_value = ret
+ # Get the command object to test
+ self.cmd = service_provider.ShowServiceProvider(self.app, None)
+
+ def test_service_provider_show(self):
+ arglist = [
+ service_fakes.sp_id,
+ ]
+ verifylist = [
+ ('service_provider', service_fakes.sp_id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.service_providers_mock.get.assert_called_with(
+ service_fakes.sp_id,
+ )
+
+ collist = ('auth_url', 'description', 'enabled', 'id', 'sp_url')
+ self.assertEqual(collist, columns)
+ datalist = (
+ service_fakes.sp_auth_url,
+ service_fakes.sp_description,
+ True,
+ service_fakes.sp_id,
+ service_fakes.service_provider_url
+ )
+ self.assertEqual(data, datalist)
diff --git a/openstackclient/tests/identity/v3/test_unscoped_saml.py b/openstackclient/tests/identity/v3/test_unscoped_saml.py
index c2f14493..d12cb454 100644
--- a/openstackclient/tests/identity/v3/test_unscoped_saml.py
+++ b/openstackclient/tests/identity/v3/test_unscoped_saml.py
@@ -30,23 +30,23 @@ class TestUnscopedSAML(identity_fakes.TestFederatedIdentity):
self.domains_mock.reset_mock()
-class TestProjectList(TestUnscopedSAML):
+class TestDomainList(TestUnscopedSAML):
def setUp(self):
- super(TestProjectList, self).setUp()
+ super(TestDomainList, self).setUp()
- self.projects_mock.list.return_value = [
+ self.domains_mock.list.return_value = [
fakes.FakeResource(
None,
- copy.deepcopy(identity_fakes.PROJECT),
+ copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
),
]
# Get the command object to test
- self.cmd = unscoped_saml.ListAccessibleProjects(self.app, None)
+ self.cmd = unscoped_saml.ListAccessibleDomains(self.app, None)
- def test_accessible_projects_list(self):
+ def test_accessible_domains_list(self):
self.app.client_manager.auth_plugin_name = 'v3unscopedsaml'
arglist = []
verifylist = []
@@ -57,19 +57,19 @@ class TestProjectList(TestUnscopedSAML):
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
- self.projects_mock.list.assert_called_with()
+ self.domains_mock.list.assert_called_with()
- collist = ('ID', 'Domain ID', 'Enabled', 'Name')
+ collist = ('ID', 'Enabled', 'Name', 'Description')
self.assertEqual(collist, columns)
datalist = ((
- identity_fakes.project_id,
identity_fakes.domain_id,
True,
- identity_fakes.project_name,
+ identity_fakes.domain_name,
+ identity_fakes.domain_description,
), )
self.assertEqual(datalist, tuple(data))
- def test_accessible_projects_list_wrong_auth(self):
+ def test_accessible_domains_list_wrong_auth(self):
auth = identity_fakes.FakeAuth("wrong auth")
self.app.client_manager.identity.session.auth = auth
arglist = []
@@ -81,23 +81,23 @@ class TestProjectList(TestUnscopedSAML):
parsed_args)
-class TestDomainList(TestUnscopedSAML):
+class TestProjectList(TestUnscopedSAML):
def setUp(self):
- super(TestDomainList, self).setUp()
+ super(TestProjectList, self).setUp()
- self.domains_mock.list.return_value = [
+ self.projects_mock.list.return_value = [
fakes.FakeResource(
None,
- copy.deepcopy(identity_fakes.DOMAIN),
+ copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
),
]
# Get the command object to test
- self.cmd = unscoped_saml.ListAccessibleDomains(self.app, None)
+ self.cmd = unscoped_saml.ListAccessibleProjects(self.app, None)
- def test_accessible_domains_list(self):
+ def test_accessible_projects_list(self):
self.app.client_manager.auth_plugin_name = 'v3unscopedsaml'
arglist = []
verifylist = []
@@ -108,19 +108,19 @@ class TestDomainList(TestUnscopedSAML):
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
- self.domains_mock.list.assert_called_with()
+ self.projects_mock.list.assert_called_with()
- collist = ('ID', 'Enabled', 'Name', 'Description')
+ collist = ('ID', 'Domain ID', 'Enabled', 'Name')
self.assertEqual(collist, columns)
datalist = ((
+ identity_fakes.project_id,
identity_fakes.domain_id,
True,
- identity_fakes.domain_name,
- identity_fakes.domain_description,
+ identity_fakes.project_name,
), )
self.assertEqual(datalist, tuple(data))
- def test_accessible_domains_list_wrong_auth(self):
+ def test_accessible_projects_list_wrong_auth(self):
auth = identity_fakes.FakeAuth("wrong auth")
self.app.client_manager.identity.session.auth = auth
arglist = []
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index 9e6bf97f..2672d8e1 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -419,7 +419,7 @@ class FakeSecurityGroup(object):
"""Fake one or more security groups."""
@staticmethod
- def create_one_security_group(attrs={}, methods={}):
+ def create_one_security_group(attrs=None, methods=None):
"""Create a fake security group.
:param Dictionary attrs:
@@ -429,6 +429,11 @@ class FakeSecurityGroup(object):
:return:
A FakeResource object, with id, name, etc.
"""
+ if attrs is None:
+ attrs = {}
+ if methods is None:
+ methods = {}
+
# Set default attributes.
security_group_attrs = {
'id': 'security-group-id-' + uuid.uuid4().hex,
@@ -442,7 +447,10 @@ class FakeSecurityGroup(object):
security_group_attrs.update(attrs)
# Set default methods.
- security_group_methods = {}
+ security_group_methods = {
+ 'keys': ['id', 'name', 'description', 'tenant_id',
+ 'security_group_rules'],
+ }
# Overwrite default methods.
security_group_methods.update(methods)
@@ -451,10 +459,14 @@ class FakeSecurityGroup(object):
info=copy.deepcopy(security_group_attrs),
methods=copy.deepcopy(security_group_methods),
loaded=True)
+
+ # Set attributes with special mapping in OpenStack SDK.
+ security_group.project_id = security_group_attrs['tenant_id']
+
return security_group
@staticmethod
- def create_security_groups(attrs={}, methods={}, count=2):
+ def create_security_groups(attrs=None, methods=None, count=2):
"""Create multiple fake security groups.
:param Dictionary attrs:
@@ -478,7 +490,7 @@ class FakeSecurityGroupRule(object):
"""Fake one or more security group rules."""
@staticmethod
- def create_one_security_group_rule(attrs={}, methods={}):
+ def create_one_security_group_rule(attrs=None, methods=None):
"""Create a fake security group rule.
:param Dictionary attrs:
@@ -488,6 +500,11 @@ class FakeSecurityGroupRule(object):
:return:
A FakeResource object, with id, etc.
"""
+ if attrs is None:
+ attrs = {}
+ if methods is None:
+ methods = {}
+
# Set default attributes.
security_group_rule_attrs = {
'direction': 'ingress',
@@ -520,13 +537,13 @@ class FakeSecurityGroupRule(object):
methods=copy.deepcopy(security_group_rule_methods),
loaded=True)
- # Set attributes with special mappings.
+ # Set attributes with special mapping in OpenStack SDK.
security_group_rule.project_id = security_group_rule_attrs['tenant_id']
return security_group_rule
@staticmethod
- def create_security_group_rules(attrs={}, methods={}, count=2):
+ def create_security_group_rules(attrs=None, methods=None, count=2):
"""Create multiple fake security group rules.
:param Dictionary attrs:
@@ -734,15 +751,15 @@ class FakeSubnetPool(object):
'id': 'subnet-pool-id-' + uuid.uuid4().hex,
'name': 'subnet-pool-name-' + uuid.uuid4().hex,
'prefixes': ['10.0.0.0/24', '10.1.0.0/24'],
- 'default_prefixlen': 8,
+ 'default_prefixlen': '8',
'address_scope_id': 'address-scope-id-' + uuid.uuid4().hex,
'tenant_id': 'project-id-' + uuid.uuid4().hex,
'is_default': False,
'shared': False,
- 'max_prefixlen': 32,
- 'min_prefixlen': 8,
+ 'max_prefixlen': '32',
+ 'min_prefixlen': '8',
'default_quota': None,
- 'ip_version': 4,
+ 'ip_version': '4',
}
# Overwrite default attributes.
diff --git a/openstackclient/tests/network/v2/test_security_group.py b/openstackclient/tests/network/v2/test_security_group.py
index b8114cbc..2d43d872 100644
--- a/openstackclient/tests/network/v2/test_security_group.py
+++ b/openstackclient/tests/network/v2/test_security_group.py
@@ -37,6 +37,153 @@ class TestSecurityGroupCompute(compute_fakes.TestComputev2):
self.compute = self.app.client_manager.compute
+class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork):
+
+ # The security group to be created.
+ _security_group = \
+ network_fakes.FakeSecurityGroup.create_one_security_group()
+
+ columns = (
+ 'description',
+ 'id',
+ 'name',
+ 'project_id',
+ 'rules',
+ )
+
+ data = (
+ _security_group.description,
+ _security_group.id,
+ _security_group.name,
+ _security_group.project_id,
+ '',
+ )
+
+ def setUp(self):
+ super(TestCreateSecurityGroupNetwork, self).setUp()
+
+ self.network.create_security_group = mock.Mock(
+ return_value=self._security_group)
+
+ # Get the command object to test
+ self.cmd = security_group.CreateSecurityGroup(self.app, self.namespace)
+
+ def test_create_no_options(self):
+ self.assertRaises(tests_utils.ParserException,
+ self.check_parser, self.cmd, [], [])
+
+ def test_create_min_options(self):
+ arglist = [
+ self._security_group.name,
+ ]
+ verifylist = [
+ ('name', self._security_group.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.create_security_group.assert_called_once_with(**{
+ 'description': self._security_group.name,
+ 'name': self._security_group.name,
+ })
+ self.assertEqual(tuple(self.columns), columns)
+ self.assertEqual(self.data, data)
+
+ def test_create_all_options(self):
+ arglist = [
+ '--description', self._security_group.description,
+ self._security_group.name,
+ ]
+ verifylist = [
+ ('description', self._security_group.description),
+ ('name', self._security_group.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.create_security_group.assert_called_once_with(**{
+ 'description': self._security_group.description,
+ 'name': self._security_group.name,
+ })
+ self.assertEqual(tuple(self.columns), columns)
+ self.assertEqual(self.data, data)
+
+
+class TestCreateSecurityGroupCompute(TestSecurityGroupCompute):
+
+ # The security group to be shown.
+ _security_group = \
+ compute_fakes.FakeSecurityGroup.create_one_security_group()
+
+ columns = (
+ 'description',
+ 'id',
+ 'name',
+ 'project_id',
+ 'rules',
+ )
+
+ data = (
+ _security_group.description,
+ _security_group.id,
+ _security_group.name,
+ _security_group.tenant_id,
+ '',
+ )
+
+ def setUp(self):
+ super(TestCreateSecurityGroupCompute, self).setUp()
+
+ self.app.client_manager.network_endpoint_enabled = False
+
+ self.compute.security_groups.create.return_value = self._security_group
+
+ # Get the command object to test
+ self.cmd = security_group.CreateSecurityGroup(self.app, None)
+
+ def test_create_no_options(self):
+ self.assertRaises(tests_utils.ParserException,
+ self.check_parser, self.cmd, [], [])
+
+ def test_create_min_options(self):
+ arglist = [
+ self._security_group.name,
+ ]
+ verifylist = [
+ ('name', self._security_group.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.compute.security_groups.create.assert_called_once_with(
+ self._security_group.name,
+ self._security_group.name)
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+ def test_create_all_options(self):
+ arglist = [
+ '--description', self._security_group.description,
+ self._security_group.name,
+ ]
+ verifylist = [
+ ('description', self._security_group.description),
+ ('name', self._security_group.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.compute.security_groups.create.assert_called_once_with(
+ self._security_group.name,
+ self._security_group.description)
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+
class TestDeleteSecurityGroupNetwork(TestSecurityGroupNetwork):
# The security group to be deleted.
@@ -65,7 +212,7 @@ class TestDeleteSecurityGroupNetwork(TestSecurityGroupNetwork):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
- self.network.delete_security_group.assert_called_with(
+ self.network.delete_security_group.assert_called_once_with(
self._security_group)
self.assertIsNone(result)
@@ -100,7 +247,7 @@ class TestDeleteSecurityGroupCompute(TestSecurityGroupCompute):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
- self.compute.security_groups.delete.assert_called_with(
+ self.compute.security_groups.delete.assert_called_once_with(
self._security_group.id)
self.assertIsNone(result)
@@ -143,7 +290,7 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
columns, data = self.cmd.take_action(parsed_args)
- self.network.security_groups.assert_called_with()
+ self.network.security_groups.assert_called_once_with()
self.assertEqual(self.expected_columns, columns)
self.assertEqual(self.expected_data, tuple(data))
@@ -158,7 +305,7 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
columns, data = self.cmd.take_action(parsed_args)
- self.network.security_groups.assert_called_with()
+ self.network.security_groups.assert_called_once_with()
self.assertEqual(self.expected_columns, columns)
self.assertEqual(self.expected_data, tuple(data))
@@ -212,7 +359,7 @@ class TestListSecurityGroupCompute(TestSecurityGroupCompute):
columns, data = self.cmd.take_action(parsed_args)
kwargs = {'search_opts': {'all_tenants': False}}
- self.compute.security_groups.list.assert_called_with(**kwargs)
+ self.compute.security_groups.list.assert_called_once_with(**kwargs)
self.assertEqual(self.expected_columns, columns)
self.assertEqual(self.expected_data, tuple(data))
@@ -228,7 +375,7 @@ class TestListSecurityGroupCompute(TestSecurityGroupCompute):
columns, data = self.cmd.take_action(parsed_args)
kwargs = {'search_opts': {'all_tenants': True}}
- self.compute.security_groups.list.assert_called_with(**kwargs)
+ self.compute.security_groups.list.assert_called_once_with(**kwargs)
self.assertEqual(self.expected_columns_all_projects, columns)
self.assertEqual(self.expected_data_all_projects, tuple(data))
@@ -363,3 +510,122 @@ class TestSetSecurityGroupCompute(TestSecurityGroupCompute):
new_description
)
self.assertIsNone(result)
+
+
+class TestShowSecurityGroupNetwork(TestSecurityGroupNetwork):
+
+ # The security group rule to be shown with the group.
+ _security_group_rule = \
+ network_fakes.FakeSecurityGroupRule.create_one_security_group_rule()
+
+ # The security group to be shown.
+ _security_group = \
+ network_fakes.FakeSecurityGroup.create_one_security_group(
+ attrs={'security_group_rules': [_security_group_rule._info]}
+ )
+
+ columns = (
+ 'description',
+ 'id',
+ 'name',
+ 'project_id',
+ 'rules',
+ )
+
+ data = (
+ _security_group.description,
+ _security_group.id,
+ _security_group.name,
+ _security_group.project_id,
+ security_group._format_network_security_group_rules(
+ [_security_group_rule._info]),
+ )
+
+ def setUp(self):
+ super(TestShowSecurityGroupNetwork, self).setUp()
+
+ self.network.find_security_group = mock.Mock(
+ return_value=self._security_group)
+
+ # Get the command object to test
+ self.cmd = security_group.ShowSecurityGroup(self.app, self.namespace)
+
+ def test_show_no_options(self):
+ self.assertRaises(tests_utils.ParserException,
+ self.check_parser, self.cmd, [], [])
+
+ def test_show_all_options(self):
+ arglist = [
+ self._security_group.id,
+ ]
+ verifylist = [
+ ('group', self._security_group.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.find_security_group.assert_called_once_with(
+ self._security_group.id, ignore_missing=False)
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+
+class TestShowSecurityGroupCompute(TestSecurityGroupCompute):
+
+ # The security group rule to be shown with the group.
+ _security_group_rule = \
+ compute_fakes.FakeSecurityGroupRule.create_one_security_group_rule()
+
+ # The security group to be shown.
+ _security_group = \
+ compute_fakes.FakeSecurityGroup.create_one_security_group(
+ attrs={'rules': [_security_group_rule._info]}
+ )
+
+ columns = (
+ 'description',
+ 'id',
+ 'name',
+ 'project_id',
+ 'rules',
+ )
+
+ data = (
+ _security_group.description,
+ _security_group.id,
+ _security_group.name,
+ _security_group.tenant_id,
+ security_group._format_compute_security_group_rules(
+ [_security_group_rule._info]),
+ )
+
+ def setUp(self):
+ super(TestShowSecurityGroupCompute, self).setUp()
+
+ self.app.client_manager.network_endpoint_enabled = False
+
+ self.compute.security_groups.get.return_value = self._security_group
+
+ # Get the command object to test
+ self.cmd = security_group.ShowSecurityGroup(self.app, None)
+
+ def test_show_no_options(self):
+ self.assertRaises(tests_utils.ParserException,
+ self.check_parser, self.cmd, [], [])
+
+ def test_show_all_options(self):
+ arglist = [
+ self._security_group.id,
+ ]
+ verifylist = [
+ ('group', self._security_group.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.compute.security_groups.get.assert_called_once_with(
+ self._security_group.id)
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
diff --git a/openstackclient/tests/network/v2/test_subnet_pool.py b/openstackclient/tests/network/v2/test_subnet_pool.py
index c4e3340d..99994681 100644
--- a/openstackclient/tests/network/v2/test_subnet_pool.py
+++ b/openstackclient/tests/network/v2/test_subnet_pool.py
@@ -11,8 +11,10 @@
# under the License.
#
+import argparse
import mock
+from openstackclient.common import exceptions
from openstackclient.common import utils
from openstackclient.network.v2 import subnet_pool
from openstackclient.tests.network.v2 import fakes as network_fakes
@@ -28,6 +30,117 @@ class TestSubnetPool(network_fakes.TestNetworkV2):
self.network = self.app.client_manager.network
+class TestCreateSubnetPool(TestSubnetPool):
+
+ # The new subnet pool to create.
+ _subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
+
+ columns = (
+ 'address_scope_id',
+ 'default_prefixlen',
+ 'default_quota',
+ 'id',
+ 'ip_version',
+ 'is_default',
+ 'max_prefixlen',
+ 'min_prefixlen',
+ 'name',
+ 'prefixes',
+ 'project_id',
+ 'shared',
+ )
+ data = (
+ _subnet_pool.address_scope_id,
+ _subnet_pool.default_prefixlen,
+ _subnet_pool.default_quota,
+ _subnet_pool.id,
+ _subnet_pool.ip_version,
+ _subnet_pool.is_default,
+ _subnet_pool.max_prefixlen,
+ _subnet_pool.min_prefixlen,
+ _subnet_pool.name,
+ utils.format_list(_subnet_pool.prefixes),
+ _subnet_pool.project_id,
+ _subnet_pool.shared,
+ )
+
+ def setUp(self):
+ super(TestCreateSubnetPool, self).setUp()
+
+ self.network.create_subnet_pool = mock.Mock(
+ return_value=self._subnet_pool)
+
+ # Get the command object to test
+ self.cmd = subnet_pool.CreateSubnetPool(self.app, self.namespace)
+
+ def test_create_no_options(self):
+ arglist = []
+ verifylist = []
+
+ # Missing required args should bail here
+ self.assertRaises(tests_utils.ParserException, self.check_parser,
+ self.cmd, arglist, verifylist)
+
+ def test_create_default_options(self):
+ arglist = [
+ '--pool-prefix', '10.0.10.0/24',
+ self._subnet_pool.name,
+ ]
+ verifylist = [
+ ('prefixes', ['10.0.10.0/24']),
+ ('name', self._subnet_pool.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = (self.cmd.take_action(parsed_args))
+
+ self.network.create_subnet_pool.assert_called_with(**{
+ 'prefixes': ['10.0.10.0/24'],
+ 'name': self._subnet_pool.name,
+ })
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+ def test_create_prefixlen_options(self):
+ arglist = [
+ '--default-prefix-length', self._subnet_pool.default_prefixlen,
+ '--max-prefix-length', self._subnet_pool.max_prefixlen,
+ '--min-prefix-length', self._subnet_pool.min_prefixlen,
+ self._subnet_pool.name,
+ ]
+ verifylist = [
+ ('default_prefix_length', self._subnet_pool.default_prefixlen),
+ ('max_prefix_length', self._subnet_pool.max_prefixlen),
+ ('min_prefix_length', self._subnet_pool.min_prefixlen),
+ ('name', self._subnet_pool.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = (self.cmd.take_action(parsed_args))
+
+ self.network.create_subnet_pool.assert_called_with(**{
+ 'default_prefix_length': self._subnet_pool.default_prefixlen,
+ 'max_prefix_length': self._subnet_pool.max_prefixlen,
+ 'min_prefix_length': self._subnet_pool.min_prefixlen,
+ 'name': self._subnet_pool.name,
+ })
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+ def test_create_len_negative(self):
+ arglist = [
+ self._subnet_pool.name,
+ '--min-prefix-length', '-16',
+ ]
+ verifylist = [
+ ('subnet_pool', self._subnet_pool.name),
+ ('min_prefix_length', '-16'),
+ ]
+
+ self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
+ self.cmd, arglist, verifylist)
+
+
class TestDeleteSubnetPool(TestSubnetPool):
# The subnet pool to delete.
@@ -129,6 +242,96 @@ class TestListSubnetPool(TestSubnetPool):
self.assertEqual(self.data_long, list(data))
+class TestSetSubnetPool(TestSubnetPool):
+
+ # The subnet_pool to set.
+ _subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
+
+ def setUp(self):
+ super(TestSetSubnetPool, self).setUp()
+
+ self.network.update_subnet_pool = mock.Mock(return_value=None)
+
+ self.network.find_subnet_pool = mock.Mock(
+ return_value=self._subnet_pool)
+
+ # Get the command object to test
+ self.cmd = subnet_pool.SetSubnetPool(self.app, self.namespace)
+
+ def test_set_this(self):
+ arglist = [
+ self._subnet_pool.name,
+ '--name', 'noob',
+ '--default-prefix-length', '8',
+ '--min-prefix-length', '8',
+ ]
+ verifylist = [
+ ('subnet_pool', self._subnet_pool.name),
+ ('name', 'noob'),
+ ('default_prefix_length', '8'),
+ ('min_prefix_length', '8'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'name': 'noob',
+ 'default_prefix_length': '8',
+ 'min_prefix_length': '8',
+ }
+ self.network.update_subnet_pool.assert_called_with(
+ self._subnet_pool, **attrs)
+ self.assertIsNone(result)
+
+ def test_set_that(self):
+ arglist = [
+ self._subnet_pool.name,
+ '--pool-prefix', '10.0.1.0/24',
+ '--pool-prefix', '10.0.2.0/24',
+ '--max-prefix-length', '16',
+ ]
+ verifylist = [
+ ('subnet_pool', self._subnet_pool.name),
+ ('prefixes', ['10.0.1.0/24', '10.0.2.0/24']),
+ ('max_prefix_length', '16'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ prefixes = ['10.0.1.0/24', '10.0.2.0/24']
+ prefixes.extend(self._subnet_pool.prefixes)
+ attrs = {
+ 'prefixes': prefixes,
+ 'max_prefix_length': '16',
+ }
+ self.network.update_subnet_pool.assert_called_with(
+ self._subnet_pool, **attrs)
+ self.assertIsNone(result)
+
+ def test_set_nothing(self):
+ arglist = [self._subnet_pool.name, ]
+ verifylist = [('subnet_pool', self._subnet_pool.name), ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
+ def test_set_len_negative(self):
+ arglist = [
+ self._subnet_pool.name,
+ '--max-prefix-length', '-16',
+ ]
+ verifylist = [
+ ('subnet_pool', self._subnet_pool.name),
+ ('max_prefix_length', '-16'),
+ ]
+
+ self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
+ self.cmd, arglist, verifylist)
+
+
class TestShowSubnetPool(TestSubnetPool):
# The subnet_pool to set.
@@ -189,14 +392,13 @@ class TestShowSubnetPool(TestSubnetPool):
verifylist = [
('subnet_pool', self._subnet_pool.name),
]
-
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
columns, data = self.cmd.take_action(parsed_args)
self.network.find_subnet_pool.assert_called_with(
self._subnet_pool.name,
ignore_missing=False
)
-
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
diff --git a/openstackclient/tests/utils.py b/openstackclient/tests/utils.py
index d3f3853f..319c1c11 100644
--- a/openstackclient/tests/utils.py
+++ b/openstackclient/tests/utils.py
@@ -17,7 +17,6 @@
import os
import fixtures
-import sys
import testtools
from openstackclient.tests import fakes
@@ -50,29 +49,6 @@ class TestCase(testtools.TestCase):
msg = 'method %s should not have been called' % m
self.fail(msg)
- # 2.6 doesn't have the assert dict equals so make sure that it exists
- if tuple(sys.version_info)[0:2] < (2, 7):
-
- def assertIsInstance(self, obj, cls, msg=None):
- """self.assertTrue(isinstance(obj, cls)), with a nicer message"""
-
- if not isinstance(obj, cls):
- standardMsg = '%s is not an instance of %r' % (obj, cls)
- self.fail(self._formatMessage(msg, standardMsg))
-
- def assertDictEqual(self, d1, d2, msg=None):
- # Simple version taken from 2.7
- self.assertIsInstance(d1, dict,
- 'First argument is not a dictionary')
- self.assertIsInstance(d2, dict,
- 'Second argument is not a dictionary')
- if d1 != d2:
- if msg:
- self.fail(msg)
- else:
- standardMsg = '%r != %r' % (d1, d2)
- self.fail(standardMsg)
-
class TestCommand(TestCase):
"""Test cliff command classes"""
diff --git a/openstackclient/tests/volume/v2/fakes.py b/openstackclient/tests/volume/v2/fakes.py
index 61d9df3a..97bbc59b 100644
--- a/openstackclient/tests/volume/v2/fakes.py
+++ b/openstackclient/tests/volume/v2/fakes.py
@@ -211,6 +211,26 @@ 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 FakeVolumeClient(object):