|
| 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 mock |
| 15 | + |
| 16 | +from openstackclient.identity.v3 import catalog |
| 17 | +from openstackclient.tests import utils |
| 18 | + |
| 19 | + |
| 20 | +class TestCatalog(utils.TestCommand): |
| 21 | + |
| 22 | + fake_service = { |
| 23 | + 'id': 'qwertyuiop', |
| 24 | + 'type': 'compute', |
| 25 | + 'name': 'supernova', |
| 26 | + 'endpoints': [ |
| 27 | + { |
| 28 | + 'region': 'onlyone', |
| 29 | + 'url': 'https://public.example.com', |
| 30 | + 'interface': 'public', |
| 31 | + }, |
| 32 | + { |
| 33 | + 'region_id': 'onlyone', |
| 34 | + 'url': 'https://admin.example.com', |
| 35 | + 'interface': 'admin', |
| 36 | + }, |
| 37 | + { |
| 38 | + 'url': 'https://internal.example.com', |
| 39 | + 'interface': 'internal', |
| 40 | + }, |
| 41 | + ], |
| 42 | + } |
| 43 | + |
| 44 | + def setUp(self): |
| 45 | + super(TestCatalog, self).setUp() |
| 46 | + |
| 47 | + self.sc_mock = mock.MagicMock() |
| 48 | + self.sc_mock.service_catalog.get_data.return_value = [ |
| 49 | + self.fake_service, |
| 50 | + ] |
| 51 | + |
| 52 | + self.auth_mock = mock.MagicMock() |
| 53 | + self.app.client_manager.session = self.auth_mock |
| 54 | + |
| 55 | + self.auth_mock.auth.get_auth_ref.return_value = self.sc_mock |
| 56 | + |
| 57 | + |
| 58 | +class TestCatalogList(TestCatalog): |
| 59 | + |
| 60 | + def setUp(self): |
| 61 | + super(TestCatalogList, self).setUp() |
| 62 | + |
| 63 | + # Get the command object to test |
| 64 | + self.cmd = catalog.ListCatalog(self.app, None) |
| 65 | + |
| 66 | + def test_catalog_list(self): |
| 67 | + arglist = [] |
| 68 | + verifylist = [] |
| 69 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 70 | + |
| 71 | + # DisplayCommandBase.take_action() returns two tuples |
| 72 | + columns, data = self.cmd.take_action(parsed_args) |
| 73 | + self.sc_mock.service_catalog.get_data.assert_called_with() |
| 74 | + |
| 75 | + collist = ('Name', 'Type', 'Endpoints') |
| 76 | + self.assertEqual(collist, columns) |
| 77 | + datalist = (( |
| 78 | + 'supernova', |
| 79 | + 'compute', |
| 80 | + 'onlyone\n public: https://public.example.com\n' |
| 81 | + 'onlyone\n admin: https://admin.example.com\n' |
| 82 | + '<none>\n internal: https://internal.example.com\n', |
| 83 | + ), ) |
| 84 | + self.assertEqual(datalist, tuple(data)) |
0 commit comments