diff --git a/congressclient/osc/v1/datasource.py b/congressclient/osc/v1/datasource.py index 1814f67..f2954c7 100644 --- a/congressclient/osc/v1/datasource.py +++ b/congressclient/osc/v1/datasource.py @@ -62,10 +62,8 @@ class ListDatasourceTables(lister.Lister): def take_action(self, parsed_args): self.log.debug('take_action(%s)' % parsed_args) client = self.app.client_manager.congressclient - results = client.list_datasources() - datasource_id = utils.get_resource_id_from_name( - parsed_args.datasource_name, results) - data = client.list_datasource_tables(datasource_id)['results'] + name_or_id = parsed_args.datasource_name + data = client.list_datasource_tables(name_or_id)['results'] columns = ['id'] formatters = {'DatasourceTables': utils.format_list} return (columns, @@ -90,11 +88,7 @@ class ShowDatasourceStatus(show.ShowOne): def take_action(self, parsed_args): self.log.debug('take_action(%s)' % parsed_args) client = self.app.client_manager.congressclient - - results = client.list_datasources() - datasource_id = utils.get_resource_id_from_name( - parsed_args.datasource_name, results) - + datasource_id = parsed_args.datasource_name data = client.list_datasource_status(datasource_id) return zip(*sorted(six.iteritems(data))) @@ -119,11 +113,7 @@ class ShowDatasourceActions(lister.Lister): parsed_args.max_width = 40 client = self.app.client_manager.congressclient - - results = client.list_datasources() - datasource_id = utils.get_resource_id_from_name( - parsed_args.datasource_name, results) - + datasource_id = parsed_args.datasource_name data = client.list_datasource_actions(datasource_id) formatters = {'args': utils.format_long_dict_list} newdata = [{'action': x['name'], @@ -153,9 +143,7 @@ class ShowDatasourceSchema(lister.Lister): def take_action(self, parsed_args): self.log.debug('take_action(%s)' % parsed_args) client = self.app.client_manager.congressclient - results = client.list_datasources() - datasource_id = utils.get_resource_id_from_name( - parsed_args.datasource_name, results) + datasource_id = parsed_args.datasource_name data = client.show_datasource_schema(datasource_id) formatters = {'columns': utils.format_long_dict_list} newdata = [{'table': x['table_id'], @@ -188,9 +176,7 @@ class ShowDatasourceTableSchema(lister.Lister): def take_action(self, parsed_args): self.log.debug('take_action(%s)' % parsed_args) client = self.app.client_manager.congressclient - results = client.list_datasources() - datasource_id = utils.get_resource_id_from_name( - parsed_args.datasource_name, results) + datasource_id = parsed_args.datasource_name data = client.show_datasource_table_schema( datasource_id, parsed_args.table_name) @@ -220,10 +206,7 @@ class ListDatasourceRows(lister.Lister): def take_action(self, parsed_args): self.log.debug('take_action(%s)' % parsed_args) client = self.app.client_manager.congressclient - - results = client.list_datasources() - datasource_id = utils.get_resource_id_from_name( - parsed_args.datasource_name, results) + datasource_id = parsed_args.datasource_name results = client.list_datasource_rows(datasource_id, parsed_args.table)['results'] if results: @@ -317,9 +300,7 @@ class DeleteDatasource(command.Command): def take_action(self, parsed_args): self.log.debug('take_action(%s)' % parsed_args) client = self.app.client_manager.congressclient - results = client.list_datasources() - datasource_id = utils.get_resource_id_from_name( - parsed_args.datasource, results) + datasource_id = parsed_args.datasource client.delete_datasource(datasource_id) diff --git a/congressclient/tests/v1/test_datasource.py b/congressclient/tests/v1/test_datasource.py index 9928758..0fc9e2a 100644 --- a/congressclient/tests/v1/test_datasource.py +++ b/congressclient/tests/v1/test_datasource.py @@ -96,16 +96,13 @@ class TestListDatasourceTables(common.TestCongressBase): {"id": "networks"}] } lister = mock.Mock(return_value=response) - self.app.client_manager.congressclient.list_datasources = mock.Mock() self.app.client_manager.congressclient.list_datasource_tables = lister cmd = datasource.ListDatasourceTables(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - with mock.patch.object(utils, "get_resource_id_from_name", - return_value="id"): - result = cmd.take_action(parsed_args) - lister.assert_called_with("id") + result = cmd.take_action(parsed_args) + lister.assert_called_with(datasource_name) self.assertEqual(['id'], result[0]) @@ -122,15 +119,12 @@ class TestListDatasourceStatus(common.TestCongressBase): 'last_error': "None"} lister = mock.Mock(return_value=response) self.app.client_manager.congressclient.list_datasource_status = lister - self.app.client_manager.congressclient.list_datasources = mock.Mock() cmd = datasource.ShowDatasourceStatus(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - with mock.patch.object(utils, "get_resource_id_from_name", - return_value="id"): - result = list(cmd.take_action(parsed_args)) + result = list(cmd.take_action(parsed_args)) - lister.assert_called_with("id") + lister.assert_called_with(datasource_name) self.assertEqual([('last_error', 'last_updated'), ('None', 'now')], result) @@ -155,15 +149,12 @@ class TestShowDatasourceActions(common.TestCongressBase): } lister = mock.Mock(return_value=response) self.app.client_manager.congressclient.list_datasource_actions = lister - self.app.client_manager.congressclient.list_datasources = mock.Mock() cmd = datasource.ShowDatasourceActions(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - with mock.patch.object(utils, "get_resource_id_from_name", - return_value="id"): - result = cmd.take_action(parsed_args) + result = cmd.take_action(parsed_args) - lister.assert_called_once_with("id") + lister.assert_called_once_with(datasource_name) self.assertEqual(['action', 'args', 'description'], result[0]) @@ -189,15 +180,12 @@ class TestShowDatasourceSchema(common.TestCongressBase): } lister = mock.Mock(return_value=response) self.app.client_manager.congressclient.show_datasource_schema = lister - self.app.client_manager.congressclient.list_datasources = mock.Mock() cmd = datasource.ShowDatasourceSchema(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - with mock.patch.object(utils, "get_resource_id_from_name", - return_value="id"): - result = cmd.take_action(parsed_args) + result = cmd.take_action(parsed_args) - lister.assert_called_with("id") + lister.assert_called_with(datasource_name) self.assertEqual(['table', 'columns'], result[0]) @@ -224,11 +212,9 @@ class TestShowDatasourceTableSchema(common.TestCongressBase): cmd = datasource.ShowDatasourceTableSchema(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - with mock.patch.object(utils, "get_resource_id_from_name", - return_value="id"): - result = cmd.take_action(parsed_args) + result = cmd.take_action(parsed_args) - lister.assert_called_with("id", table_name) + lister.assert_called_with(datasource_name, table_name) self.assertEqual(['name', 'description'], result[0]) @@ -256,18 +242,15 @@ class TestListDatasourceRows(common.TestCongressBase): client = self.app.client_manager.congressclient lister = mock.Mock(return_value=response) - self.app.client_manager.congressclient.list_datasources = mock.Mock() client.list_datasource_rows = lister schema_lister = mock.Mock(return_value=schema_response) client.show_datasource_table_schema = schema_lister cmd = datasource.ListDatasourceRows(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - with mock.patch.object(utils, "get_resource_id_from_name", - return_value="id"): - result = cmd.take_action(parsed_args) + result = cmd.take_action(parsed_args) - lister.assert_called_with('id', table_name) + lister.assert_called_with(datasource_name, table_name) self.assertEqual(['ID', 'name'], result[0]) @@ -352,13 +335,10 @@ class TestDeleteDatasourceDriver(common.TestCongressBase): mocker = mock.Mock(return_value=None) self.app.client_manager.congressclient.delete_datasource = mocker - self.app.client_manager.congressclient.list_datasources = mock.Mock() cmd = datasource.DeleteDatasource(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - with mock.patch.object(utils, "get_resource_id_from_name", - return_value="id"): - result = cmd.take_action(parsed_args) - mocker.assert_called_with("id") + result = cmd.take_action(parsed_args) + mocker.assert_called_with(driver) self.assertIsNone(result)