diff --git a/cratonclient/shell/v1/cells_shell.py b/cratonclient/shell/v1/cells_shell.py index b8b6d4c..c312c6e 100644 --- a/cratonclient/shell/v1/cells_shell.py +++ b/cratonclient/shell/v1/cells_shell.py @@ -84,9 +84,19 @@ def do_cell_show(cc, args): metavar='', default=None, help='ID of the cell to use to resume listing cells.') +@cliutils.arg('--vars', + metavar='', + nargs='+', + action='append', + default=[], + help='Variables to use as filter in the form of ' + '--vars="key:value" --vars="key2:value2"') def do_cell_list(cc, args): """Print list of cells which are registered with the Craton service.""" params = {} + if args.vars: + query_vars = ",".join([i[0] for i in args.vars]) + params['vars'] = query_vars if args.cloud is not None: params['cloud_id'] = args.cloud if args.limit is not None: diff --git a/cratonclient/tests/integration/shell/v1/test_cells_shell.py b/cratonclient/tests/integration/shell/v1/test_cells_shell.py index f5ede2f..c435827 100644 --- a/cratonclient/tests/integration/shell/v1/test_cells_shell.py +++ b/cratonclient/tests/integration/shell/v1/test_cells_shell.py @@ -181,6 +181,30 @@ class TestCellsShell(base.ShellTestCase): ) self.assertIn("invalid choice: 'invalid'", error) + @mock.patch('cratonclient.v1.cells.CellManager.list') + def test_cell_list_with_vars_success(self, mock_list): + """Verify --vars arguments successfully passed to Client.""" + self.shell('cell-list --vars a:b') + mock_list.assert_called_once_with( + vars='a:b', + marker=None, + sort_dir='asc', + autopaginate=False, + ) + mock_list.reset_mock() + + @mock.patch('cratonclient.v1.cells.CellManager.list') + def test_cell_list_with_multiple_vars_success(self, mock_list): + """Verify multiple --vars arguments successfully passed to Client.""" + self.shell('cell-list --vars=a:b --vars=c:d') + mock_list.assert_called_once_with( + vars='a:b,c:d', + marker=None, + sort_dir='asc', + autopaginate=False, + ) + mock_list.reset_mock() + def test_cell_create_missing_required_args(self): """Verify that missing required args results in error message.""" expected_responses = [ diff --git a/cratonclient/tests/unit/shell/v1/test_cells_shell.py b/cratonclient/tests/unit/shell/v1/test_cells_shell.py index 5e7e07e..d25793d 100644 --- a/cratonclient/tests/unit/shell/v1/test_cells_shell.py +++ b/cratonclient/tests/unit/shell/v1/test_cells_shell.py @@ -56,6 +56,7 @@ class TestDoCellList(base.TestShellCommand): kwargs.setdefault('fields', cells_shell.DEFAULT_CELL_FIELDS) kwargs.setdefault('marker', None) kwargs.setdefault('all', False) + kwargs.setdefault('vars', None) return super(TestDoCellList, self).args_for(**kwargs) def test_with_defaults(self): @@ -177,6 +178,19 @@ class TestDoCellList(base.TestShellCommand): self.assertRaisesCommandErrorWith(cells_shell.do_cell_list, args) self.assertNothingWasCalled() + def test_with_multiple_vars(self): + """Verify that we pass vars filters to cell list.""" + args = self.args_for(vars=[['a:b'], ['c:d']]) + cells_shell.do_cell_list(self.craton_client, args) + self.craton_client.cells.list.assert_called_once_with( + vars='a:b,c:d', + region_id=123, + marker=None, + sort_dir='asc', + autopaginate=False, + ) + self.assertFieldsEqualTo(cells_shell.DEFAULT_CELL_FIELDS) + def test_autopaginate(self): """Verify that autopagination works.""" args = self.args_for(all=True)