|
16 | 16 | from openstackclient.common import utils |
17 | 17 | from openstackclient.network.v2 import subnet as subnet_v2 |
18 | 18 | from openstackclient.tests.network.v2 import fakes as network_fakes |
| 19 | +from openstackclient.tests import utils as tests_utils |
19 | 20 |
|
20 | 21 |
|
21 | 22 | class TestSubnet(network_fakes.TestNetworkV2): |
@@ -106,3 +107,76 @@ def test_subnet_list_long(self): |
106 | 107 | self.network.subnets.assert_called_with() |
107 | 108 | self.assertEqual(self.columns_long, columns) |
108 | 109 | self.assertEqual(self.data_long, list(data)) |
| 110 | + |
| 111 | + |
| 112 | +class TestShowSubnet(TestSubnet): |
| 113 | + # The subnets to be shown |
| 114 | + _subnet = network_fakes.FakeSubnet.create_one_subnet() |
| 115 | + |
| 116 | + columns = ( |
| 117 | + 'allocation_pools', |
| 118 | + 'cidr', |
| 119 | + 'dns_nameservers', |
| 120 | + 'enable_dhcp', |
| 121 | + 'gateway_ip', |
| 122 | + 'host_routes', |
| 123 | + 'id', |
| 124 | + 'ip_version', |
| 125 | + 'ipv6_address_mode', |
| 126 | + 'ipv6_ra_mode', |
| 127 | + 'name', |
| 128 | + 'network_id', |
| 129 | + 'project_id', |
| 130 | + 'subnetpool_id', |
| 131 | + ) |
| 132 | + |
| 133 | + data = ( |
| 134 | + subnet_v2._format_allocation_pools(_subnet.allocation_pools), |
| 135 | + _subnet.cidr, |
| 136 | + utils.format_list(_subnet.dns_nameservers), |
| 137 | + _subnet.enable_dhcp, |
| 138 | + _subnet.gateway_ip, |
| 139 | + utils.format_list(_subnet.host_routes), |
| 140 | + _subnet.id, |
| 141 | + _subnet.ip_version, |
| 142 | + _subnet.ipv6_address_mode, |
| 143 | + _subnet.ipv6_ra_mode, |
| 144 | + _subnet.name, |
| 145 | + _subnet.network_id, |
| 146 | + _subnet.tenant_id, |
| 147 | + _subnet.subnetpool_id, |
| 148 | + ) |
| 149 | + |
| 150 | + def setUp(self): |
| 151 | + super(TestShowSubnet, self).setUp() |
| 152 | + |
| 153 | + # Get the command object to test |
| 154 | + self.cmd = subnet_v2.ShowSubnet(self.app, self.namespace) |
| 155 | + |
| 156 | + self.network.find_subnet = mock.Mock(return_value=self._subnet) |
| 157 | + |
| 158 | + def test_show_no_options(self): |
| 159 | + arglist = [] |
| 160 | + verifylist = [] |
| 161 | + |
| 162 | + # Testing that a call without the required argument will fail and |
| 163 | + # throw a "ParserExecption" |
| 164 | + self.assertRaises(tests_utils.ParserException, |
| 165 | + self.check_parser, self.cmd, arglist, verifylist) |
| 166 | + |
| 167 | + def test_show_all_options(self): |
| 168 | + arglist = [ |
| 169 | + self._subnet.name, |
| 170 | + ] |
| 171 | + verifylist = [ |
| 172 | + ('subnet', self._subnet.name), |
| 173 | + ] |
| 174 | + |
| 175 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 176 | + columns, data = self.cmd.take_action(parsed_args) |
| 177 | + |
| 178 | + self.network.find_subnet.assert_called_with(self._subnet.name, |
| 179 | + ignore_missing=False) |
| 180 | + |
| 181 | + self.assertEqual(self.columns, columns) |
| 182 | + self.assertEqual(list(self.data), list(data)) |
0 commit comments