diff --git a/cratonclient/shell/v1/regions_shell.py b/cratonclient/shell/v1/regions_shell.py index 1541fde..c16ef81 100644 --- a/cratonclient/shell/v1/regions_shell.py +++ b/cratonclient/shell/v1/regions_shell.py @@ -40,3 +40,14 @@ def do_region_show(cc, args): region = cc.regions.get(args.id) 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_delete(cc, args): + """Delete a region that is registered with the Craton service.""" + response = cc.regions.delete(args.id) + print("Region {0} was {1}successfully deleted.". + format(args.id, '' if response else 'un')) diff --git a/cratonclient/tests/unit/test_cells_shell.py b/cratonclient/tests/unit/test_cells_shell.py index d8be071..5a5f80a 100644 --- a/cratonclient/tests/unit/test_cells_shell.py +++ b/cratonclient/tests/unit/test_cells_shell.py @@ -191,7 +191,7 @@ class TestCellsShell(base.ShellTestCase): @mock.patch('cratonclient.v1.cells.CellManager.update') def test_do_cell_update_calls_cell_manager_with_fields(self, mock_update): - """Verify that do cell update calls CellManager create.""" + """Verify that do cell update calls CellManager update.""" client = mock.Mock() inventory = mock.Mock() inventory.cells = cells.CellManager(mock.ANY, @@ -208,7 +208,7 @@ class TestCellsShell(base.ShellTestCase): @mock.patch('cratonclient.v1.cells.CellManager.update') def test_do_cell_update_ignores_unknown_fields(self, mock_update): - """Verify that do cell create ignores unknown field.""" + """Verify that do cell update ignores unknown field.""" client = mock.Mock() inventory = mock.Mock() inventory.cells = cells.CellManager(mock.ANY, @@ -239,7 +239,7 @@ class TestCellsShell(base.ShellTestCase): @mock.patch('cratonclient.v1.cells.CellManager.get') def test_do_cell_show_calls_cell_manager_with_fields(self, mock_get): - """Verify that do cell update calls CellManager create.""" + """Verify that do cell show calls CellManager get.""" client = mock.Mock() inventory = mock.Mock() inventory.cells = cells.CellManager(mock.ANY, @@ -264,7 +264,7 @@ class TestCellsShell(base.ShellTestCase): @mock.patch('cratonclient.v1.cells.CellManager.delete') def test_do_cell_delete_calls_cell_manager_with_fields(self, mock_delete): - """Verify that do cell update calls CellManager create.""" + """Verify that do cell delete calls CellManager delete.""" client = mock.Mock() inventory = mock.Mock() inventory.cells = cells.CellManager(mock.ANY, diff --git a/cratonclient/tests/unit/test_hosts_shell.py b/cratonclient/tests/unit/test_hosts_shell.py index 7db2e33..1e315d1 100644 --- a/cratonclient/tests/unit/test_hosts_shell.py +++ b/cratonclient/tests/unit/test_hosts_shell.py @@ -203,7 +203,7 @@ class TestHostsShell(base.ShellTestCase): @mock.patch('cratonclient.v1.hosts.HostManager.update') def test_do_host_update_calls_host_manager_with_fields(self, mock_update): - """Verify that do host update calls HostManager create.""" + """Verify that do host update calls HostManager update.""" client = mock.Mock() inventory = mock.Mock() inventory.hosts = hosts.HostManager(mock.ANY, @@ -220,7 +220,7 @@ class TestHostsShell(base.ShellTestCase): @mock.patch('cratonclient.v1.hosts.HostManager.update') def test_do_host_update_ignores_unknown_fields(self, mock_update): - """Verify that do host create ignores unknown field.""" + """Verify that do host update ignores unknown field.""" client = mock.Mock() inventory = mock.Mock() inventory.hosts = hosts.HostManager(mock.ANY, @@ -251,7 +251,7 @@ class TestHostsShell(base.ShellTestCase): @mock.patch('cratonclient.v1.hosts.HostManager.get') def test_do_host_show_calls_host_manager_with_fields(self, mock_get): - """Verify that do host update calls HostManager create.""" + """Verify that do host show calls HostManager get.""" client = mock.Mock() inventory = mock.Mock() inventory.hosts = hosts.HostManager(mock.ANY, @@ -276,7 +276,7 @@ class TestHostsShell(base.ShellTestCase): @mock.patch('cratonclient.v1.hosts.HostManager.delete') def test_do_host_delete_calls_host_manager_with_fields(self, mock_delete): - """Verify that do host update calls HostManager create.""" + """Verify that do host delete calls HostManager delete.""" client = mock.Mock() inventory = mock.Mock() inventory.hosts = hosts.HostManager(mock.ANY, diff --git a/cratonclient/tests/unit/test_regions_shell.py b/cratonclient/tests/unit/test_regions_shell.py index 0932d1a..39a7a06 100644 --- a/cratonclient/tests/unit/test_regions_shell.py +++ b/cratonclient/tests/unit/test_regions_shell.py @@ -52,7 +52,7 @@ class TestRegionsShell(base.ShellTestCase): matchers.MatchesRegex(r, self.re_options)) @mock.patch('cratonclient.v1.regions.RegionManager.create') - def test_do_region_create_calls_host_manager(self, mock_create): + def test_do_region_create_calls_region_manager(self, mock_create): """Verify that do region create calls RegionManager create.""" client = mock.Mock() session = mock.Mock() @@ -63,7 +63,7 @@ class TestRegionsShell(base.ShellTestCase): @mock.patch('cratonclient.v1.regions.RegionManager.create') def test_do_region_create_ignores_unknown_fields(self, mock_create): - """Verify that do host create ignores unknown field.""" + """Verify that do region create ignores unknown field.""" client = mock.Mock() session = mock.Mock() session.project_id = 1 @@ -85,7 +85,7 @@ class TestRegionsShell(base.ShellTestCase): @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.""" + """Verify that do region show calls RegionManager get.""" client = mock.Mock() session = mock.Mock() session.project_id = 1 @@ -93,3 +93,25 @@ class TestRegionsShell(base.ShellTestCase): test_args = Namespace(id=1) regions_shell.do_region_show(client, test_args) mock_get.assert_called_once_with(vars(test_args)['id']) + + def test_region_delete_missing_required_args(self): + """Verify that missing required args results in error message.""" + expected_responses = [ + '.*?^usage: craton region-delete', + '.*?^craton region-delete: error:.*$', + ] + stdout, stderr = self.shell('region-delete') + for r in expected_responses: + self.assertThat((stdout + stderr), + matchers.MatchesRegex(r, self.re_options)) + + @mock.patch('cratonclient.v1.regions.RegionManager.delete') + def test_do_region_delete_calls_region_manager(self, mock_delete): + """Verify that do region delete calls RegionManager delete.""" + 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_delete(client, test_args) + mock_delete.assert_called_once_with(vars(test_args)['id']) diff --git a/cratonclient/v1/regions.py b/cratonclient/v1/regions.py index 0b0f913..1e66e0a 100644 --- a/cratonclient/v1/regions.py +++ b/cratonclient/v1/regions.py @@ -29,7 +29,6 @@ class RegionManager(crud.CRUDClient): resource_class = Region project_id = 0 - REGION_FIELDS = { 'id': 'ID', 'project_id': 'Project ID',