diff options
author | Serena Feng <feng.xiaowei@zte.com.cn> | 2018-03-23 08:09:44 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-03-23 08:09:44 +0000 |
commit | bc9984f823618c421a613d366f2ce6c44346b26f (patch) | |
tree | db385fdd548a81755d3c3585e43e380f503559fa | |
parent | 924e01b30bb8f0743269206c420e2b4aba84628b (diff) | |
parent | de4afff43dfbfb9c05a7b67f29288a6f46485cac (diff) |
Merge "Add customs CRUD in testapiclient"
-rw-r--r-- | testapi/testapi-client/setup.cfg | 4 | ||||
-rw-r--r-- | testapi/testapi-client/testapiclient/cli/scenarios.py | 99 | ||||
-rw-r--r-- | testapi/testapi-client/testapiclient/tests/unit/test_scenario_custom.py | 88 |
3 files changed, 191 insertions, 0 deletions
diff --git a/testapi/testapi-client/setup.cfg b/testapi/testapi-client/setup.cfg index f860a2c..5366a08 100644 --- a/testapi/testapi-client/setup.cfg +++ b/testapi/testapi-client/setup.cfg @@ -52,6 +52,10 @@ testapi = scenario project delete = testapiclient.cli.scenarios:ProjectDelete scenario project put = testapiclient.cli.scenarios:ProjectPut + scenario custom create = testapiclient.cli.scenarios:CustomCreate + scenario custom delete = testapiclient.cli.scenarios:CustomDelete + scenario custom put = testapiclient.cli.scenarios:CustomPut + [egg_info] tag_build = tag_date = 0 diff --git a/testapi/testapi-client/testapiclient/cli/scenarios.py b/testapi/testapi-client/testapiclient/cli/scenarios.py index 1e384d0..edb45c6 100644 --- a/testapi/testapi-client/testapiclient/cli/scenarios.py +++ b/testapi/testapi-client/testapiclient/cli/scenarios.py @@ -390,3 +390,102 @@ class ProjectPut(command.Command): resources_url(parsed_args.scenario_name, 'projects'), ['installer', 'version'], parsed_args), parsed_args.project) + + +class CustomCreate(command.Command): + + def get_parser(self, prog_name): + parser = super(CustomCreate, self).get_parser(prog_name) + parser.add_argument('--scenario-name', + type=str, + required=True, + help='Create custom by scenario name') + parser.add_argument('--installer', + required=True, + help='Create custom under installer name') + parser.add_argument('--version', + required=True, + help='Create custom under version name') + parser.add_argument('--project', + required=True, + help='Create custom under project name') + parser.add_argument('custom', + nargs='+', + help='Space sperated strings') + return parser + + def take_action(self, parsed_args): + return self.app.client_manager.post( + urlparse.query_by( + resources_url( + parsed_args.scenario_name, + 'customs'), + ['installer', 'version', 'project'], + parsed_args), + parsed_args.custom) + + +class CustomDelete(command.Command): + + def get_parser(self, prog_name): + parser = super(CustomDelete, self).get_parser(prog_name) + parser.add_argument('--scenario-name', + required=True, + type=str, + help='Delete custom by scenario name') + parser.add_argument('--installer', + required=True, + help='Create custom under scenario name') + parser.add_argument('--version', + required=True, + help='Create custom under scenario name') + parser.add_argument('--project', + required=True, + help='Create custom under scenario name') + parser.add_argument('name', + nargs='+', + help='Delete custom by name') + return parser + + def take_action(self, parsed_args): + return self.app.client_manager.delete( + urlparse.query_by( + resources_url( + parsed_args.scenario_name, + 'customs'), + ['installer', 'version', 'project'], + parsed_args), + parsed_args.name) + + +class CustomPut(command.Command): + + def get_parser(self, prog_name): + parser = super(CustomPut, self).get_parser(prog_name) + parser.add_argument('--scenario-name', + type=str, + required=True, + help='Update custom by scenario name') + parser.add_argument('--installer', + required=True, + help='Update custom under installer name') + parser.add_argument('--version', + required=True, + help='Update custom under version name') + parser.add_argument('--project', + required=True, + help='Update custom under project name') + parser.add_argument('custom', + nargs='+', + help='space sperated strings') + return parser + + def take_action(self, parsed_args): + return self.app.client_manager.put( + urlparse.query_by( + resources_url( + parsed_args.scenario_name, + 'customs'), + ['installer', 'version', 'project'], + parsed_args), + parsed_args.custom) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_custom.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_custom.py new file mode 100644 index 0000000..e3f89c0 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_custom.py @@ -0,0 +1,88 @@ + + +from mock import mock +from six.moves.urllib import parse + +from testapiclient.cli import scenarios +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils + + +class CustomTest(utils.TestCommand): + def setUp(self): + super(CustomTest, self).setUp() + self.base_url = parse.urljoin(self.api_url, 'scenarios/{}/customs') + self.scenario_name = 's1' + self.custom_input = 'custom' + self.custom_parsed = ['custom'] + + +class CustomCreateTest(CustomTest): + + def setUp(self): + super(CustomCreateTest, self).setUp() + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse(data=None) + custom_create = scenarios.CustomCreate(self.app, mock.Mock()) + args = [ + '--scenario-name', 's1', '--installer', 'i1', '--version', + 'v1', '--project', 'p1', self.custom_input] + verifies = [ + ('scenario_name', 's1'), + ('installer', 'i1'), + ('version', 'v1'), + ('project', 'p1'), + ('custom', self.custom_parsed)] + parsed_args = self.check_parser(custom_create, args, verifies) + custom_create.take_action(parsed_args) + self.post_mock.assert_called_once() + + +class CustomDeleteTest(CustomTest): + + def setUp(self): + super(CustomDeleteTest, self).setUp() + + def test_delete_success(self): + self.delete_mock.return_value = fakes.FakeResponse(data=None) + custom_delete = scenarios.CustomDelete(self.app, mock.Mock()) + args = [ + '--scenario-name', 's1', '--installer', 'i1', + '--version', 'v1', '--project', 'p1', 'def'] + verifies = [ + ('scenario_name', 's1'), + ('installer', 'i1'), + ('version', 'v1'), + ('project', 'p1'), + ('name', ['def'])] + parsed_args = self.check_parser(custom_delete, args, verifies) + custom_delete.take_action(parsed_args) + kall = self.delete_mock.call_args + args, kwargs = kall + self.assert_url( + args[0], + self.base_url + '?version=v1&project=p1&installer=i1') + + +class CustomPutTest(CustomTest): + + def setUp(self): + super(CustomPutTest, self).setUp() + + def test_put_success(self): + self.put_mock.return_value = fakes.FakeResponse( + data=None) + custom_put = scenarios.CustomPut(self.app, mock.Mock()) + args = [ + '--scenario-name', 's1', '--installer', 'i1', '--version', 'v1', + '--project', 'p1', self.custom_input] + verifies = [ + ('scenario_name', 's1'), + ('installer', 'i1'), + ('version', 'v1'), + ('project', 'p1'), + ('custom', self.custom_parsed)] + parsed_args = self.check_parser(custom_put, args, verifies) + custom_put.take_action(parsed_args) + self.put_mock.assert_called_once() |