From e09c3ca0bd5ccf4adbce8635ec1c2a8d20a6e319 Mon Sep 17 00:00:00 2001 From: thuva4 Date: Fri, 23 Mar 2018 12:40:52 +0530 Subject: Add scores CRUD in testapiclient implement interface to do CRUD operations for scores in testapiclient Tests are added Change-Id: Icf73a0ecdadcd51c0457837306d24ec7851500eb Signed-off-by: thuva4 --- testapi/testapi-client/setup.cfg | 2 ++ .../testapi-client/testapiclient/cli/scenarios.py | 35 ++++++++++++++++++ .../tests/unit/test_scenario_score.py | 42 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 testapi/testapi-client/testapiclient/tests/unit/test_scenario_score.py (limited to 'testapi/testapi-client') diff --git a/testapi/testapi-client/setup.cfg b/testapi/testapi-client/setup.cfg index fc25cf3..2427c57 100644 --- a/testapi/testapi-client/setup.cfg +++ b/testapi/testapi-client/setup.cfg @@ -58,6 +58,8 @@ testapi = scenario trustindicator create = testapiclient.cli.scenarios:TrustIndicatorCreate + scenario score create = testapiclient.cli.scenarios:ScoreCreate + [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 c5444e2..507705a 100644 --- a/testapi/testapi-client/testapiclient/cli/scenarios.py +++ b/testapi/testapi-client/testapiclient/cli/scenarios.py @@ -525,3 +525,38 @@ class TrustIndicatorCreate(command.Command): ['installer', 'version', 'project'], parsed_args), parsed_args.trust_indicator) + + +class ScoreCreate(command.Command): + + def get_parser(self, prog_name): + parser = super(ScoreCreate, self).get_parser(prog_name) + parser.add_argument('--scenario-name', + type=str, + required=True, + help='Create score by scenario name') + parser.add_argument('--installer', + required=True, + help='Create score under installer name') + parser.add_argument('--version', + required=True, + help='Create score under version name') + parser.add_argument('--project', + required=True, + help='Create score under project name') + parser.add_argument('score', + type=json.loads, + help='score create request format :\n' + '\'{ "date": (string, optional),' + '"score" : (string, optional) }\',\n') + return parser + + def take_action(self, parsed_args): + return self.app.client_manager.post( + urlparse.query_by( + resources_url( + parsed_args.scenario_name, + 'scores'), + ['installer', 'version', 'project'], + parsed_args), + parsed_args.score) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_score.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_score.py new file mode 100644 index 0000000..3b0e1c6 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_score.py @@ -0,0 +1,42 @@ +import json + +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 ScoreTest(utils.TestCommand): + def setUp(self): + super(ScoreTest, self).setUp() + self.base_url = parse.urljoin(self.api_url, 'scenarios/{}/scores') + self.scenario_name = 's1' + self.score_json = { + 'score': 'test_score1', + 'date': '2018/01/2' + } + self.score_string = json.dumps(self.score_json) + + +class ScoreCreateTest(ScoreTest): + + def setUp(self): + super(ScoreCreateTest, self).setUp() + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse(data=None) + score_create = scenarios.ScoreCreate(self.app, mock.Mock()) + args = [ + '--scenario-name', 's1', '--installer', 'i1', '--version', 'v1', + '--project', 'p1', self.score_string] + verifies = [ + ('scenario_name', 's1'), + ('installer', 'i1'), + ('version', 'v1'), + ('project', 'p1'), + ('score', self.score_json)] + parsed_args = self.check_parser(score_create, args, verifies) + score_create.take_action(parsed_args) + self.post_mock.assert_called_once() -- cgit 1.2.3-korg