diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2014-09-14 18:16:32 -0500 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2014-09-18 15:42:10 -0500 |
| commit | da45b34828bbc4000b1ede68f10bbcc1e4a47cc1 (patch) | |
| tree | a4c25595d3c9b8eedebdb90f55430a4d81ee806c /openstackclient/tests | |
| parent | ae957b176e5918f41024c00cbc39ea371a0c37c6 (diff) | |
| download | python-openstackclient-da45b34828bbc4000b1ede68f10bbcc1e4a47cc1.tar.gz | |
Add service catalog commands
'catalog list' and 'catalog show' for Identity v2
Identity v2 only so far.
Change-Id: I9df0dac3d5bb7c18f38a81bd7d29f8119462d3a5
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/identity/v2_0/test_catalog.py | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/openstackclient/tests/identity/v2_0/test_catalog.py b/openstackclient/tests/identity/v2_0/test_catalog.py new file mode 100644 index 00000000..5289cac4 --- /dev/null +++ b/openstackclient/tests/identity/v2_0/test_catalog.py @@ -0,0 +1,107 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +import mock + +from openstackclient.identity.v2_0 import catalog +from openstackclient.tests import utils + + +class TestCatalog(utils.TestCommand): + + fake_service = { + 'id': 'qwertyuiop', + 'type': 'compute', + 'name': 'supernova', + 'endpoints': [{ + 'region': 'onlyone', + 'publicURL': 'https://public.example.com', + 'adminURL': 'https://admin.example.com', + }], + } + + def setUp(self): + super(TestCatalog, self).setUp() + + self.sc_mock = mock.MagicMock() + self.sc_mock.service_catalog.get_data.return_value = [ + self.fake_service, + ] + + self.auth_mock = mock.MagicMock() + self.app.client_manager.session = self.auth_mock + + self.auth_mock.auth.get_auth_ref.return_value = self.sc_mock + + +class TestCatalogList(TestCatalog): + + def setUp(self): + super(TestCatalogList, self).setUp() + + # Get the command object to test + self.cmd = catalog.ListCatalog(self.app, None) + + def test_catalog_list(self): + arglist = [] + verifylist = [] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # DisplayCommandBase.take_action() returns two tuples + columns, data = self.cmd.take_action(parsed_args) + self.sc_mock.service_catalog.get_data.assert_called_with() + + collist = ('Name', 'Type', 'Endpoints') + self.assertEqual(collist, columns) + datalist = (( + 'supernova', + 'compute', + 'onlyone\n publicURL: https://public.example.com\n ' + 'internalURL: https://public.example.com\n ' + 'adminURL: https://public.example.com\n', + ), ) + self.assertEqual(datalist, tuple(data)) + + +class TestCatalogShow(TestCatalog): + + def setUp(self): + super(TestCatalogShow, self).setUp() + + # Get the command object to test + self.cmd = catalog.ShowCatalog(self.app, None) + + def test_catalog_show(self): + arglist = [ + 'compute', + ] + verifylist = [ + ('service', 'compute'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # DisplayCommandBase.take_action() returns two tuples + columns, data = self.cmd.take_action(parsed_args) + self.sc_mock.service_catalog.get_data.assert_called_with() + + collist = ('endpoints', 'id', 'name', 'type') + self.assertEqual(collist, columns) + datalist = ( + 'onlyone\n publicURL: https://public.example.com\n ' + 'internalURL: https://public.example.com\n ' + 'adminURL: https://public.example.com\n', + 'qwertyuiop', + 'supernova', + 'compute', + ) + self.assertEqual(datalist, data) |
