summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--testapi/docs/developer/devguide/testapi-client-import.rst123
-rw-r--r--testapi/testapi-client/testapiclient/client/deploy_results.py28
-rw-r--r--testapi/testapi-client/testapiclient/client/projects.py35
-rw-r--r--testapi/testapi-client/testapiclient/client/results.py28
-rw-r--r--testapi/testapi-client/testapiclient/tests/unit/test_deployresults_client.py81
-rw-r--r--testapi/testapi-client/testapiclient/tests/unit/test_project_client.py111
-rw-r--r--testapi/testapi-client/testapiclient/tests/unit/test_results_client.py78
7 files changed, 479 insertions, 5 deletions
diff --git a/testapi/docs/developer/devguide/testapi-client-import.rst b/testapi/docs/developer/devguide/testapi-client-import.rst
index 69cb6ad..ad41029 100644
--- a/testapi/docs/developer/devguide/testapi-client-import.rst
+++ b/testapi/docs/developer/devguide/testapi-client-import.rst
@@ -21,7 +21,7 @@ Pod
GET
"""
-User will get the json Pod objects with the get request.
+Get a list of all the declared pods from the TestAPI server.
.. code-block:: shell
@@ -30,7 +30,9 @@ User will get the json Pod objects with the get request.
pod_client = pods.PodsClient()
pod_client.get()
-User can use search parameters to get pods
+The user can filter the results by the name attribute. Backend will
+use a regular expression to find the list of pods which are
+related to given name.
.. code-block:: shell
@@ -39,10 +41,15 @@ User can use search parameters to get pods
pod_client = pods.PodsClient()
pod_client.get(name='pod1')
+.. NOTE::
+ Response format: [{"_id": "", "creator": "", "role": "", "name": "",
+ "details": "", "mode": "", "creation_date": ""}]
+
+
GET ONE
"""""""
-User will get the json Pod objects with the get request.
+Get a specific pod by its name.
.. code-block:: shell
@@ -51,9 +58,25 @@ User will get the json Pod objects with the get request.
pod_client = pods.PodsClient()
pod_client.get_one('name')
+.. NOTE::
+ Response format: {"_id": "", "creator": "", "role": "", "name": "",
+ "details": "", "mode": "", "creation_date": ""}
+
CREATE
""""""
-User has to authenticate before running the function.
+This method used to create a project on the server.
+The user should provide the user parameter and the password
+parameter while initiating the PodsClient.
+
+Input for the function :
+
+ * pod-json : Json object of the project
+
+.. NOTE::
+ pod-json-schema - '{"role": "", "name": "", "details": "", "mode": ""}'
+
+ * role should be either "community-ci" or "production-ci"
+ * mode should be either "metal" or "virtual"
.. code-block:: shell
@@ -61,5 +84,95 @@ User has to authenticate before running the function.
pod_client = pods.PodsClient(user='test', password='pass')
pod_client.create({'name': 'test-api', 'mode':'metal',
- 'role':'community_ci', 'details':''}
+ 'role':'community_ci', 'details':''})
+
+
+Project
+^^^^^^^
+
+GET
+"""
+
+Get a list of all the declared projects from the TestAPI server.
+
+.. code-block:: shell
+
+ from testapiclient.client import projects
+
+ project_client = projects.ProjectsClient()
+ project_client.get()
+
+User can filter the results by the name attribute. Backend will
+use a regular expression to find the list of projects which are
+related to given name.
+
+.. code-block:: shell
+
+ from testapiclient.client import projects
+
+ project_client = projects.ProjectsClient()
+ project_client.get(name='project1')
+
+.. NOTE::
+ Response format: [{"_id": "", "creator": "", "description": "",
+ "name": "", "creation_date": ""}]
+
+GET ONE
+"""""""
+
+Get a specific project by its name.
+
+.. code-block:: shell
+
+ from testapiclient.client import projects
+
+ project_client = projects.ProjectsClient()
+ project_client.get_one('name')
+
+.. NOTE::
+ Response format: {"_id": "", "creator": "", "description": "",
+ "name": "", "creation_date": ""}
+
+CREATE
+""""""
+
+This method used to create a project on the server.
+The user should provide the user parameter and the password
+parameter while initiating the ProjectsClient.
+
+Input for the function :
+
+ * project-json : Json object of the project
+
+.. NOTE::
+ project-json schema - '{"description": "", "name": ""}'
+
+.. code-block:: shell
+
+ from testapiclient.client import projects
+
+ project_client = projects.ProjectsClient(user='test', password='pass')
+ project_client.create({'name': 'functest', 'description':'sample text'}
+
+UPDATE
+""""""
+
+This method used to update an existing project on the server.
+The user should provide the user parameter and the password
+parameter while initiating the ProjectsClient.
+
+Input for the function :
+
+ * project-name: name of the project which user want to update.
+ * project-json: Json object of the project
+
+.. NOTE::
+ project-json schema - '{"description": "", "name": ""}'
+
+.. code-block:: shell
+
+ from testapiclient.client import projects
+ project_client = projects.ProjectsClient(user='test', password='pass')
+ project_client.update('functest', {'name': 'functest',
+ 'description':'updated text'}) \ No newline at end of file
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/client/projects.py b/testapi/testapi-client/testapiclient/client/projects.py
new file mode 100644
index 0000000..63d00fe
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/client/projects.py
@@ -0,0 +1,35 @@
+import json
+
+from testapiclient.client import base
+from testapiclient.utils import urlparse
+
+
+class ProjectsClient(base.Client):
+ resource = 'projects'
+
+ def __init__(self, **kwargs):
+ super(ProjectsClient, self).__init__(**kwargs)
+
+ def create(self, project_req):
+ return self.clientmanager.post(self.url, project_req)
+
+ def get(self, **queries):
+ if queries:
+ return json.dumps(
+ self.clientmanager.get(
+ urlparse.query_join(self.url, **queries))['projects'])
+ else:
+ return json.dumps(
+ self.clientmanager.get(self.url)['projects'])
+
+ def get_one(self, name):
+ return json.dumps(self.clientmanager.get(
+ urlparse.path_join(self.url, name)))
+
+ def delete(self, name):
+ return self.clientmanager.delete(
+ urlparse.path_join(self.url, name))
+
+ def update(self, name, project_req):
+ return self.clientmanager.put(
+ urlparse.path_join(self.url, name), project_req)
diff --git a/testapi/testapi-client/testapiclient/client/results.py b/testapi/testapi-client/testapiclient/client/results.py
new file mode 100644
index 0000000..7d9ad0e
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/client/results.py
@@ -0,0 +1,28 @@
+import json
+
+from testapiclient.client import base
+from testapiclient.utils import urlparse
+
+
+class ResultsClient(base.Client):
+ resource = 'results'
+
+ def __init__(self, **kwargs):
+ super(ResultsClient, 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))['results'])
+ else:
+ return json.dumps(
+ self.clientmanager.get(self.url)['results'])
+
+ 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)
diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_project_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_project_client.py
new file mode 100644
index 0000000..7aa11e6
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/tests/unit/test_project_client.py
@@ -0,0 +1,111 @@
+import json
+
+from six.moves.urllib import parse
+import testtools
+
+from testapiclient.client import projects
+from testapiclient.tests.unit import fakes
+from testapiclient.tests.unit import utils
+from testapiclient.utils import clientmanager
+
+
+class ProjectClientTest(utils.TestCommand):
+ def setUp(self):
+ super(ProjectClientTest, self).setUp()
+ self.base_url = parse.urljoin(self.api_url, 'projects')
+ self.project_json = {
+ 'description': 'test_description',
+ 'name': 'test_project',
+ }
+ self.project_client = projects.ProjectsClient()
+ self.project_string = json.dumps(self.project_json)
+
+
+class ProjectClientGetTest(ProjectClientTest):
+
+ def setUp(self):
+ super(ProjectClientGetTest, self).setUp()
+ self.projects_rsp = {'projects': [self.project_json]}
+
+ def test_get(self):
+ self.get_mock.return_value = fakes.FakeResponse(
+ data=self.projects_rsp)
+ self.project_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.projects_rsp)
+ self.project_client.get(name='project1')
+ self.get_mock.assert_called_once_with(
+ self.base_url + '?name=project1',
+ headers=clientmanager.ClientManager.headers)
+
+ def test_get_one(self):
+ self.get_mock.return_value = fakes.FakeResponse(
+ data=self.project_json)
+ self.project_client.get_one('def')
+ self.get_mock.assert_called_once_with(
+ self.base_url + '/def',
+ headers=clientmanager.ClientManager.headers)
+
+
+class ProjectClientCreateTest(ProjectClientTest):
+
+ def setUp(self):
+ super(ProjectClientCreateTest, self).setUp()
+ self.succ_rsp = {
+ 'href': '{}/{}'.format(
+ self.base_url, self.project_json.get('name'))
+ }
+
+ def test_create_success(self):
+ self.post_mock.return_value = fakes.FakeResponse(
+ data=self.succ_rsp)
+ self.project_client.create(self.project_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.project_client.create(self.project_json)
+
+
+class ProjectClientDeleteTest(ProjectClientTest):
+
+ def setUp(self):
+ super(ProjectClientDeleteTest, self).setUp()
+
+ def test_delete_success(self):
+ self.delete_mock.return_value = fakes.FakeResponse()
+ self.project_client.delete('def')
+ self.delete_mock.assert_called_once_with(
+ self.base_url + '/def',
+ data=None,
+ headers=clientmanager.ClientManager.headers)
+
+ def test_delete_failure(self):
+ with testtools.ExpectedException(Exception, 'Delete failed: Error'):
+ self.delete_mock.return_value = utils.FAKE_FAILURE
+ self.project_client.delete('def')
+
+
+class ProjectClientUpdateTest(ProjectClientTest):
+
+ def setUp(self):
+ super(ProjectClientUpdateTest, self).setUp()
+
+ def test_update_success(self):
+ self.put_mock.return_value = fakes.FakeResponse()
+ self.project_client.update('def', self.project_json)
+ self.put_mock.assert_called_once_with(
+ self.base_url + '/def',
+ data=self.project_string,
+ headers=clientmanager.ClientManager.headers)
+
+ def test_update_failure(self):
+ with testtools.ExpectedException(Exception, 'Update failed: Error'):
+ self.put_mock.return_value = utils.FAKE_FAILURE
+ self.project_client.update('def', self.project_json)
diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_results_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_results_client.py
new file mode 100644
index 0000000..ae677f7
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/tests/unit/test_results_client.py
@@ -0,0 +1,78 @@
+import json
+
+from six.moves.urllib import parse
+import testtools
+
+from testapiclient.client import results
+from testapiclient.tests.unit import fakes
+from testapiclient.tests.unit import utils
+from testapiclient.utils import clientmanager
+
+
+class ResultClientTest(utils.TestCommand):
+ def setUp(self):
+ super(ResultClientTest, self).setUp()
+ self.base_url = parse.urljoin(self.api_url, 'results')
+ self.result_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.result_id = '5a6dc1089a07c80f3c9f8d62'
+ self.result_string = json.dumps(self.result_json)
+ self.result_client = results.ResultsClient()
+
+
+class ResultClientGetTest(ResultClientTest):
+
+ def setUp(self):
+ super(ResultClientGetTest, self).setUp()
+ self.results_rsp = {'results': [self.result_json]}
+
+ def test_get(self):
+ self.get_mock.return_value = fakes.FakeResponse(data=self.results_rsp)
+ self.result_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.results_rsp)
+ self.result_client.get(name='result1')
+ self.get_mock.assert_called_once_with(
+ self.base_url + '?name=result1',
+ headers=clientmanager.ClientManager.headers)
+
+ def test_get_one(self):
+ self.get_mock.return_value = fakes.FakeResponse(data=self.result_json)
+ self.result_client.get_one('2333')
+ self.get_mock.assert_called_once_with(
+ self.base_url + '/2333',
+ headers=clientmanager.ClientManager.headers)
+
+
+class ResultClientCreateTest(ResultClientTest):
+
+ def setUp(self):
+ super(ResultClientCreateTest, self).setUp()
+ self.succ_rsp = {
+ 'href': '{}/{}'.format(self.base_url, self.result_id)
+ }
+
+ def test_create_success(self):
+ self.post_mock.return_value = fakes.FakeResponse(data=self.succ_rsp)
+ self.result_client.create(self.result_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.result_client.create(self.result_json)