diff options
| author | Jenkins <jenkins@review.openstack.org> | 2016-02-23 00:13:44 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2016-02-23 00:13:44 +0000 |
| commit | 7c9bb377c1d9be92af676a06959f7ddc86403491 (patch) | |
| tree | 535a7c62afcd7fbfdeb744629cf9dd90880e2a9c /openstackclient/tests | |
| parent | c57fc41c33df58237f6b3ec8a5b2a0ff9573da2e (diff) | |
| parent | 112d7b0e0966599aa940de4c0598cea759780785 (diff) | |
| download | python-openstackclient-7c9bb377c1d9be92af676a06959f7ddc86403491.tar.gz | |
Merge "Add "os subnet show" command using SDK"
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/network/v2/fakes.py | 11 | ||||
| -rw-r--r-- | openstackclient/tests/network/v2/test_subnet.py | 74 |
2 files changed, 83 insertions, 2 deletions
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py index 680e9cbf..c24410e1 100644 --- a/openstackclient/tests/network/v2/fakes.py +++ b/openstackclient/tests/network/v2/fakes.py @@ -550,18 +550,22 @@ class FakeSubnet(object): A FakeResource object faking the subnet """ # Set default attributes. + project_id = 'project-id-' + uuid.uuid4().hex subnet_attrs = { 'id': 'subnet-id-' + uuid.uuid4().hex, 'name': 'subnet-name-' + uuid.uuid4().hex, 'network_id': 'network-id-' + uuid.uuid4().hex, 'cidr': '10.10.10.0/24', - 'tenant_id': 'project-id-' + uuid.uuid4().hex, + 'tenant_id': project_id, 'enable_dhcp': True, 'dns_nameservers': [], 'allocation_pools': [], 'host_routes': [], 'ip_version': '4', 'gateway_ip': '10.10.10.1', + 'ipv6_address_mode': 'None', + 'ipv6_ra_mode': 'None', + 'subnetpool_id': 'None', } # Overwrite default attributes. @@ -571,7 +575,8 @@ class FakeSubnet(object): subnet_methods = { 'keys': ['id', 'name', 'network_id', 'cidr', 'enable_dhcp', 'allocation_pools', 'dns_nameservers', 'gateway_ip', - 'host_routes', 'ip_version', 'tenant_id'] + 'host_routes', 'ip_version', 'tenant_id', + 'ipv6_address_mode', 'ipv6_ra_mode', 'subnetpool_id'] } # Overwrite default methods. @@ -580,6 +585,8 @@ class FakeSubnet(object): subnet = fakes.FakeResource(info=copy.deepcopy(subnet_attrs), methods=copy.deepcopy(subnet_methods), loaded=True) + # Set attributes with special mappings in OpenStack SDK. + subnet.project_id = subnet_attrs['tenant_id'] return subnet diff --git a/openstackclient/tests/network/v2/test_subnet.py b/openstackclient/tests/network/v2/test_subnet.py index 5fca5edd..c02dc407 100644 --- a/openstackclient/tests/network/v2/test_subnet.py +++ b/openstackclient/tests/network/v2/test_subnet.py @@ -16,6 +16,7 @@ import mock from openstackclient.common import utils from openstackclient.network.v2 import subnet as subnet_v2 from openstackclient.tests.network.v2 import fakes as network_fakes +from openstackclient.tests import utils as tests_utils class TestSubnet(network_fakes.TestNetworkV2): @@ -106,3 +107,76 @@ class TestListSubnet(TestSubnet): self.network.subnets.assert_called_with() self.assertEqual(self.columns_long, columns) self.assertEqual(self.data_long, list(data)) + + +class TestShowSubnet(TestSubnet): + # The subnets to be shown + _subnet = network_fakes.FakeSubnet.create_one_subnet() + + columns = ( + 'allocation_pools', + 'cidr', + 'dns_nameservers', + 'enable_dhcp', + 'gateway_ip', + 'host_routes', + 'id', + 'ip_version', + 'ipv6_address_mode', + 'ipv6_ra_mode', + 'name', + 'network_id', + 'project_id', + 'subnetpool_id', + ) + + data = ( + subnet_v2._format_allocation_pools(_subnet.allocation_pools), + _subnet.cidr, + utils.format_list(_subnet.dns_nameservers), + _subnet.enable_dhcp, + _subnet.gateway_ip, + utils.format_list(_subnet.host_routes), + _subnet.id, + _subnet.ip_version, + _subnet.ipv6_address_mode, + _subnet.ipv6_ra_mode, + _subnet.name, + _subnet.network_id, + _subnet.tenant_id, + _subnet.subnetpool_id, + ) + + def setUp(self): + super(TestShowSubnet, self).setUp() + + # Get the command object to test + self.cmd = subnet_v2.ShowSubnet(self.app, self.namespace) + + self.network.find_subnet = mock.Mock(return_value=self._subnet) + + def test_show_no_options(self): + arglist = [] + verifylist = [] + + # Testing that a call without the required argument will fail and + # throw a "ParserExecption" + self.assertRaises(tests_utils.ParserException, + self.check_parser, self.cmd, arglist, verifylist) + + def test_show_all_options(self): + arglist = [ + self._subnet.name, + ] + verifylist = [ + ('subnet', self._subnet.name), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.find_subnet.assert_called_with(self._subnet.name, + ignore_missing=False) + + self.assertEqual(self.columns, columns) + self.assertEqual(list(self.data), list(data)) |
