From 9218a48028db824204cf2708c3aee8f820d433d3 Mon Sep 17 00:00:00 2001 From: thuva4 Date: Thu, 10 May 2018 19:35:34 +0530 Subject: Add deploy results client Change-Id: I1f4cb33ce80318cdf532ce0dcb0665d890de1545 Signed-off-by: thuva4 --- .../testapiclient/client/deploy_results.py | 28 ++++++++ .../tests/unit/test_deployresults_client.py | 81 ++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 testapi/testapi-client/testapiclient/client/deploy_results.py create mode 100644 testapi/testapi-client/testapiclient/tests/unit/test_deployresults_client.py diff --git a/testapi/testapi-client/testapiclient/client/deploy_results.py b/testapi/testapi-client/testapiclient/client/deploy_results.py new file mode 100644 index 0000000..b0724b0 --- /dev/null +++ b/testapi/testapi-client/testapiclient/client/deploy_results.py @@ -0,0 +1,28 @@ +import json + +from testapiclient.client import base +from testapiclient.utils import urlparse + + +class DeployResultsClient(base.Client): + resource = 'deployresults' + + def __init__(self, **kwargs): + super(DeployResultsClient, self).__init__(**kwargs) + + def create(self, testcase_req): + return self.clientmanager.post(self.url, testcase_req) + + def get(self, **queries): + if queries: + return json.dumps( + self.clientmanager.get( + urlparse.query_join(self.url, **queries))['deployresults']) + else: + return json.dumps( + self.clientmanager.get(self.url)['deployresults']) + + def get_one(self, id): + return json.dumps( + self.clientmanager.get( + urlparse.path_join(self.url, id))) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_deployresults_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_deployresults_client.py new file mode 100644 index 0000000..03288fe --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_deployresults_client.py @@ -0,0 +1,81 @@ +import json + +from six.moves.urllib import parse +import testtools + +from testapiclient.client import deploy_results +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils +from testapiclient.utils import clientmanager + + +class DeployResultsClientTest(utils.TestCommand): + def setUp(self): + super(DeployResultsClientTest, self).setUp() + self.base_url = parse.urljoin(self.api_url, 'deployresults') + self.deployresult_json = { + 'project_name': 'functest', + 'scenario': 'test-scenario', + 'stop_date': '2018-04-09 13:44:53', + 'case_name': 'test-case', + 'build_tag': 'test-build', + 'version': 'test-version', + 'pod_name': 'test-pod', + 'criteria': 'test-criteria', + 'installer': 'test-installer', + 'start_date': '2018-04-09 13:44:53', + 'details': 'test-details' + } + self.deployresult_id = '5a6dc1089a07c80f3c9f8d62' + self.deployresult_string = json.dumps(self.deployresult_json) + self.deployresult_client = deploy_results.DeployResultsClient() + + +class DeployResultsClientGetTest(DeployResultsClientTest): + + def setUp(self): + super(DeployResultsClientGetTest, self).setUp() + self.deployresults_rsp = {'deployresults': [self.deployresult_json]} + + def test_get(self): + self.get_mock.return_value = fakes.FakeResponse( + data=self.deployresults_rsp) + self.deployresult_client.get() + self.get_mock.assert_called_once_with( + self.base_url, + headers=clientmanager.ClientManager.headers) + + def test_get_search(self): + self.get_mock.return_value = fakes.FakeResponse( + data=self.deployresults_rsp) + self.deployresult_client.get(name='deployresult1') + self.get_mock.assert_called_once_with( + self.base_url + '?name=deployresult1', + headers=clientmanager.ClientManager.headers) + + def test_get_one(self): + self.get_mock.return_value = fakes.FakeResponse( + data=self.deployresult_json) + self.deployresult_client.get_one('2333') + self.get_mock.assert_called_once_with( + self.base_url + '/2333', + headers=clientmanager.ClientManager.headers) + + +class DeployResultsClientCreateTest(DeployResultsClientTest): + + def setUp(self): + super(DeployResultsClientCreateTest, self).setUp() + self.succ_rsp = { + 'href': '{}/{}'.format(self.base_url, self.deployresult_id) + } + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse(data=self.succ_rsp) + self.deployresult_client.create(self.deployresult_json) + self.post_mock.assert_called_once() + + def test_create_failure(self): + with testtools.ExpectedException(Exception, 'Create failed: Error'): + self.post_mock.return_value = utils.FAKE_FAILURE + self.deployresult_client.create(self.deployresult_json) -- cgit 1.2.3-korg