|
13 | 13 |
|
14 | 14 | import mock |
15 | 15 |
|
| 16 | +from openstackclient.common import utils |
16 | 17 | from openstackclient.network.v2 import subnet_pool |
17 | 18 | from openstackclient.tests.network.v2 import fakes as network_fakes |
| 19 | +from openstackclient.tests import utils as tests_utils |
18 | 20 |
|
19 | 21 |
|
20 | 22 | class TestSubnetPool(network_fakes.TestNetworkV2): |
@@ -124,3 +126,76 @@ def test_subnet_pool_list_long(self): |
124 | 126 | self.network.subnet_pools.assert_called_with() |
125 | 127 | self.assertEqual(self.columns_long, columns) |
126 | 128 | self.assertEqual(self.data_long, list(data)) |
| 129 | + |
| 130 | + |
| 131 | +class TestShowSubnetPool(TestSubnetPool): |
| 132 | + |
| 133 | + # The subnet_pool to set. |
| 134 | + _subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool() |
| 135 | + |
| 136 | + columns = ( |
| 137 | + 'address_scope_id', |
| 138 | + 'default_prefixlen', |
| 139 | + 'default_quota', |
| 140 | + 'id', |
| 141 | + 'ip_version', |
| 142 | + 'is_default', |
| 143 | + 'max_prefixlen', |
| 144 | + 'min_prefixlen', |
| 145 | + 'name', |
| 146 | + 'prefixes', |
| 147 | + 'project_id', |
| 148 | + 'shared', |
| 149 | + ) |
| 150 | + |
| 151 | + data = ( |
| 152 | + _subnet_pool.address_scope_id, |
| 153 | + _subnet_pool.default_prefixlen, |
| 154 | + _subnet_pool.default_quota, |
| 155 | + _subnet_pool.id, |
| 156 | + _subnet_pool.ip_version, |
| 157 | + _subnet_pool.is_default, |
| 158 | + _subnet_pool.max_prefixlen, |
| 159 | + _subnet_pool.min_prefixlen, |
| 160 | + _subnet_pool.name, |
| 161 | + utils.format_list(_subnet_pool.prefixes), |
| 162 | + _subnet_pool.tenant_id, |
| 163 | + _subnet_pool.shared, |
| 164 | + ) |
| 165 | + |
| 166 | + def setUp(self): |
| 167 | + super(TestShowSubnetPool, self).setUp() |
| 168 | + |
| 169 | + self.network.find_subnet_pool = mock.Mock( |
| 170 | + return_value=self._subnet_pool |
| 171 | + ) |
| 172 | + |
| 173 | + # Get the command object to test |
| 174 | + self.cmd = subnet_pool.ShowSubnetPool(self.app, self.namespace) |
| 175 | + |
| 176 | + def test_show_no_options(self): |
| 177 | + arglist = [] |
| 178 | + verifylist = [] |
| 179 | + |
| 180 | + # Missing required args should bail here |
| 181 | + self.assertRaises(tests_utils.ParserException, self.check_parser, |
| 182 | + self.cmd, arglist, verifylist) |
| 183 | + |
| 184 | + def test_show_all_options(self): |
| 185 | + arglist = [ |
| 186 | + self._subnet_pool.name, |
| 187 | + ] |
| 188 | + verifylist = [ |
| 189 | + ('subnet_pool', self._subnet_pool.name), |
| 190 | + ] |
| 191 | + |
| 192 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 193 | + columns, data = self.cmd.take_action(parsed_args) |
| 194 | + |
| 195 | + self.network.find_subnet_pool.assert_called_with( |
| 196 | + self._subnet_pool.name, |
| 197 | + ignore_missing=False |
| 198 | + ) |
| 199 | + |
| 200 | + self.assertEqual(self.columns, columns) |
| 201 | + self.assertEqual(self.data, data) |
0 commit comments