|
| 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 | + |
| 14 | +import copy |
| 15 | + |
| 16 | +from openstackclient.common import extension |
| 17 | +from openstackclient.tests import fakes |
| 18 | +from openstackclient.tests import utils |
| 19 | + |
| 20 | +from openstackclient.tests.identity.v2_0 import fakes as identity_fakes |
| 21 | + |
| 22 | + |
| 23 | +class TestExtension(utils.TestCommand): |
| 24 | + |
| 25 | + def setUp(self): |
| 26 | + super(TestExtension, self).setUp() |
| 27 | + |
| 28 | + self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client( |
| 29 | + endpoint=fakes.AUTH_URL, |
| 30 | + token=fakes.AUTH_TOKEN, |
| 31 | + ) |
| 32 | + |
| 33 | + # Get shortcuts to the ExtensionManager Mocks |
| 34 | + self.identity_extensions_mock = ( |
| 35 | + self.app.client_manager.identity.extensions) |
| 36 | + self.identity_extensions_mock.reset_mock() |
| 37 | + |
| 38 | + |
| 39 | +class TestExtensionList(TestExtension): |
| 40 | + |
| 41 | + def setUp(self): |
| 42 | + super(TestExtensionList, self).setUp() |
| 43 | + |
| 44 | + self.identity_extensions_mock.list.return_value = [ |
| 45 | + fakes.FakeResource( |
| 46 | + None, |
| 47 | + copy.deepcopy(identity_fakes.EXTENSION), |
| 48 | + loaded=True, |
| 49 | + ), |
| 50 | + ] |
| 51 | + |
| 52 | + # Get the command object to test |
| 53 | + self.cmd = extension.ListExtension(self.app, None) |
| 54 | + |
| 55 | + def test_extension_list_no_options(self): |
| 56 | + arglist = [] |
| 57 | + verifylist = [] |
| 58 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 59 | + |
| 60 | + # DisplayCommandBase.take_action() returns two tuples |
| 61 | + columns, data = self.cmd.take_action(parsed_args) |
| 62 | + |
| 63 | + # no args should output from all services |
| 64 | + self.identity_extensions_mock.list.assert_called_with() |
| 65 | + |
| 66 | + collist = ('Name', 'Alias', 'Description') |
| 67 | + self.assertEqual(columns, collist) |
| 68 | + datalist = ( |
| 69 | + ( |
| 70 | + identity_fakes.extension_name, |
| 71 | + identity_fakes.extension_alias, |
| 72 | + identity_fakes.extension_description, |
| 73 | + ), |
| 74 | + ) |
| 75 | + self.assertEqual(tuple(data), datalist) |
| 76 | + |
| 77 | + def test_extension_list_long(self): |
| 78 | + arglist = [ |
| 79 | + '--long', |
| 80 | + ] |
| 81 | + verifylist = [ |
| 82 | + ('long', True), |
| 83 | + ] |
| 84 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 85 | + |
| 86 | + # DisplayCommandBase.take_action() returns two tuples |
| 87 | + columns, data = self.cmd.take_action(parsed_args) |
| 88 | + |
| 89 | + # no args should output from all services |
| 90 | + self.identity_extensions_mock.list.assert_called_with() |
| 91 | + |
| 92 | + collist = ('Name', 'Namespace', 'Description', 'Alias', 'Updated', |
| 93 | + 'Links') |
| 94 | + self.assertEqual(columns, collist) |
| 95 | + datalist = ( |
| 96 | + ( |
| 97 | + identity_fakes.extension_name, |
| 98 | + identity_fakes.extension_namespace, |
| 99 | + identity_fakes.extension_description, |
| 100 | + identity_fakes.extension_alias, |
| 101 | + identity_fakes.extension_updated, |
| 102 | + identity_fakes.extension_links, |
| 103 | + ), |
| 104 | + ) |
| 105 | + self.assertEqual(tuple(data), datalist) |
| 106 | + |
| 107 | + def test_extension_list_identity(self): |
| 108 | + arglist = [ |
| 109 | + '--identity', |
| 110 | + ] |
| 111 | + verifylist = [ |
| 112 | + ('identity', True), |
| 113 | + ] |
| 114 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 115 | + |
| 116 | + # DisplayCommandBase.take_action() returns two tuples |
| 117 | + columns, data = self.cmd.take_action(parsed_args) |
| 118 | + |
| 119 | + self.identity_extensions_mock.list.assert_called_with() |
| 120 | + |
| 121 | + collist = ('Name', 'Alias', 'Description') |
| 122 | + self.assertEqual(columns, collist) |
| 123 | + datalist = (( |
| 124 | + identity_fakes.extension_name, |
| 125 | + identity_fakes.extension_alias, |
| 126 | + identity_fakes.extension_description, |
| 127 | + ), ) |
| 128 | + self.assertEqual(tuple(data), datalist) |
0 commit comments