|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +import uuid |
| 14 | + |
| 15 | +from openstack.compute.v2 import console_auth_token as _console_auth_token |
| 16 | +from openstack.test import fakes as sdk_fakes |
| 17 | + |
| 18 | +from openstackclient.compute.v2 import console_connection |
| 19 | +from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes |
| 20 | + |
| 21 | + |
| 22 | +class TestConsoleTokens(compute_fakes.TestComputev2): |
| 23 | + def setUp(self): |
| 24 | + super().setUp() |
| 25 | + |
| 26 | + self._console_auth_token = sdk_fakes.generate_fake_resource( |
| 27 | + _console_auth_token.ConsoleAuthToken, |
| 28 | + host='127.0.0.1', |
| 29 | + instance_uuid=uuid.uuid4().hex, |
| 30 | + internal_access_path=None, |
| 31 | + port=5900, |
| 32 | + tls_port=5901, |
| 33 | + ) |
| 34 | + self.compute_client.validate_console_auth_token.return_value = ( |
| 35 | + self._console_auth_token |
| 36 | + ) |
| 37 | + |
| 38 | + self.columns = ( |
| 39 | + 'host', |
| 40 | + 'instance_uuid', |
| 41 | + 'internal_access_path', |
| 42 | + 'port', |
| 43 | + 'tls_port', |
| 44 | + ) |
| 45 | + self.data = ( |
| 46 | + self._console_auth_token.host, |
| 47 | + self._console_auth_token.instance_uuid, |
| 48 | + self._console_auth_token.internal_access_path, |
| 49 | + self._console_auth_token.port, |
| 50 | + self._console_auth_token.tls_port, |
| 51 | + ) |
| 52 | + |
| 53 | + self.cmd = console_connection.ShowConsoleConnectionInformation( |
| 54 | + self.app, None |
| 55 | + ) |
| 56 | + |
| 57 | + def test_console_connection_show(self): |
| 58 | + arglist = [ |
| 59 | + 'token', |
| 60 | + ] |
| 61 | + verifylist = [ |
| 62 | + ('token', 'token'), |
| 63 | + ] |
| 64 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 65 | + |
| 66 | + columns, data = self.cmd.take_action(parsed_args) |
| 67 | + |
| 68 | + self.compute_client.validate_console_auth_token.assert_called_once_with( |
| 69 | + 'token' |
| 70 | + ) |
| 71 | + self.assertEqual(self.columns, columns) |
| 72 | + self.assertEqual(self.data, data) |
0 commit comments