|
11 | 11 | # under the License. |
12 | 12 | # |
13 | 13 | import mock |
| 14 | +from openstackclient.tests.unit import utils as tests_utils |
| 15 | +from osc_lib import exceptions |
14 | 16 |
|
15 | 17 | from otcextensions.osclient.privatenat.v3 import private_nat_gateway |
16 | 18 | from otcextensions.tests.unit.osclient.privatenat.v3 import fakes |
@@ -138,3 +140,76 @@ def test_list_args(self): |
138 | 140 | virsubnet_id=["s1"], |
139 | 141 | enterprise_project_id=["ep1"], |
140 | 142 | ) |
| 143 | + |
| 144 | + |
| 145 | +class TestGetPrivateNatGateway(fakes.TestPrivateNat): |
| 146 | + |
| 147 | + _data = fakes.FakePrivateNatGateway.create_one() |
| 148 | + |
| 149 | + columns = ( |
| 150 | + "id", |
| 151 | + "name", |
| 152 | + "spec", |
| 153 | + "status", |
| 154 | + "project_id", |
| 155 | + "enterprise_project_id", |
| 156 | + ) |
| 157 | + |
| 158 | + data = fakes.gen_data(_data, columns) |
| 159 | + |
| 160 | + def setUp(self): |
| 161 | + super(TestGetPrivateNatGateway, self).setUp() |
| 162 | + |
| 163 | + self.cmd = private_nat_gateway.ShowPrivateNatGateway(self.app, None) |
| 164 | + |
| 165 | + self.client.get_private_nat_gateway = mock.Mock(return_value=self._data) |
| 166 | + |
| 167 | + def test_get_no_options(self): |
| 168 | + arglist = [] |
| 169 | + verifylist = [] |
| 170 | + |
| 171 | + # Testing that a call without the required argument will fail and |
| 172 | + # throw a "ParserExecption" |
| 173 | + self.assertRaises( |
| 174 | + tests_utils.ParserException, |
| 175 | + self.check_parser, |
| 176 | + self.cmd, |
| 177 | + arglist, |
| 178 | + verifylist, |
| 179 | + ) |
| 180 | + |
| 181 | + def test_get(self): |
| 182 | + arglist = [ |
| 183 | + self._data.id, |
| 184 | + ] |
| 185 | + |
| 186 | + verifylist = [ |
| 187 | + ("gateway", self._data.id), |
| 188 | + ] |
| 189 | + |
| 190 | + # Verify cm is triggered with default parameters |
| 191 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 192 | + |
| 193 | + # Trigger the action |
| 194 | + columns, data = self.cmd.take_action(parsed_args) |
| 195 | + self.client.get_private_nat_gateway.assert_called_with(self._data.id) |
| 196 | + |
| 197 | + self.assertEqual(tuple(sorted(self.columns)), tuple(sorted(columns))) |
| 198 | + self.assertEqual(tuple(sorted(self.data)), tuple(sorted(data))) |
| 199 | + |
| 200 | + def test_get_non_existing(self): |
| 201 | + arglist = ["unexist_nat_gateway"] |
| 202 | + verifylist = [("gateway", "unexist_nat_gateway")] |
| 203 | + |
| 204 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 205 | + |
| 206 | + self.client.get_private_nat_gateway.side_effect = exceptions.CommandError( |
| 207 | + "Resource Not Found" |
| 208 | + ) |
| 209 | + |
| 210 | + with self.assertRaises(exceptions.CommandError): |
| 211 | + self.cmd.take_action(parsed_args) |
| 212 | + |
| 213 | + self.client.get_private_nat_gateway.assert_called_once_with( |
| 214 | + "unexist_nat_gateway" |
| 215 | + ) |
0 commit comments