diff options
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/network/v2/fakes.py | 16 | ||||
| -rw-r--r-- | openstackclient/tests/network/v2/test_subnet_pool.py | 75 |
2 files changed, 90 insertions, 1 deletions
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py index dac3737b..7de0a692 100644 --- a/openstackclient/tests/network/v2/fakes.py +++ b/openstackclient/tests/network/v2/fakes.py @@ -696,12 +696,24 @@ class FakeSubnetPool(object): A FakeResource object faking the subnet pool """ # Set default attributes. + project_id = 'project-id-' + uuid.uuid4().hex subnet_pool_attrs = { '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, 'address_scope_id': 'address-scope-id-' + uuid.uuid4().hex, + 'tenant_id': project_id, + 'is_default': False, + 'shared': False, + 'max_prefixlen': 32, + 'min_prefixlen': 8, + 'default_quota': None, + 'ip_version': 4, + + # OpenStack SDK automatically translates project_id to tenant_id. + # So we need an additional attr to simulate this behavior. + 'project_id': project_id, } # Overwrite default attributes. @@ -710,7 +722,9 @@ class FakeSubnetPool(object): # Set default methods. subnet_pool_methods = { 'keys': ['id', 'name', 'prefixes', 'default_prefixlen', - 'address_scope_id'] + 'address_scope_id', 'tenant_id', 'is_default', + 'shared', 'max_prefixlen', 'min_prefixlen', + 'default_quota', 'ip_version'] } # Overwrite default methods. diff --git a/openstackclient/tests/network/v2/test_subnet_pool.py b/openstackclient/tests/network/v2/test_subnet_pool.py index 28be5937..0ee5a714 100644 --- a/openstackclient/tests/network/v2/test_subnet_pool.py +++ b/openstackclient/tests/network/v2/test_subnet_pool.py @@ -13,8 +13,10 @@ import mock +from openstackclient.common import utils from openstackclient.network.v2 import subnet_pool from openstackclient.tests.network.v2 import fakes as network_fakes +from openstackclient.tests import utils as tests_utils class TestSubnetPool(network_fakes.TestNetworkV2): @@ -124,3 +126,76 @@ class TestListSubnetPool(TestSubnetPool): self.network.subnet_pools.assert_called_with() self.assertEqual(self.columns_long, columns) self.assertEqual(self.data_long, list(data)) + + +class TestShowSubnetPool(TestSubnetPool): + + # The subnet_pool to set. + _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.tenant_id, + _subnet_pool.shared, + ) + + def setUp(self): + super(TestShowSubnetPool, self).setUp() + + self.network.find_subnet_pool = mock.Mock( + return_value=self._subnet_pool + ) + + # Get the command object to test + self.cmd = subnet_pool.ShowSubnetPool(self.app, self.namespace) + + def test_show_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_show_all_options(self): + arglist = [ + self._subnet_pool.name, + ] + 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) |
