Adding region update capabilities to python and CLI clients.

CLI: region-update <region_id> <args>
python: region.update(region_id, args)

Change-Id: Ic52bcc23a85859a3284fa0ddb8e8acddecb053ad
Implements: blueprint craton-client-access-inventory (partial)
Closes-Bug: #1613345
This commit is contained in:
Chris Spencer
2016-08-19 12:33:16 -07:00
parent d021b036c0
commit afc34fb2b8
2 changed files with 60 additions and 0 deletions

View File

@@ -42,6 +42,29 @@ def do_region_show(cc, args):
cliutils.print_dict(data, wrap=72)
@cliutils.arg('id',
metavar='<region>',
type=int,
help='ID of the region')
@cliutils.arg('-n', '--name',
metavar='<name>',
help='Name of the region.')
@cliutils.arg('-p', '--project',
dest='project_id',
metavar='<project_id>',
type=int,
help='ID of the project that the region belongs to.')
@cliutils.arg('--note',
help='Note about the region.')
def do_region_update(cc, args):
"""Update a region that is registered with the Craton service."""
fields = {k: v for (k, v) in vars(args).items()
if k in r_fields and not (v is None)}
region = cc.regions.update(**fields)
data = {f: getattr(region, f, '') for f in r_fields}
cliutils.print_dict(data, wrap=72)
@cliutils.arg('id',
metavar='<region>',
type=int,

View File

@@ -115,3 +115,40 @@ class TestRegionsShell(base.ShellTestCase):
test_args = Namespace(id=1)
regions_shell.do_region_delete(client, test_args)
mock_delete.assert_called_once_with(vars(test_args)['id'])
def test_region_update_missing_required_args(self):
"""Verify that missing required args results in error message."""
expected_responses = [
'.*?^usage: craton region-update',
'.*?^craton region-update: error:.*$',
]
stdout, stderr = self.shell('region-update')
for r in expected_responses:
self.assertThat((stdout + stderr),
matchers.MatchesRegex(r, self.re_options))
@mock.patch('cratonclient.v1.regions.RegionManager.update')
def test_do_region_update_calls_region_manager(self, mock_update):
"""Verify that do region update calls RegionManager update."""
client = mock.Mock()
session = mock.Mock()
session.project_id = 1
client.regions = regions.RegionManager(session, 'http://127.0.0.1/')
valid_input = Namespace(id=1,
name='mock_region')
regions_shell.do_region_update(client, valid_input)
mock_update.assert_called_once_with(**vars(valid_input))
@mock.patch('cratonclient.v1.regions.RegionManager.update')
def test_do_region_update_ignores_unknown_fields(self, mock_update):
"""Verify that do region update ignores unknown field."""
client = mock.Mock()
session = mock.Mock()
session.project_id = 1
client.regions = regions.RegionManager(session, 'http://127.0.0.1/')
invalid_input = Namespace(id=1,
name='mock_region',
invalid=True)
regions_shell.do_region_update(client, invalid_input)
vars(invalid_input).pop('invalid')
mock_update.assert_called_once_with(**vars(invalid_input))