From d865a4da95c9c1bd0ba7c7c4d83553d0cbaf60c8 Mon Sep 17 00:00:00 2001 From: Chris Spencer Date: Thu, 18 Aug 2016 15:32:38 -0700 Subject: [PATCH] Adding region-show capabilities to clients. Added region-show to CLI client and region.get() to python client. Change-Id: I8343f84a94c700d543de8b58c12cdcde4cefc817 Implements: blueprint craton-client-access-inventory (partial) Closes-Bug: #1613344 --- cratonclient/shell/v1/regions_shell.py | 11 +++++++++ cratonclient/tests/unit/test_regions_shell.py | 23 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/cratonclient/shell/v1/regions_shell.py b/cratonclient/shell/v1/regions_shell.py index 9b46c54..1541fde 100644 --- a/cratonclient/shell/v1/regions_shell.py +++ b/cratonclient/shell/v1/regions_shell.py @@ -29,3 +29,14 @@ def do_region_create(cc, args): region = cc.regions.create(**fields) data = {f: getattr(region, f, '') for f in r_fields} cliutils.print_dict(data, wrap=72) + + +@cliutils.arg('id', + metavar='', + type=int, + help='ID of the region.') +def do_region_show(cc, args): + """Show detailed information about a region.""" + region = cc.regions.get(args.id) + data = {f: getattr(region, f, '') for f in r_fields} + cliutils.print_dict(data, wrap=72) diff --git a/cratonclient/tests/unit/test_regions_shell.py b/cratonclient/tests/unit/test_regions_shell.py index 4cd6381..0932d1a 100644 --- a/cratonclient/tests/unit/test_regions_shell.py +++ b/cratonclient/tests/unit/test_regions_shell.py @@ -70,3 +70,26 @@ class TestRegionsShell(base.ShellTestCase): client.regions = regions.RegionManager(session, 'http://127.0.0.1/') regions_shell.do_region_create(client, self.region_invalid_field) mock_create.assert_called_once_with(**vars(self.region_valid_fields)) + + def test_region_show_missing_required_args(self): + """Verify that missing required args results in error message.""" + expected_responses = [ + '.*?^usage: craton region-show', + '.*?^craton region-show: error:.*$', + ] + stdout, stderr = self.shell('region-show') + actual_output = stdout + stderr + for r in expected_responses: + self.assertThat(actual_output, + matchers.MatchesRegex(r, self.re_options)) + + @mock.patch('cratonclient.v1.regions.RegionManager.get') + def test_do_region_show_calls_region_manager_with_fields(self, mock_get): + """Verify that do host update calls HostManager create.""" + client = mock.Mock() + session = mock.Mock() + session.project_id = 1 + client.regions = regions.RegionManager(session, 'http://127.0.0.1/') + test_args = Namespace(id=1) + regions_shell.do_region_show(client, test_args) + mock_get.assert_called_once_with(vars(test_args)['id'])