diff options
35 files changed, 3622 insertions, 94 deletions
diff --git a/reporting/reporting/bottlenecks/reporting-status.py b/reporting/reporting/bottlenecks/reporting-status.py index 225227a..8966d06 100644 --- a/reporting/reporting/bottlenecks/reporting-status.py +++ b/reporting/reporting/bottlenecks/reporting-status.py @@ -37,14 +37,10 @@ for version in VERSIONS: # For all the installers for installer in INSTALLERS: # get scenarios results data - if version != 'master': - new_version = "stable/{}".format(version) - else: - new_version = version scenario_results = rp_utils.getScenarios("bottlenecks", "posca_factor_ping", installer, - new_version) + version) LOGGER.info("scenario_results: %s", scenario_results) scenario_stats = rp_utils.getScenarioStats(scenario_results) diff --git a/testapi/docs/developer/devguide/testapi-client-import.rst b/testapi/docs/developer/devguide/testapi-client-import.rst new file mode 100644 index 0000000..c6d7311 --- /dev/null +++ b/testapi/docs/developer/devguide/testapi-client-import.rst @@ -0,0 +1,974 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. (c) 2017 ZTE Corp. + +===================== +TestAPI client import +===================== + +**Python module to communicate with the TestAPI Server** + +This project aims to provide a python module which can +communicate with the TestAPI Server. The user can use this client +to fetch/post/modify the resources on the TestAPI Server. + +Usage +----- + +Pod +^^^ + +GET +""" + +Get a list of all the declared pods from the TestAPI server. + +.. code-block:: shell + + from testapiclient.client import pods + + pod_client = pods.PodsClient() + pod_client.get() + +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 + + from testapiclient.client import pods + + pod_client = pods.PodsClient() + pod_client.get(name='pod1') + +.. NOTE:: + Response format: [{"_id": "", "creator": "", "role": "", "name": "", + "details": "", "mode": "", "creation_date": ""}] + + +GET ONE +""""""" + +Get a specific pod by its name. + +.. code-block:: shell + + from testapiclient.client import pods + + pod_client = pods.PodsClient() + pod_client.get_one('name') + +.. NOTE:: + Response format: {"_id": "", "creator": "", "role": "", "name": "", + "details": "", "mode": "", "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 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 + + from testapiclient.client import pods + + pod_client = pods.PodsClient(user='test', password='pass') + pod_client.create({'name': 'test-api', 'mode':'metal', + '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'}) + +DELETE +"""""" + +This method used to delete 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 delete. + +.. code-block:: shell + + from testapiclient.client import projects + + project_client = projects.ProjectsClient(user='test', password='pass') + project_client.delete('functest') + + +Testcase +^^^^^^^^ + +GET +""" + +Get a list of all the declared testcases under a project +from the TestAPI server. + +Input for the function : + + * project_name : Name of the project + +.. code-block:: shell + + from testapiclient.client import testcases + + testcase_client = testcases.TestcasesClient() + testcase_client.get(project_name='functest') + + +.. NOTE:: + Response format: [{ "project_name": "functest", "run": "", + "description": "", "tags": "", "creation_date": "", + "dependencies": "", "tier": "", "trust": "", "blocking": "", + "name": "", "ci_loop": "", "url": "", "version": "", + "criteria": "", "domains": "", "_id": "", "catalog_description": ""}] + +GET ONE +""""""" + +Get a specific testcase by its name and project name. + +.. code-block:: shell + + from testapiclient.client import testcases + + testcase_client = testcases.TestcasesClient() + testcase_client.get_one(project_name='functest', case_name='name') + +.. NOTE:: + Response format: { "project_name": "functest", "run": "", + "description": "", "tags": "", "creation_date": "", + "dependencies": "", "tier": "", "trust": "", "blocking": "", + "name": "", "ci_loop": "", "url": "", "version": "", + "criteria": "", "domains": "", "_id": "", "catalog_description": ""} + +CREATE +"""""" + +This method used to create a testcase on the server. +The user should provide the user parameter and the password +parameter while initiating the TestcasesClient. + +Input for the function : + * project_name : Project name + * testcase_json : Json object of the testcase + +.. NOTE:: + testcase_json schema - '{ "run": "", "description": "", "tags": "", + "dependencies": "", "tier": "", "trust": "", "blocking": "", + "name": "", "ci_loop": "", "url": "", "version": "", + "criteria": "", "domains": "", "catalog_description": ""}' + +.. code-block:: shell + + from testapiclient.client import testcases + + testcase_client = testcases.TestcasesClient(user='test', password='pass') + testcase_client.create(project_name, testcase_json) + +UPDATE +"""""" + +This method used to update an existing testcase on the server. +The user should provide the user parameter and the password +parameter while initiating the TestcasesClient. + +Input for the function : + * project_name : Project name + * testcase_name: name of the testcase which user want to update. + * testcase_json: Json object of the testcase + +.. NOTE:: + testcase-json schema - '{ "run": "", "description": "", "tags": "", + "dependencies": "", "tier": "", "trust": "", "blocking": "", + "name": "", "ci_loop": "", "url": "", "version": "", + "criteria": "", "domains": "", "catalog_description": ""}' + +.. code-block:: shell + + from testapiclient.client import testcases + + testcase_client = testcases.TestcasesClient(user='test', password='pass') + testcase_client.update(project_name, testcase_name, testcase_json) + +DELETE +"""""" + +This method used to delete an existing testcase on the server. +The user should provide the user parameter and the password +parameter while initiating the TestcasesClient. + +Input for the function : + + * project_name: name of the project + * testcase_name: name of the testcase which user want to delete. + +.. code-block:: shell + + from testapiclient.client import testcases + + testcase_client = testcases.TestcasesClient(user='test', password='pass') + testcase_client.delete(project_name, testcase_name) + + +Result +^^^^^^^ + +GET +""" + +Get a list of all the declared results from the TestAPI server. + +.. code-block:: shell + + from testapiclient.client import results + + result_client = results.ResultsClient() + result_client.get() + +User can filter the results by using some attributes. + +.. NOTE:: + List of search attributes. + + * case : Search results using tesetcase + * build-tag : Search results using build tag + * from : Search results using from date + * last : Search results using last date + * scenario : Search results using scenario + * period : Search results using period + * project : Search results using project + * to : Search results using to + * version : Search results using version + * criteria : Search results using criteria + * installer : Search results using installer + * pod : Search results using pod + * page : Search results using page + +.. code-block:: shell + + from testapiclient.client import results + + result_client = results.ResultsClient() + result_client.get(pod='pod1', project='project1') + + +.. NOTE:: + Response format: [{ "project_name": "", "scenario": "", + "stop_date": "", "case_name": "", "build_tag": "", + "version": "", "pod_name": "", "criteria": "", + "installer": "", "start_date": "", "details": ""}] + +GET ONE +""""""" + +Get a specific result by its id. + +.. code-block:: shell + + from testapiclient.client import results + + result_client = results.ResultsClient() + result_client.get_one(result_id) + +.. NOTE:: + Response format: { "project_name": "", "scenario": "", + "stop_date": "", "case_name": "", "build_tag": "", + "version": "", "pod_name": "", "criteria": "", + "installer": "", "start_date": "", "details": ""} + +CREATE +"""""" + +This method used to create a result on the server. +The user should provide a valid token to run this method. +Read testapi-client.rst to more details. + +Input for the function : + * result_json : Json object of the result + +.. NOTE:: + result_json schema - '{ "project_name": "", "scenario": "", + "stop_date": "", "case_name": "", "build_tag": "", + "version": "", "pod_name": "", "criteria": "", + "installer": "", "start_date": "", "details": ""}' + +.. code-block:: shell + + from testapiclient.client import results + + result_client = results.ResultsClient() + result_client.create(result_json) + +DeployResult +^^^^^^^^^^^^ + +GET +""" + +Get a list of all the declared deploy results from the TestAPI server. + +.. code-block:: shell + + from testapiclient.client import deploy_results + + deploy_result_client = deploy_results.DeployResultsClient() + deploy_result_client.get() + +User can filter the deploy results by using some attributes. + +.. NOTE:: + List of search attributes. + + * job-name : Search results using job + * build_id : Search results using build id + * from : Search results using from date + * last : Search results using last date + * scenario : Search results using scenario + * period : Search results using period + * to : Search results using to + * version : Search results using version + * criteria : Search results using criteria + * installer : Search results using installer + * pod_name : Search results using pod + * page : Search results using page + +.. code-block:: shell + + from testapiclient.client import deploy_results + + deploy_result_client = deploy_results.DeployResultsClient() + deploy_result_client.get(scenario='scenario1', installer='installer1') + + +.. NOTE:: + Response format: [{"build_id": "", "upstream_build_id": "", + "scenario": "", "stop_date": "", "start_date": "", + "upstream_job_name": "", "version": "", "pod_name": "", + "criteria": "", "installer": "", "_id": "", "job_name": "", + "details": ""}] + +GET ONE +""""""" + +Get a specific deploy result by its id. + +.. code-block:: shell + + from testapiclient.client import deploy_results + + deploy_result_client = deploy_results.DeployResultsClient() + deploy_result_client.get_one(deploy_result_id) + +.. NOTE:: + Response format: {"build_id": "", "upstream_build_id": "", + "scenario": "", "stop_date": "", "start_date": "", + "upstream_job_name": "", "version": "", "pod_name": "", + "criteria": "", "installer": "", "_id": "", "job_name": "", + "details": ""} + +CREATE +"""""" + +This method used to create a deploy_result on the server. +The user should provide a valid token to run this method. +Read testapi-client.rst to more details. + +Input for the function : + * deploy_result_json : Json object of the deploy_result + +.. NOTE:: + deploy_result_json schema - '{"build_id": "", "upstream_build_id": "", + "scenario": "", "stop_date": "", "start_date": "", + "upstream_job_name": "", "version": "", "pod_name": "", + "criteria": "", "installer": "", "job_name": "", + "details": ""}' + +.. code-block:: shell + + from testapiclient.client import deploy_results + + deploy_result_client = deploy_results.DeployResultsClient() + deploy_result_client.create(deploy_result_json) + +Scenario +^^^^^^^^ + +GET +""" + +Get a list of all the declared scenarios from the TestAPI server. + +.. code-block:: shell + + from testapiclient.client import scenarios + + scenario_client = scenarios.ScenariosClient() + scenario_client.get() + +User can filter the scenarios by using some attributes. + +.. NOTE:: + List of search attributes. + + * project : Search scenarios using project + * installer : Search scenarios using project + * version : Search scenarios using project + * name: Search scenarios using project + +.. code-block:: shell + + from testapiclient.client import scenarios + + scenario_client = scenarios.ScenariosClient() + scenario_client.get(name='scenario1') + +.. NOTE:: + Response format: [{ "installers": [], "_id": "", "creation_date": "", + "name": "", "creator": ""}] + +GET ONE +""""""" + +Get a specific scenario by its name. + +.. code-block:: shell + + from testapiclient.client import scenarios + + scenario_client = scenarios.ScenariosClient() + scenario_client.get_one('name') + +.. NOTE:: + Response format: { "installers": [], "_id": "", "creation_date": "", + "name": "", "creator": ""} + +CREATE +"""""" + +This method used to create a scenario on the server. +The user should provide the user parameter and the password +parameter while initiating the ScenariosClient. + +Input for the function : + + * scenario-json : Json object of the scenario + +.. NOTE:: + scenario_json schema - '{ "installers": [], + "name": ""}' + + See Installer for installer_schema + +.. code-block:: shell + + from testapiclient.client import scenarios + + scenario_client = scenarios.ScenariosClient(user='test', password='pass') + scenario_client.create(scenario_json) + +UPDATE +"""""" + +This method used to update the name of an existing scenario on the server. +The user should provide the user parameter and the password +parameter while initiating the ScenariosClient. + +Input for the function : + + * scenario-name: name of the scenario which user want to update. + * scenario-json: Json object of the scenario + +.. NOTE:: + * scenario_name + * scenario_update_json schema - '{"name": ""}' + +.. code-block:: shell + + from testapiclient.client import scenarios + + scenario_client = scenarios.ScenariosClient(user='test', password='pass') + scenario_client.update(scenario_name, scenario_update_json) + +DELETE +"""""" + +This method used to delete an existing scenario on the server. +The user should provide the user parameter and the password +parameter while initiating the ScenariosClient. + +Input for the function : + + * scenario_name: name of the scenario which user want to delete. + +.. code-block:: shell + + from testapiclient.client import scenarios + + scenario_client = scenarios.ScenariosClient(user='test', password='pass') + scenario_client.delete('scenario_name') + +Scenario Installer +^^^^^^^^^^^^^^^^^^ + +CREATE +"""""" + +This method used to create an installer under a scenario +on the server. The user should provide the user parameter +and the password parameter while initiating the InstallersClient. + +Input for the function : + * scenario_name + * installer-json : Json object of the installer + +.. NOTE:: + installer_json schema - '{ "versions": [], + "installer": ""}' + + See version for version_schema + +.. code-block:: shell + + from testapiclient.client import installers + + installer_client = installers.InstallersClient(user='test', password='pass') + installer_client.create(scenario_name, installer_json) + +UPDATE +"""""" + +This method used to update the all existing installers of a scenario +The user should provide the user parameter and the password +parameter while initiating the InstallersClient. + +Input for the function : + + * scenario_name + * installer-json: Json object of the installer + +.. NOTE:: + * scenario_name + * installer_json schema - [{ "versions": [], "installer": ""}] + +.. code-block:: shell + + from testapiclient.client import installers + + installer_client = installers.InstallersClient(user='test', password='pass') + installer_client.update(scenario_name, installer_update_json) + +DELETE +"""""" + +This method used to delete existing installers from a scenario. +on the server. +The user should provide the user parameter and the password +parameter while initiating the InstallersClient. + +Input for the function : + * scenario_name + * installer_names: names of the installer which user want to delete. + +.. code-block:: shell + + from testapiclient.client import installers + + installer_client = installers.InstallersClient(user='test', password='pass') + installer_client.delete(scenario_name, installer_names) + +Scenario Version +^^^^^^^^^^^^^^^^ + +CREATE +"""""" + +This method used to create a version under a scenario +on the server. The user should provide the user parameter +and the password parameter while initiating the VersionsClient. + +Input for the function : + + * scenario_name + * installer_name + * version-json : Json object of the version + +.. NOTE:: + version_json schema - '{ "projects": [], "owner": "", + "version": ""}' + + See version for version_schema + +.. code-block:: shell + + from testapiclient.client import versions + + version_client = versions.VersionsClient(user='test', password='pass') + version_client.create(scenario_name, installer_name, version_json) + +UPDATE +"""""" + +This method used to update the all existing versions of a scenario +The user should provide the user parameter and the password +parameter while initiating the VersionsClient. + +Input for the function : + + * scenario_name + * installer_name + * version-json: Json object of the version + +.. NOTE:: + * scenario_name + * version_json schema - [{ "projects": [], "owner": "", "version": ""}] + +.. code-block:: shell + + from testapiclient.client import versions + + version_client = versions.VersionsClient(user='test', password='pass') + version_client.update(scenario_name, installer_name, version_update_json) + +DELETE +"""""" + +This method used to delete existing versions from a scenario. +on the server. +The user should provide the user parameter and the password +parameter while initiating the VersionsClient. + +Input for the function : + * scenario_name + * installer_name + * version_names: names of the version which user want to delete. + +.. code-block:: shell + + from testapiclient.client import versions + + version_client = versions.VersionsClient(user='test', password='pass') + version_client.delete(scenario_name, installer_name, version_names) + +Scenario Project +^^^^^^^^^^^^^^^^ + +CREATE +"""""" + +This method used to create a project under a scenario +on the server. The user should provide the user parameter +and the password parameter while initiating the ProjectsClient. + +Input for the function : + + * scenario_name + * installer_name + * version_name + * project-json : Json object of the project + +.. NOTE:: + project_json schema - '{ "scores": [], "trust_indcators": [], + "customs": [], "project": ""}' + + See project for project_schema + +.. code-block:: shell + + from testapiclient.client import projects + + project_client = projects.ProjectsClient(user='test', password='pass') + project_client.create(scenario_name, installer_name, version_name, project_json) + +UPDATE +"""""" + +This method used to update the all existing projects of a scenario +The user should provide the user parameter and the password +parameter while initiating the ProjectsClient. + +Input for the function : + + * scenario_name + * installer_name + * version_name + * project-json: Json object of the project + +.. NOTE:: + * scenario_name + * project_json schema - [{"scores": [], "trust_indcators": [], "customs": [], "project": ""}] + +.. code-block:: shell + + from testapiclient.client import projects + + project_client = projects.ProjectsClient(user='test', password='pass') + project_client.update(scenario_name, installer_name, version_name, project_update_json) + +DELETE +"""""" + +This method used to delete existing projects from a scenario. +on the server. +The user should provide the user parameter and the password +parameter while initiating the ProjectsClient. + +Input for the function : + * scenario_name + * installer_name + * version_name + * project_names: names of the project which user want to delete. + +.. code-block:: shell + + from testapiclient.client import projects + + project_client = projects.ProjectsClient(user='test', password='pass') + project_client.delete(scenario_name, installer_name, version_name, project_names) + +Scenario Custom +^^^^^^^^^^^^^^^ + +CREATE +"""""" + +This method used to create a custom under a scenario +on the server. The user should provide the user parameter +and the password parameter while initiating the CustomsClient. + +Input for the function : + + * scenario_name + * installer_name + * version_name + * project_name + * custom : List of Customs + +.. NOTE:: + * scenario_name + * custom schema - ["List of Strings"] + + See custom for custom_schema + +.. code-block:: shell + + from testapiclient.client import customs + + custom_client = customs.CustomsClient(user='test', password='pass') + custom_client.create(scenario_name, installer_name, version_name, + project_name, custom_json) + +UPDATE +"""""" + +This method used to update the all existing customs of a scenario +The user should provide the user parameter and the password +parameter while initiating the CustomsClient. + +Input for the function : + + * scenario_name + * installer_name + * version_name + * project_name + * custom : List of Customs + +.. NOTE:: + * scenario_name + * custom schema - ["List of Strings"] + +.. code-block:: shell + + from testapiclient.client import customs + + custom_client = customs.CustomsClient(user='test', password='pass') + custom_client.update(scenario_name, installer_name, version_name, + project_name custom) + +DELETE +"""""" + +This method used to delete existing customs from a scenario. +on the server. +The user should provide the user parameter and the password +parameter while initiating the CustomsClient. + +Input for the function : + * scenario_name + * installer_name + * version_name + * project_name + * custom: custom which user want to delete. + +.. code-block:: shell + + from testapiclient.client import customs + + custom_client = customs.CustomsClient(user='test', password='pass') + custom_client.delete(scenario_name, installer_name, version_name, + project_name, customs) + +Scenario Scores +^^^^^^^^^^^^^^^ + +CREATE +"""""" + +This method used to create a score under a scenario +on the server. The user should provide the user parameter +and the password parameter while initiating the ScoresClient. + +Input for the function : + + * scenario_name + * installer_name + * version_name + * project_name + * score_json : Schema for the score + +.. NOTE:: + * scenario_name + * score_json schema - '{ "date": "", "score": ""}' + + See score for score_schema + +.. code-block:: shell + + from testapiclient.client import scores + + score_client = scores.ScoresClient(user='test', password='pass') + score_client.create(scenario_name, installer_name, version_name, + project_name, score_json) + +Scenario TrustIndicator +^^^^^^^^^^^^^^^^^^^^^^^ + +CREATE +"""""" + +This method used to create a trust indicator under a scenario +on the server. The user should provide the user parameter +and the password parameter while initiating the TrustIndicatorsClient. + +Input for the function : + + * scenario_name + * installer_name + * version_name + * project_name + * trust_indicator_json : Schema for the trust_indicator + +.. NOTE:: + * scenario_name + * trust_indicator_json schema - '{ "date": "", "status": ""}' + + See trust_indicator for trust_indicator_schema + +.. code-block:: shell + + from testapiclient.client import trust_indicators + + trust_indicator_client = trust_indicators.TrustIndicatorsClient(user='test', password='pass') + trust_indicator_client.create(scenario_name, installer_name, version_name, + project_name, trust_indicator_json)
\ No newline at end of file diff --git a/testapi/docs/developer/devguide/testapi-client.rst b/testapi/docs/developer/devguide/testapi-client.rst index ab4c8e8..5ba5df3 100644 --- a/testapi/docs/developer/devguide/testapi-client.rst +++ b/testapi/docs/developer/devguide/testapi-client.rst @@ -6,5 +6,859 @@ TestAPI client ============== -.. toctree:: - :maxdepth: 2 +TestAPIClient is a command-line client for TestAPI that +brings the command set for pod, project, testcase, results, +deploy result and scenario together in a single shell with a uniform command +structure. + + +Installation +------------ + +User can install this client from the source. + +.. code-block:: shell + + python install testapi/testapi-client/setup.py install + +After the installation, user has to set the environment variables + +.. code-block:: shell + + source testapi/testapi-client/etc/client.creds + + +Authentication Process +---------------------- + +User needs to provide the username and the password with the testapi +command. + +.. code-block:: shell + + $ testapi -u [username] -p [password] + (testapi) pod create + + +or + +.. code-block:: shell + + testapi pode create -u [username] -p [password] [pod-schema] + +First one, user can continue the progress after the authentication. +cli will create a new session to handle the request. + +In second one, cli won't create a session. one time command. + +Token is also used for the authorization purpose. User has to obtain the +valid token from the TestAPI comminity and set it in the following file +: **testapi/testapi-client/etc/client.creds** + +.. code-block:: shell + + source testapi/testapi-client/etc/client.creds + + +Command Structure +----------------- + +TestAPIClient follows a common command Structure. + +.. code-block:: shell + + testapi [resource-name] [function] [-u] [username] [-p] [password] + [command-arguments] + +.. NOTE:: + resource-name : include first order parent name and resource name. + + example: + scenario installer, scenario version, scenario project, scenario custom, + scenario trustindicator, scenario score, pod , project, testcase, result, + deployresult and scenario. + +.. NOTE:: + -u and -p are optional commands. The user can decide on them. + +There are many arguments for each commands. User can get them using +help command in the cli. + +.. code-block:: shell + + pod create --help/-h + +Pod +^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi pod create [-u] [username] [-p] [password] [pod-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) pod create [pod-schema] + +.. NOTE:: + pod-schema - '{"role": "", "name": "", "details": "", "mode": ""}' + +Get +""" + +Authentication is not required + +.. code-block:: shell + + testapi pod get [-name] [key-word] + +.. NOTE:: + -name is not mandatory. The user can use the -name option to reduce the + search result otherwise they will get the details about all pods. + +Get one +""""""" + +Authentication is not required + +.. code-block:: shell + + testapi pod getone [name-keyword] + +.. NOTE:: + name-keyword is mandatory. + + +Delete +"""""" + +Authentication is required + +.. code-block:: shell + + testapi pod delete [-u] [username] [-p] [password] [pod-name] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) pod delete [pod-name] + +.. NOTE:: + pod-name is mandatory. + + +Project +^^^^^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi project create [-u] [username] [-p] [password] [project-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) project create [project-schema] + +.. NOTE:: + project-schema - '{"description": "", "name": ""}' + + +Get +""" + +Authentication is not required + +.. code-block:: shell + + testapi project get [-name] [key-word] + +.. NOTE:: + -name is not mandatory. The user can use the -name option to reduce the + search result otherwise they will get the details about all projects. + +Get one +""""""" + +Authentication is not required + +.. code-block:: shell + + testapi project getone [name-keyword] + +.. NOTE:: + name-keyword is mandatory. + +Update +"""""" + +Authentication required + +.. code-block:: shell + + testapi project put [-u] [username] [-p] [password] [project-name] + [project-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) project put [project-name] [project-schema] + +.. NOTE:: + project-schema - '{"name": "", "description": ""}' + +Delete +"""""" + +Authentication is required + +.. code-block:: shell + + testapi project delete [-u] [username] [-p] [password] [project-name] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) project delete [project-name] + +.. NOTE:: + project-name is mandatory. + +Testcase +^^^^^^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi testcase create [-u] [username] [-p] [password] + [--project-name] [testcase-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) testcase create [--project-name] [testcase-schema] + +.. NOTE:: + testcase-schema - '{"run": "", "name": "", "ci_loop": "", "tags": "", + "url": "", "catalog_description": "", "tier": "", + "dependencies": "", "version": "", "criteria": "", + "domains": "", "trust": "", "blocking": "", + "description": ""}' + + +Get +""" + +Authentication is not required + +.. code-block:: shell + + testapi testcase get [--project-name] + +.. NOTE:: + --project-name is mandatory. + +Get one +""""""" + +Authentication is not required + +.. code-block:: shell + + testapi testcase getone [--project-name] [name] + +.. NOTE:: + name and project-name are mandatory. + +Update +"""""" + +Authentication required + +.. code-block:: shell + + testapi testcase put [-u] [username] [-p] [password] [--project-name] + [name] [testcase-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) testcase put [--project-name] [name] [testcase-schema] + +.. NOTE:: + testcase-schema - '{"run": "", "name": "", "ci_loop": "", "tags": "", + "url": "", "catalog_description": "", "tier": "", + "dependencies": "", "version": "", "criteria": "", + "domains": "", "trust": "", "blocking": "", + "description": ""} + + +Result +^^^^^^^ + +Create +"""""" + +Token is required. Set token as an environment variable. + +.. code-block:: shell + + testapi result create [-u] [username] [-p] [password] [result-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) result create [result-schema] + +.. NOTE:: + result-schema - '{"project_name": "", "scenario": "", "stop_date": "", + "case_name": "", "build_tag": "", "version": "", + "pod_name": "", "criteria": "", "installer": "", + "start_date": "", "details": ""}' + + +Get +""" + +Authentication is not required + +.. code-block:: shell + + testapi result get [-cli-arguments] [arguments-value] + +.. NOTE:: + List of commandline arguments + + * -case : Search results using tesetcase + * -build-tag : Search results using build tag + * -from : Search results using from date + * -last : Search results using last date + * -scenario : Search results using scenario + * -period : Search results using period + * -project : Search results using project + * -to : Search results using to + * ---version : Search results using version + * -criteria : Search results using criteria + * -installer : Search results using installer + * -pod : Search results using pod + * -page : Search results using page + +Get one +""""""" + +Token is required. Set token as an environment variable. + +.. code-block:: shell + + testapi result getone [result_id] + +.. NOTE:: + result_id is mandatory. + +Deploy Result +^^^^^^^^^^^^^ + +Create +"""""" + +Token is required. Set token as an environment variable. + + +.. code-block:: shell + + testapi deployresult [-u] [username] [-p] [password] + [--project-name] [deployresult-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) deployresult create [deployresult-schema] + +.. NOTE:: + deployresult-schema - '{"run": "", "name": "", "ci_loop": "", "tags": "", + "url": "", "catalog_description": "", "tier": "", + "dependencies": "", "version": "", "criteria": "", + "domains": "", "trust": "", "blocking": "", + "description": ""}' + + +Get +""" + +Authentication is not required + +.. code-block:: shell + + testapi deployresult get [-cli-arguments] [arguments-value] + +.. NOTE:: + List of command line arguments + + * -job-name : Search results using job + * -build-id : Search results using build id + * -from : Search results using from date + * -last : Search results using last date + * -scenario : Search results using scenario + * -period : Search results using period + * -to : Search results using to + * ---version : Search results using version + * -criteria : Search results using criteria + * -installer : Search results using installer + * -pod-name : Search results using pod + * -page : Search results using page + +Get one +""""""" + +Authentication is not required + +.. code-block:: shell + + testapi deployresult getone [deployresult_id] + +.. NOTE:: + deployresult_id is mandatory. + + +Scenario +^^^^^^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario create [-u] [username] [-p] [password] [scenario-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario create [scenario-schema] + +.. NOTE:: + scenario-schema - '{"name": "", "installers": []}' + + +Get +""" + +Authentication is not required + +.. code-block:: shell + + testapi scenario get [-name] [key-word] + +.. NOTE:: + + user can use some attributes to reduce the search results. These are not + mandatory. + + * -name : Backend will use regular expression to search. + * -project : Search using project name + * -installer : Search using installer name + * -version : Search using version name + +Get one +""""""" + +Authentication is not required + +.. code-block:: shell + + testapi scenario getone [name-keyword] + +.. NOTE:: + name-keyword is mandatory. + +Update +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario put [-u] [username] [-p] [password] [scenario-name] + [scenario-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario put [scenario-name] [scenario-schema] + +.. NOTE:: + scenario-schema - '{"name": "", "installers": []}' + +Delete +"""""" + +Authentication is required + +.. code-block:: shell + + testapi scenario delete [-u] [username] [-p] [password] [scenario-name] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario delete [scenario-name] + +.. NOTE:: + scenario-name is mandatory. + +Scenario installer +^^^^^^^^^^^^^^^^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario installer create [-u] [username] [-p] [password] + --scenario-name [scenario-name] [installer-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario installer create --scenario-name [scenario-name] + [installer-schema] + +.. NOTE:: + installer-schema - '{"installer": "", "versions": []}' + +Update +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario installer put [-u] [username] [-p] [password] + --scenario-name [scenario-name] [installer-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario put --scenario-name [scenario-name] [installer-schema] + +.. NOTE:: + scenario-schema - '{"installer": "", "installers": []}' + +Delete +"""""" + +Authentication is required + +.. code-block:: shell + + testapi scenario delete [-u] [username] [-p] [password] --scenario-name + [scenario-name] [name] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario delete --scenario-name [scenario-name] [name] + +Scenario version +^^^^^^^^^^^^^^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario version create [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] [version-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario installer create --scenario-name [scenario-name] + --installer [installer] [version-schema] + +.. NOTE:: + installer-schema - '{"version": "", "owner": "", "projects": []}' + +Update +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario installer put [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] [version-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario installer put --scenario-name [scenario-name] + --installer [installer] [installer-schema] + +.. NOTE:: + scenario-schema - '{"version": "","owner": "", "projects": []}' + +Delete +"""""" + +Authentication is required + +.. code-block:: shell + + testapi scenario installer delete [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] [name] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario installer delete --scenario-name [scenario-name] + --installer [installer] [name] + +Scenario Project +^^^^^^^^^^^^^^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario project create [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] + ---version [version] [project-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario project create --scenario-name [scenario-name] + --installer [installer] ---version [version] [project-schema] + +.. NOTE:: + installer-schema - '{"scores": [],"customs": [], "trust_indicators": [], + project:""}' + +Update +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario project put [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] ---version + [version] [project-schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario project put --scenario-name [scenario-name] --installer + [installer] ---version [version] [project-schema] + +.. NOTE:: + scenario-schema - '{"scores": [],"customs": [], "trust_indicators": [], + project:""}' + +Delete +"""""" + +Authentication is required + +.. code-block:: shell + + testapi scenario project delete [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] ---version + [version] [name] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario project delete --scenario-name [scenario-name] + --installer [installer] ---version [version] [name] + +Scenario Customs +^^^^^^^^^^^^^^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario custom create [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] + ---version [version] --project [project] [customs] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario custom create --scenario-name [scenario-name] + --installer [installer] ---version [version] --project [project] [customs] + +.. NOTE:: + + customs : Space sperated strings + +Update +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario custom put [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] ---version + [version] --project [project] [customs] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario custom put --scenario-name [scenario-name] --installer + [installer] ---version [version] --project [project] [customs] + +.. NOTE:: + + customs : Space sperated strings + +Delete +"""""" + +Authentication is required + +.. code-block:: shell + + testapi scenario custom delete [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] ---version + [version] --project [project] [customs] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario custom delete --scenario-name [scenario-name] + --installer [installer] ---version [version] --project [project] + [customs] + +.. NOTE:: + + customs : Space sperated strings + +Scenario Score +^^^^^^^^^^^^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario score create [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] + ---version [version] --project [project] [score_schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario score create --scenario-name [scenario-name] + --installer [installer] ---version [version] --project [project] + [score_schema] + +.. NOTE:: + + score_schema : '{"score": "", "date": ""}' + +Scenario TrustIndicators +^^^^^^^^^^^^^^^^^^^^^^^^ + +Create +"""""" + +Authentication required + +.. code-block:: shell + + testapi scenario trustindicator create [-u] [username] [-p] [password] + --scenario-name [scenario-name] --installer [installer] + ---version [version] --project [project] [trustindicator_schema] + +or + +.. code-block:: shell + + $ testapi [-u] [username] [-p] [password] + (testapi) scenario trustindicator create --scenario-name [scenario-name] + --installer [installer] ---version [version] --project [project] + [trustindicator_schema] + +.. NOTE:: + + trustindicator_schema : '{"status": "", "date": ""}'
\ No newline at end of file diff --git a/testapi/docs/internship/webportal.rst b/testapi/docs/internship/webportal.rst new file mode 100644 index 0000000..1ea9c19 --- /dev/null +++ b/testapi/docs/internship/webportal.rst @@ -0,0 +1,169 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 + + +***************************** +Web Portal for OPNFV Test API +***************************** + +Author: Tharmarajasingam Thuvarakan Mentors: S. Feng, J.Lausuch, M.Richomme + +Abstract +======== + +TestAPI is used by all the test projects to report results. It is also used to declare projects, +test cases and labs. It is defined in the Functest developer guide. The internship aims to add web +portal for TestAPI. The showcase user got through the web portal, will be more human-friendly +compared to the swagger page. Also, internship aims to build a python client to reduce the workload. +Python client can be used as a python module. + +Overview +======== + +The internship time period was from Oct 9th to May 18th. The project proposal page is here [1]_. +The intern project was assigned to Thuvarakan and was mentored by S. Feng, J.Lausuch, M.Richomme. +The link to the patches submitted is [2]_. The internship was successfully completed and the +documentation is as follows. + + + +Problem Statement +================= + +The following were to be accomplished within the internship time frame. + +* Redesign the website theme + + Change the existing theme of the frontend and design a unified theme. + +* Add separate pages to each resource + + Create a separate web page for each resource in the new theme. + +* Implement all the functionalities in the frontend + + Implement the backend functionalities in the frontend for each + resource. + +* Authentication for testapiclient + + Implement the authentication functionality in the testapiclient. + +* Add all functionalities to testapiclient + + Implement the backend functionalities in the testapiclient for each + resource. + +* Add support to testapiclient as a python module + + Convert the testapiclient from CLI only to CLI and python module + mode. + + +Curation Phase +============== + +The curation phase was the first 4 to 8 weeks of the internship. This phase +was to get familiar with the testapi code and functionality and propose the +solutions/tools for the tasks mentioned above. + +These are the tools, we proposed for the solutions. + +* protractor: An end-to-end test framework for Angular and AngularJS applications + +* grunt: A Javascript task runner, a tool used to automatically perform + frequent tasks such as minification, compilation, unit testing, and + linting. + +* cliff: Command Line Interface Formulation Framework. + + +Schedule +======== + +=================== ======================================================== + Date Comment +=================== ======================================================== +10th Oct ~17th Oct Setting up the development environment, design decisions +17th Oct ~ 24th Oct Pod web portal CRUD +24th Oct ~ 31st Oct Projects web portal CRUD +13st Oct ~ 7th Nov Test cases web portal CRUD +7th Nov ~ 14th Nov Results web portal R +14th Nov ~ 21st Nov Results web portal R +21st Nov ~ 28th Nov Scenario web portal CRUD +28th Nov ~ 5th Dec Testapi-client framework +5th Dec ~ 12nd Dec Pods testapi-client CRUD +12nd Dec ~ 19th Dec Projects testapi-client CRUD +19th Dec ~ 26th Dec Test cases testapi-client CRUD +26th Dec ~ 9th Jan Results testapi-client CRUD +9th Jan ~ 23rd Jan Scenario testapi-client CRUD +23rd Jan ~ 6th Mar Bugfix in the frontend and testapiclient +6th Mar ~ 20th Mar Convert testapiclient to python module +20th Mar ~ 3rd Apr Testing the python module +3rd Apr ~ 9th May Documentation & Bugfix +=================== ======================================================== + + +FAQ +=== + + +Frontend +******** + +1. How to add a new test file for the frontend? + + * Frontend test is handled by protractor [3]_ and + automated by the grunt [4]_. All the tests are located in + "opnfv_testapi/tests/UI/e2e". + First, create a text file in the e2e folder. Then add it to the spec + list in the "opnfv_testapi/ui/Gruntfile.js". + + +2. How to test application's functionalities interactively? + + * Application requires authentication for many functionalities. + It will cause time for the developer to check the functionalities. + Developers can use the application in the authentication false mode. + To do that, first, change the authenticate to false in the + "etc/config.ini" file then change the authenticate to false in + the "opnfv_testapi/ui/config.json" file. + + +3. Browser does not reflect the code changes, what is it mean? + + * Browser is saving the caches for fast reloadings. Sometime browser + won't reload the new changes, to solve that we have to clear the browser + caches. + + +Testapiclient +************* + +1. How to add a new test file for testapiclient? + + * Frontend test is handled by testtools [5]_ and automated by tox [6]_. + All the tests are located in "testapi-client/tests/unit". Create a text + file in the unit folder. The name of the test file should start with + 'test\_'. It will automatically add that test file to queue. + + +2. Difference between client and cli? + + * Client is used to importing testapiclient as a python module. + The cli folder contained the command line interface for the testapiclient. + +References +========== + +.. [1] https://wiki.opnfv.org/display/DEV/Intern+Project%3A+Web+Portal+for+OPNFV+Test+API + +.. [2] https://gerrit.opnfv.org/gerrit/#/q/status:merged+owner:%22Thuvarakan+Tharmarajasingam+%253Ctharma.thuva%2540gmail.com%253E%22 + +.. [3] https://www.protractortest.org/ + +.. [4] https://gruntjs.com + +.. [5] https://github.com/testing-cabal/testtools + +.. [6] https://tox.readthedocs.io/en/latest/#
\ No newline at end of file diff --git a/testapi/test-requirements.txt b/testapi/test-requirements.txt index 233f465..17be7ea 100644 --- a/testapi/test-requirements.txt +++ b/testapi/test-requirements.txt @@ -8,3 +8,4 @@ nose # LGPL pytest # MIT pytest-cov # MIT pytest-mock # MIT +futures diff --git a/testapi/testapi-client/testapiclient/cli/deployresults.py b/testapi/testapi-client/testapiclient/cli/deployresults.py index a6fe13e..1ca0bef 100644 --- a/testapi/testapi-client/testapiclient/cli/deployresults.py +++ b/testapi/testapi-client/testapiclient/cli/deployresults.py @@ -2,6 +2,7 @@ import json from testapiclient.utils import command from testapiclient.utils import urlparse +from testapiclient.models import deployresult def deployresults_url(): @@ -85,13 +86,10 @@ class DeployresultCreate(command.ShowOne): parser.add_argument('deployresult', type=json.loads, help='Deployresult create request format:\n' - '\'{"job_name" : "","scenario" : "",' - '"stop_date" : "", "build_id" : "",' - '"upstream_job_name": "",' - '"version" : "", "pod_name" : "",' - '"criteria" : "", "installer" : "",' - '"upstream_build_id" : "",' - '"start_date" : "", "details" : ""}\'') + '\'{}\''.format(json.dumps( + deployresult.DeployResultCreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): diff --git a/testapi/testapi-client/testapiclient/cli/pods.py b/testapi/testapi-client/testapiclient/cli/pods.py index df63737..a7706f6 100644 --- a/testapi/testapi-client/testapiclient/cli/pods.py +++ b/testapi/testapi-client/testapiclient/cli/pods.py @@ -3,6 +3,7 @@ import json from testapiclient.client import pods from testapiclient.utils import command from testapiclient.utils import urlparse +from testapiclient.models import pods as pm def pods_url(): @@ -61,8 +62,10 @@ class PodCreate(command.ShowOne): parser.add_argument('pod', type=json.loads, help='Pod create request format :\n' - '\'{"role": "", "name": "", "details": "", ' - '"mode": ""}\',\n role should be either ' + '\'{}\''.format(json.dumps( + pm.PodCreateRequest().__dict__ + )) + + '\n role should be either ' '"community-ci" or "production-ci", and ' 'mode should be either "metal" or "virtual.') return parser diff --git a/testapi/testapi-client/testapiclient/cli/projects.py b/testapi/testapi-client/testapiclient/cli/projects.py index 510acc8..2fa5b5b 100644 --- a/testapi/testapi-client/testapiclient/cli/projects.py +++ b/testapi/testapi-client/testapiclient/cli/projects.py @@ -2,6 +2,7 @@ import json from testapiclient.utils import command from testapiclient.utils import urlparse +from testapiclient.models import project def projects_url(): @@ -51,9 +52,10 @@ class ProjectCreate(command.ShowOne): parser = super(ProjectCreate, self).get_parser(prog_name) parser.add_argument('project', type=json.loads, - help='Project create request format :{' - ' "name": (required)"", ' - '"description": (optional)""}') + help='Project create request format :\n' + '\'{}\''.format(json.dumps( + project.ProjectCreateRequest().__dict__ + ))) return parser def take_action(self, parsed_args): @@ -83,9 +85,10 @@ class ProjectPut(command.ShowOne): help='Update project by name') parser.add_argument('project', type=json.loads, - help='Project Update request format :{' - '"name": (required)"", ' - '"description": (optional)""}') + help='Project Update request format :\n' + '\'{}\''.format(json.dumps( + project.ProjectCreateRequest().__dict__ + ))) return parser def take_action(self, parsed_args): diff --git a/testapi/testapi-client/testapiclient/cli/results.py b/testapi/testapi-client/testapiclient/cli/results.py index 56ea71f..5500501 100644 --- a/testapi/testapi-client/testapiclient/cli/results.py +++ b/testapi/testapi-client/testapiclient/cli/results.py @@ -2,6 +2,7 @@ import json from testapiclient.utils import command from testapiclient.utils import urlparse +from testapiclient.models import result def results_url(): @@ -86,12 +87,8 @@ class ResultCreate(command.ShowOne): parser.add_argument('result', type=json.loads, help='Result create request format:\n' - '\'{"project_name" : "","scenario" : "",' - '"stop_date" : "", "case_name" : "",' - '"build_tag" : "", "version" : "",' - '"pod_name" : "" , "criteria" : "",' - '"installer" : "", "start_date" : "",' - '"details" : ""}\'') + '\'{}\''.format(json.dumps( + result.ResultCreateRequest().__dict__))) return parser def take_action(self, parsed_args): diff --git a/testapi/testapi-client/testapiclient/cli/scenarios.py b/testapi/testapi-client/testapiclient/cli/scenarios.py index 507705a..197ee0c 100644 --- a/testapi/testapi-client/testapiclient/cli/scenarios.py +++ b/testapi/testapi-client/testapiclient/cli/scenarios.py @@ -2,6 +2,7 @@ import json from testapiclient.utils import command from testapiclient.utils import urlparse +from testapiclient.models import scenario def scenarios_url(): @@ -64,22 +65,37 @@ class ScenarioCreate(command.ShowOne): parser.add_argument('scenario', type=json.loads, help='Scenario create request format :\n' - '\'{ "installers": [], "name": ""}\',\n' - 'Intaller create request format :\n' - '\'{"installer": "","versions": []}\',\n' - 'Version create request format :\n' - '\'{"owner": "","version": "",' - '"projects": []}\',\n' - 'Project create request format :\n' - '\'{"project": "","customs": [],' - '"scores": [],' - '"trust_indicators": []}\',\n' - 'Custom create request format :\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioCreateRequest( + ).__dict__ + )) + + '\n Intaller create request format :\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioInstallerCreateRequest( + ).__dict__ + )) + + '\n Version create request format :\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioVersionCreateRequest( + ).__dict__ + )) + + '\n Project create request format :\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioProjectCreateRequest( + ).__dict__ + )) + + '\n Custom create request format :\n' '\'["asf","saf"]\',\n' - 'Score create request format :\n' - '\'{"date": "", "score": ""}\',\n' - 'Trust Indicators create request format :\n' - '\'{"date": "", "status": ""}\'') + '\n Score create request format :\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioScoreCreateRequest( + ).__dict__ + )) + + '\nTrustIndicator create request format:\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioTICreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): @@ -110,23 +126,38 @@ class ScenarioPut(command.ShowOne): help='Update scenario by name') parser.add_argument('scenario', type=json.loads, - help='Scenario create request format :\n' - '\'{ "installers": [], "name": ""}\',\n' - 'Intaller create request format :\n' - '\'{"installer": "","versions": []}\',\n' - 'Version create request format :\n' - '\'{"owner": "","version": "",' - '"projects": []}\',\n' - 'Project create request format :\n' - '\'{"project": "","customs": [],' - '"scores": [],' - '"trust_indicators": []}\',\n' - 'Custom create request format :\n' + help='Scenario create request format :\n' + + '\'{}\''.format(json.dumps( + scenario.ScenarioCreateRequest( + ).__dict__ + )) + + '\n Intaller create request format :\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioInstallerCreateRequest( + ).__dict__ + )) + + '\n Version create request format :\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioVersionCreateRequest( + ).__dict__ + )) + + '\n Project create request format :\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioProjectCreateRequest( + ).__dict__ + )) + + '\n Custom create request format :\n' '\'["asf","saf"]\',\n' - 'Score create request format :\n' - '\'{"date": "", "score": ""}\',\n' - 'Trust Indicators create request format :\n' - '\'{"date": "", "status": ""}\'') + '\n Score create request format :\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioScoreCreateRequest( + ).__dict__ + )) + + '\nTrustIndicator create request format:\n' + '\'{}\''.format(json.dumps( + scenario.ScenarioTICreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): @@ -145,7 +176,10 @@ class InstallerCreate(command.Command): parser.add_argument('installer', type=json.loads, help='Intaller create request format :\n' - '\'[{"installer": "","versions": []}]\',\n') + '\'{}\''.format(json.dumps( + scenario.ScenarioInstallerCreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): @@ -186,7 +220,10 @@ class InstallerPut(command.Command): parser.add_argument('installer', type=json.loads, help='Intaller create request format :\n' - '\'[{"installer": "","versions": []}]\',\n') + '\'{}\''.format(json.dumps( + scenario.ScenarioInstallerCreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): @@ -209,10 +246,10 @@ class VersionCreate(command.Command): parser.add_argument('version', type=json.loads, help='version create request format :\n' - '\'[{"owner":(string),' - '"version": (string),' - '"projects": (array[ScenarioProject])' - '}]\',\n') + '\'{}\''.format(json.dumps( + scenario.ScenarioVersionCreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): @@ -261,10 +298,10 @@ class VersionPut(command.Command): parser.add_argument('version', type=json.loads, help='version update request format :\n' - '\'[{"owner":(string),' - '"version": (string),' - '"projects": (array[ScenarioProject])' - '}]\',\n') + '\'{}\''.format(json.dumps( + scenario.ScenarioVersionCreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): @@ -320,10 +357,10 @@ class ProjectCreate(command.Command): parser.add_argument('project', type=json.loads, help='Project create request format :\n' - '\'[{ "project" (string),' - '"scores": (array[ScenarioScore]),' - '"trust_indicators": (array[ScenarioTI]),' - '"customs": (array[string]) }]\',\n') + '\'{}\''.format(json.dumps( + scenario.ScenarioProjectCreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): @@ -378,10 +415,10 @@ class ProjectPut(command.Command): parser.add_argument('project', type=json.loads, help='Project update request format :\n' - '\'[{ "project" (string),' - '"scores": (array[ScenarioScore]),' - '"trust_indicators": (array[ScenarioTI]),' - '"customs": (array[string]) }]\',\n') + '\'{}\''.format(json.dumps( + scenario.ScenarioProjectCreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): @@ -511,8 +548,10 @@ class TrustIndicatorCreate(command.Command): parser.add_argument('trust_indicator', type=json.loads, help='trust indicator create request format :\n' - '\'{ "date": (string, optional),' - '"status": (string, optional) }\',\n') + '\'{}\''.format(json.dumps( + scenario.ScenarioTICreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): @@ -547,8 +586,10 @@ class ScoreCreate(command.Command): parser.add_argument('score', type=json.loads, help='score create request format :\n' - '\'{ "date": (string, optional),' - '"score" : (string, optional) }\',\n') + '\'{}\''.format(json.dumps( + scenario.ScenarioScoreCreateRequest( + ).__dict__ + ))) return parser def take_action(self, parsed_args): diff --git a/testapi/testapi-client/testapiclient/cli/testcases.py b/testapi/testapi-client/testapiclient/cli/testcases.py index 6c97edb..3052c18 100644 --- a/testapi/testapi-client/testapiclient/cli/testcases.py +++ b/testapi/testapi-client/testapiclient/cli/testcases.py @@ -2,6 +2,7 @@ import json from testapiclient.utils import command from testapiclient.utils import urlparse +from testapiclient.models import testcase def testcases_url(name): @@ -60,12 +61,9 @@ class TestcaseCreate(command.ShowOne): parser.add_argument('testcase', type=json.loads, help='Testcase create request format:\n' - '\'{"run": "", "name": "", "ci_loop": "",' - '"tags": "",\n "url": "", "blocking": "",' - '"domains": "", "dependencies": "",\n ' - '"version": "", "criteria": "", "tier": "",' - '"trust": "",\n "catalog_description": "",' - '"description": ""}\'') + '\'{}\''.format(json.dumps( + testcase.TestCaseCreateRequest().__dict__ + ))) return parser def take_action(self, parsed_args): @@ -105,12 +103,9 @@ class TestcasePut(command.ShowOne): parser.add_argument('testcase', type=json.loads, help='Testcase Update request format:\n' - '\'{"run": "", "name": "", "ci_loop": "",' - '"tags": "",\n "url": "", "blocking": "",' - '"domains": "", "dependencies": "",\n ' - '"version": "", "criteria": "", "tier": "",' - '"trust": "",\n "catalog_description": "",' - '"description": ""}\'') + '\'{}\''.format(json.dumps( + testcase.TestCaseCreateRequest().__dict__ + ))) return parser def take_action(self, parsed_args): 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/pods.py b/testapi/testapi-client/testapiclient/client/pods.py index 4254da7..d08114f 100644 --- a/testapi/testapi-client/testapiclient/client/pods.py +++ b/testapi/testapi-client/testapiclient/client/pods.py @@ -1,4 +1,7 @@ +import json + from testapiclient.client import base +from testapiclient.utils import urlparse class PodsClient(base.Client): @@ -9,3 +12,20 @@ class PodsClient(base.Client): def create(self, pod_req): return self.clientmanager.post(self.url, pod_req) + + def get(self, **queries): + if queries: + return json.dumps( + self.clientmanager.get( + urlparse.query_join(self.url, **queries))['pods']) + else: + return json.dumps( + self.clientmanager.get(self.url)['pods']) + + 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)) 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/client/scenarios.py b/testapi/testapi-client/testapiclient/client/scenarios.py new file mode 100644 index 0000000..e5ce2f1 --- /dev/null +++ b/testapi/testapi-client/testapiclient/client/scenarios.py @@ -0,0 +1,177 @@ +import json + +from testapiclient.client import base +from testapiclient.utils import urlparse + + +class ScenariosClient(base.Client): + resource = 'scenarios' + + def __init__(self, **kwargs): + super(ScenariosClient, self).__init__(**kwargs) + + def create(self, scenario_req): + return self.clientmanager.post(self.url, scenario_req) + + def get(self, **queries): + if queries: + return json.dumps( + self.clientmanager.get( + urlparse.query_join(self.url, **queries))['scenarios']) + else: + return json.dumps( + self.clientmanager.get(self.url)['scenarios']) + + def get_one(self, scenario_name): + return json.dumps( + self.clientmanager.get( + urlparse.path_join( + self.url, scenario_name))) + + def delete(self, scenario_name): + return self.clientmanager.delete( + urlparse.path_join( + self.url, scenario_name)) + + def update(self, scenario_name, scenario_req): + return self.clientmanager.put( + urlparse.path_join( + self.url, scenario_name), scenario_req) + + +class InstallersClient(base.Client): + resource = 'scenarios/{}/installers' + + def __init__(self, **kwargs): + super(InstallersClient, self).__init__(**kwargs) + + def delete(self, scenario_name, name): + return self.clientmanager.delete( + self.url.format(scenario_name), [name]) + + def update(self, scenario_name, installer_req): + return self.clientmanager.put( + self.url.format(scenario_name), installer_req) + + def create(self, scenario_name, installer_req): + return self.clientmanager.post( + self.url.format(scenario_name), installer_req) + + +class VersionsClient(base.Client): + resource = 'scenarios/{}/versions' + + def __init__(self, **kwargs): + super(VersionsClient, self).__init__(**kwargs) + + def delete(self, scenario_name, installer, name): + queries = {'installer': installer} + return self.clientmanager.delete( + urlparse.query_join( + self.url.format(scenario_name), **queries), name) + + def update(self, scenario_name, installer, version_req): + queries = {'installer': installer} + return self.clientmanager.put( + urlparse.query_join( + self.url.format(scenario_name), **queries), version_req) + + def create(self, scenario_name, installer, version_req): + queries = {'installer': installer} + return self.clientmanager.post( + urlparse.query_join( + self.url.format(scenario_name), **queries), version_req) + + +class VersionsOwnerClient(base.Client): + resource = 'scenarios/{}/owner' + + def __init__(self, **kwargs): + super(VersionsOwnerClient, self).__init__(**kwargs) + + def update(self, scenario_name, installer, version, owner): + queries = {'installer': installer, 'version': version} + return self.clientmanager.put( + urlparse.query_join( + self.url.format(scenario_name), **queries), owner) + + +class ProjectsClient(base.Client): + resource = 'scenarios/{}/projects' + + def __init__(self, **kwargs): + super(ProjectsClient, self).__init__(**kwargs) + + def delete(self, scenario_name, installer, version, name): + queries = {'installer': installer, 'version': version} + return self.clientmanager.delete( + urlparse.query_join( + self.url.format(scenario_name), **queries), name) + + def update(self, scenario_name, installer, version, project_req): + queries = {'installer': installer, 'version': version} + return self.clientmanager.put( + urlparse.query_join( + self.url.format(scenario_name), **queries), project_req) + + def create(self, scenario_name, installer, version, project_req): + queries = {'installer': installer, 'version': version} + return self.clientmanager.post( + urlparse.query_join( + self.url.format(scenario_name), **queries), project_req) + + +class TrustIndicatorsClient(base.Client): + resource = 'scenarios/{}/trust_indicators' + + def __init__(self, **kwargs): + super(TrustIndicatorsClient, self).__init__(**kwargs) + + def create(self, scenario_name, installer, version, project, trust_in_req): + queries = { + 'installer': installer, 'version': version, 'project': project} + return self.clientmanager.post( + urlparse.query_join( + self.url.format(scenario_name), **queries), trust_in_req) + + +class ScoresClient(base.Client): + resource = 'scenarios/{}/scores' + + def __init__(self, **kwargs): + super(ScoresClient, self).__init__(**kwargs) + + def create(self, scenario_name, installer, version, project, scores_req): + queries = { + 'installer': installer, 'version': version, 'project': project} + return self.clientmanager.post( + urlparse.query_join( + self.url.format(scenario_name), **queries), scores_req) + + +class CustomsClient(base.Client): + resource = 'scenarios/{}/customs' + + def __init__(self, **kwargs): + super(CustomsClient, self).__init__(**kwargs) + + def delete(self, scenario_name, installer, version, project, customs): + queries = { + 'installer': installer, 'version': version, 'project': project} + return self.clientmanager.delete( + urlparse.query_join( + self.url.format(scenario_name), **queries), customs) + + def update(self, scenario_name, installer, version, project, customs): + queries = { + 'installer': installer, 'version': version, 'project': project} + return self.clientmanager.put( + urlparse.query_join( + self.url.format(scenario_name), **queries), customs) + + def create(self, scenario_name, installer, version, project, customs): + queries = { + 'installer': installer, 'version': version, 'project': project} + return self.clientmanager.post( + urlparse.query_join( + self.url.format(scenario_name), **queries), customs) diff --git a/testapi/testapi-client/testapiclient/client/testcases.py b/testapi/testapi-client/testapiclient/client/testcases.py new file mode 100644 index 0000000..bb2b6d3 --- /dev/null +++ b/testapi/testapi-client/testapiclient/client/testcases.py @@ -0,0 +1,36 @@ +import json + +from testapiclient.client import base +from testapiclient.utils import urlparse + + +class TestcasesClient(base.Client): + resource = 'projects/{}/cases' + + def __init__(self, **kwargs): + super(TestcasesClient, self).__init__(**kwargs) + + def create(self, project_name, testcase_req): + return self.clientmanager.post( + self.url.format(project_name), testcase_req) + + def get(self, project_name): + return json.dumps( + self.clientmanager.get( + self.url.format(project_name))['testcases']) + + def get_one(self, project_name, name): + return json.dumps( + self.clientmanager.get( + urlparse.path_join( + self.url.format(project_name), name))) + + def delete(self, project_name, name): + return self.clientmanager.delete( + urlparse.path_join( + self.url.format(project_name), name)) + + def update(self, project_name, name, testcase_req): + return self.clientmanager.put( + urlparse.path_join( + self.url.format(project_name), name), testcase_req) diff --git a/testapi/testapi-client/testapiclient/models/deployresult.py b/testapi/testapi-client/testapiclient/models/deployresult.py new file mode 100644 index 0000000..5c13966 --- /dev/null +++ b/testapi/testapi-client/testapiclient/models/deployresult.py @@ -0,0 +1,17 @@ +class DeployResultCreateRequest(): + def __init__( + self, build_id='', scenario='', stop_date='', start_date='', + upstream_job_name='', version='', pod_name='', criteria='', + installer='', upstream_build_id='', job_name='', details=''): + self.build_id = build_id + self.scenario = scenario + self.stop_date = stop_date + self.start_date = start_date + self.upstream_job_name = upstream_job_name + self.version = version + self.pod_name = pod_name + self.criteria = criteria + self.installer = installer + self.upstream_build_id = upstream_build_id + self.job_name = job_name + self.details = details diff --git a/testapi/testapi-client/testapiclient/models/pods.py b/testapi/testapi-client/testapiclient/models/pods.py index 27ea311..4fa42e7 100644 --- a/testapi/testapi-client/testapiclient/models/pods.py +++ b/testapi/testapi-client/testapiclient/models/pods.py @@ -1,5 +1,5 @@ class PodCreateRequest(object): - def __init__(self, name='', mode='', details='', role=""): + def __init__(self, name='', mode='', details='', role=''): self.name = name self.mode = mode self.details = details diff --git a/testapi/testapi-client/testapiclient/models/project.py b/testapi/testapi-client/testapiclient/models/project.py new file mode 100644 index 0000000..fc85588 --- /dev/null +++ b/testapi/testapi-client/testapiclient/models/project.py @@ -0,0 +1,4 @@ +class ProjectCreateRequest(): + def __init__(self, name='', description=''): + self.description = description + self.name = name diff --git a/testapi/testapi-client/testapiclient/models/result.py b/testapi/testapi-client/testapiclient/models/result.py new file mode 100644 index 0000000..766c03a --- /dev/null +++ b/testapi/testapi-client/testapiclient/models/result.py @@ -0,0 +1,16 @@ +class ResultCreateRequest(): + def __init__( + self, project_name='', scenario='', case_name='', pod_name='', + installer='', version='', stop_date='', build_tag='', criteria='', + start_date='', details=''): + self.project_name = project_name + self.scenario = scenario + self.case_name = case_name + self.pod_name = pod_name + self.installer = installer + self.version = version + self.stop_date = stop_date + self.build_tag = build_tag + self.criteria = criteria + self.start_date = start_date + self.details = details diff --git a/testapi/testapi-client/testapiclient/models/scenario.py b/testapi/testapi-client/testapiclient/models/scenario.py new file mode 100644 index 0000000..f4f0f40 --- /dev/null +++ b/testapi/testapi-client/testapiclient/models/scenario.py @@ -0,0 +1,37 @@ +class ScenarioCreateRequest: + def __init__(self, name='', installers=[]): + self.name = name + self.installers = installers + + +class ScenarioInstallerCreateRequest: + def __init__(self, installer='', versions=[]): + self.installer = installer + self.versions = versions + + +class ScenarioVersionCreateRequest: + def __init__(self, version='', owner='', projects=[]): + self.version = version + self.owner = owner + self.projects = projects + + +class ScenarioProjectCreateRequest: + def __init__(self, project='', scores=[], trust_indicators=[], customs=[]): + self.project = project + self.scores = scores + self.trust_indicators = trust_indicators + self.customs = customs + + +class ScenarioScoreCreateRequest: + def __init__(self, score='', date=''): + self.score = score + self.date = date + + +class ScenarioTICreateRequest: + def __init__(self, status='', date=''): + self.status = status + self.date = date diff --git a/testapi/testapi-client/testapiclient/models/testcase.py b/testapi/testapi-client/testapiclient/models/testcase.py new file mode 100644 index 0000000..70d5d78 --- /dev/null +++ b/testapi/testapi-client/testapiclient/models/testcase.py @@ -0,0 +1,20 @@ +class TestCaseCreateRequest(): + def __init__( + self, run='', name='', ci_loop='', tags='', url='', + blocking='', domains='', dependencies='', version='', + criteria='', tier='', trust='', catalog_description='', + description=''): + self.run = run + self.name = name + self.ci_loop = ci_loop + self.tags = tags + self.url = url + self.blocking = blocking + self.domains = domains + self.dependencies = dependencies + self.version = version + self.criteria = criteria + self.tier = tier + self.trust = trust + self.catalog_description = catalog_description + self.description = description 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_pod_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_pod_client.py new file mode 100644 index 0000000..1df5660 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_pod_client.py @@ -0,0 +1,89 @@ +import json + +from six.moves.urllib import parse +import testtools + +from testapiclient.client import pods +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils +from testapiclient.utils import clientmanager + + +class PodClientTest(utils.TestCommand): + def setUp(self): + super(PodClientTest, self).setUp() + self.base_url = parse.urljoin(self.api_url, 'pods') + self.pod_json = { + 'role': 'community-ci', + 'name': 'test_pod', + 'details': '', + 'mode': 'metal' + } + self.pod_client = pods.PodsClient() + self.pod_string = json.dumps(self.pod_json) + + +class PodClientGetTest(PodClientTest): + + def setUp(self): + super(PodClientGetTest, self).setUp() + self.pods_rsp = {'pods': [self.pod_json]} + + def test_get(self): + self.get_mock.return_value = fakes.FakeResponse(data=self.pods_rsp) + self.pod_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.pods_rsp) + self.pod_client.get(name='pod1') + self.get_mock.assert_called_once_with( + self.base_url + '?name=pod1', + headers=clientmanager.ClientManager.headers) + + def test_get_one(self): + self.get_mock.return_value = fakes.FakeResponse(data=self.pod_json) + self.pod_client.get_one('def') + self.get_mock.assert_called_once_with( + self.base_url + '/def', + headers=clientmanager.ClientManager.headers) + + +class PodClientCreateTest(PodClientTest): + + def setUp(self): + super(PodClientCreateTest, self).setUp() + self.succ_rsp = { + 'href': '{}/{}'.format(self.base_url, self.pod_json.get('name')) + } + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse(data=self.succ_rsp) + self.pod_client.create(self.pod_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.pod_client.create(self.pod_json) + + +class PodClientDeleteTest(PodClientTest): + + def setUp(self): + super(PodClientDeleteTest, self).setUp() + + def test_delete_success(self): + self.delete_mock.return_value = fakes.FakeResponse() + self.pod_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.pod_client.delete('def') 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) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_client.py new file mode 100644 index 0000000..6e9e0fa --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_client.py @@ -0,0 +1,104 @@ +import json + +from six.moves.urllib import parse +import testtools + +from testapiclient.client import scenarios +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils +from testapiclient.utils import clientmanager + + +class ScenarioClientTest(utils.TestCommand): + def setUp(self): + super(ScenarioClientTest, self).setUp() + self.base_url = parse.urljoin(self.api_url, 'scenarios') + self.scenario_json = { + "installers": [], + "name": "test_scenario" + } + self.scenario_client = scenarios.ScenariosClient() + self.scenario_string = json.dumps(self.scenario_json) + + +class ScenarioClientGetTest(ScenarioClientTest): + + def setUp(self): + super(ScenarioClientGetTest, self).setUp() + self.scenarios_rsp = {'scenarios': [self.scenario_json]} + + def test_get(self): + self.get_mock.return_value = fakes.FakeResponse( + data=self.scenarios_rsp) + self.scenario_client.get() + self.get_mock.assert_called_once_with( + self.base_url, + headers=clientmanager.ClientManager.headers) + + def test_get_one(self): + self.get_mock.return_value = fakes.FakeResponse( + data=self.scenario_json) + self.scenario_client.get_one('def') + self.get_mock.assert_called_once_with( + self.base_url + '/def', + headers=clientmanager.ClientManager.headers) + + +class ScenarioClientCreateTest(ScenarioClientTest): + + def setUp(self): + super(ScenarioClientCreateTest, self).setUp() + self.succ_rsp = { + 'href': '{}/{}'.format( + self.base_url, self.scenario_json.get('name')) + } + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse( + data=self.succ_rsp) + self.scenario_client.create(self.scenario_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.scenario_client.create(self.scenario_json) + + +class ScenarioClientDeleteTest(ScenarioClientTest): + + def setUp(self): + super(ScenarioClientDeleteTest, self).setUp() + + def test_delete_success(self): + self.delete_mock.return_value = fakes.FakeResponse() + self.scenario_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.scenario_client.delete('def') + + +class ScenarioClientUpdateTest(ScenarioClientTest): + + def setUp(self): + super(ScenarioClientUpdateTest, self).setUp() + + def test_update_success(self): + self.put_mock.return_value = fakes.FakeResponse() + self.scenario_client.update( + 'def', self.scenario_json) + self.put_mock.assert_called_once_with( + self.base_url + '/def', + data=self.scenario_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.scenario_client.update('def', self.scenario_json) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_custom_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_custom_client.py new file mode 100644 index 0000000..7c6d62c --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_custom_client.py @@ -0,0 +1,106 @@ +from six.moves.urllib import parse +import testtools + +from testapiclient.client import scenarios +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils + + +class CustomClientTest(utils.TestCommand): + def setUp(self): + super(CustomClientTest, self).setUp() + self.scenario_name = 'scenrio1' + self.base_url = parse.urljoin( + self.api_url, + 'scenarios/{}/customs'.format(self.scenario_name)) + self.custom_raw = 'custom' + self.custom_input = ['custom'] + self.installer_name = 'installer' + self.version_name = 'version' + self.project_name = 'project' + self.custom_client = scenarios.CustomsClient() + + +class CustomClientCreateTest(CustomClientTest): + + def setUp(self): + super(CustomClientCreateTest, self).setUp() + self.succ_rsp = { + 'href': '{}/{}'.format( + self.base_url, self.scenario_name) + } + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse( + data=self.succ_rsp) + self.custom_client.create( + self.scenario_name, self.installer_name, + self.version_name, self.project_name, + self.custom_raw) + 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.custom_client.create( + self.scenario_name, self.installer_name, + self.version_name, self.project_name, + self.custom_raw) + + +class CustomClientDeleteTest(CustomClientTest): + + def setUp(self): + super(CustomClientDeleteTest, self).setUp() + + def test_delete_success(self): + self.delete_mock.return_value = fakes.FakeResponse() + self.custom_client.delete( + self.scenario_name, self.installer_name, + self.version_name, self.project_name, + self.custom_raw) + kall = self.delete_mock.call_args + args, kwargs = kall + self.assert_url( + args[0], + self.base_url + + '?installer=installer&version=version&project=project') + + def test_delete_failure(self): + with testtools.ExpectedException(Exception, 'Delete failed: Error'): + self.delete_mock.return_value = utils.FAKE_FAILURE + self.custom_client.delete( + self.scenario_name, self.installer_name, + self.version_name, self.project_name, + self.custom_raw) + + +class CustomClientUpdateTest(CustomClientTest): + + def setUp(self): + super(CustomClientUpdateTest, self).setUp() + + def test_update_success(self): + self.put_mock.return_value = fakes.FakeResponse() + self.custom_client.update( + self.scenario_name, + self.installer_name, + self.version_name, + self.project_name, + self.custom_raw) + kall = self.put_mock.call_args + args, kwargs = kall + self.assert_url( + args[0], + self.base_url + + '?installer=installer&version=version&project=project') + + def test_update_failure(self): + with testtools.ExpectedException(Exception, 'Update failed: Error'): + self.put_mock.return_value = utils.FAKE_FAILURE + self.custom_client.update( + self.scenario_name, + self.installer_name, + self.version_name, + self.project_name, + self.custom_raw) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_installer_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_installer_client.py new file mode 100644 index 0000000..71ba150 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_installer_client.py @@ -0,0 +1,86 @@ +import json + +from six.moves.urllib import parse +import testtools + +from testapiclient.client import scenarios +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils +from testapiclient.utils import clientmanager + + +class InstallerClientTest(utils.TestCommand): + def setUp(self): + super(InstallerClientTest, self).setUp() + self.scenario_name = 'scenrio1' + self.base_url = parse.urljoin( + self.api_url, + 'scenarios/{}/installers'.format(self.scenario_name)) + self.installer_json = { + 'versions': [], + 'installer': 'test-installer', + } + self.installer_client = scenarios.InstallersClient() + self.installer_string = json.dumps(self.installer_json) + + +class InstallerClientCreateTest(InstallerClientTest): + + def setUp(self): + super(InstallerClientCreateTest, self).setUp() + self.succ_rsp = { + 'href': '{}/{}'.format( + self.base_url, self.installer_json.get('name')) + } + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse( + data=self.succ_rsp) + self.installer_client.create(self.scenario_name, self.installer_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.installer_client.create( + self.scenario_name, self.installer_json) + + +class InstallerClientDeleteTest(InstallerClientTest): + + def setUp(self): + super(InstallerClientDeleteTest, self).setUp() + + def test_delete_success(self): + self.delete_mock.return_value = fakes.FakeResponse() + self.installer_client.delete(self.scenario_name, 'def') + self.delete_mock.assert_called_once_with( + self.base_url, + data=json.dumps(['def']), + 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.installer_client.delete(self.scenario_name, 'def') + + +class InstallerClientUpdateTest(InstallerClientTest): + + def setUp(self): + super(InstallerClientUpdateTest, self).setUp() + + def test_update_success(self): + self.put_mock.return_value = fakes.FakeResponse() + self.installer_client.update( + self.scenario_name, + self.installer_json) + self.put_mock.assert_called_once_with( + self.base_url, + data=self.installer_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.installer_client.update('def', self.installer_json) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_project_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_project_client.py new file mode 100644 index 0000000..f8c3d60 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_project_client.py @@ -0,0 +1,104 @@ +import json + +from six.moves.urllib import parse +import testtools + +from testapiclient.client import scenarios +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils + + +class ProjectClientTest(utils.TestCommand): + def setUp(self): + super(ProjectClientTest, self).setUp() + self.scenario_name = 'scenrio1' + self.base_url = parse.urljoin( + self.api_url, + 'scenarios/{}/projects'.format(self.scenario_name)) + self.project_json = { + 'trust_indicators': [], + 'project': 'test-project', + 'scores': [], + 'customs': [] + } + self.installer_name = 'installer' + self.version_name = 'version' + self.project_client = scenarios.ProjectsClient() + self.project_string = json.dumps(self.project_json) + + +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.scenario_name, self.installer_name, + self.version_name, 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.scenario_name, self.installer_name, + self.version_name, 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( + self.scenario_name, self.installer_name, + self.version_name, 'def') + kall = self.delete_mock.call_args + args, kwargs = kall + self.assert_url( + args[0], + self.base_url + '?installer=installer&version=version') + + def test_delete_failure(self): + with testtools.ExpectedException(Exception, 'Delete failed: Error'): + self.delete_mock.return_value = utils.FAKE_FAILURE + self.project_client.delete( + self.scenario_name, self.installer_name, + self.version_name, '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( + self.scenario_name, + self.installer_name, + self.version_name, + self.project_json) + kall = self.put_mock.call_args + args, kwargs = kall + self.assert_url( + args[0], + self.base_url + '?installer=installer&version=version') + + def test_update_failure(self): + with testtools.ExpectedException(Exception, 'Update failed: Error'): + self.put_mock.return_value = utils.FAKE_FAILURE + self.project_client.update( + self.scenario_name, + self.installer_name, + self.version_name, + self.project_json) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_score_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_score_client.py new file mode 100644 index 0000000..beebd47 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_score_client.py @@ -0,0 +1,53 @@ +import json + +from six.moves.urllib import parse +import testtools + +from testapiclient.client import scenarios +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils + + +class ScoreClientTest(utils.TestCommand): + def setUp(self): + super(ScoreClientTest, self).setUp() + self.scenario_name = 'scenrio1' + self.base_url = parse.urljoin( + self.api_url, + 'scenarios/{}/scores'.format(self.scenario_name)) + self.score_json = { + 'score': 'test_score1', + 'date': '2018/01/2' + } + self.installer_name = 'installer' + self.version_name = 'version' + self.project_name = 'project' + self.score_client = scenarios.ScoresClient() + self.score_string = json.dumps(self.score_json) + + +class ScoreClientCreateTest(ScoreClientTest): + + def setUp(self): + super(ScoreClientCreateTest, self).setUp() + self.succ_rsp = { + 'href': '{}/{}'.format( + self.base_url, self.score_json.get('name')) + } + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse( + data=self.succ_rsp) + self.score_client.create( + self.scenario_name, self.installer_name, + self.version_name, self.project_name, + self.score_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.score_client.create( + self.scenario_name, self.installer_name, + self.version_name, self.project_name, + self.score_json) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_trust_indicator_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_trust_indicator_client.py new file mode 100644 index 0000000..e44e2d2 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_trust_indicator_client.py @@ -0,0 +1,53 @@ +import json + +from six.moves.urllib import parse +import testtools + +from testapiclient.client import scenarios +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils + + +class TrustIndicatorClientTest(utils.TestCommand): + def setUp(self): + super(TrustIndicatorClientTest, self).setUp() + self.scenario_name = 'scenrio1' + self.base_url = parse.urljoin( + self.api_url, + 'scenarios/{}/trust_indicators'.format(self.scenario_name)) + self.trust_indicator_json = { + 'status': 'test_status', + 'date': '2018/01/2' + } + self.installer_name = 'installer' + self.version_name = 'version' + self.project_name = 'project' + self.trust_indicator_client = scenarios.TrustIndicatorsClient() + self.trust_indicator_string = json.dumps(self.trust_indicator_json) + + +class TrustIndicatorClientCreateTest(TrustIndicatorClientTest): + + def setUp(self): + super(TrustIndicatorClientCreateTest, self).setUp() + self.succ_rsp = { + 'href': '{}/{}'.format( + self.base_url, self.trust_indicator_json.get('name')) + } + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse( + data=self.succ_rsp) + self.trust_indicator_client.create( + self.scenario_name, self.installer_name, + self.version_name, self.project_name, + self.trust_indicator_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.trust_indicator_client.create( + self.scenario_name, self.installer_name, + self.version_name, self.project_name, + self.trust_indicator_json) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_scenario_version_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_version_client.py new file mode 100644 index 0000000..1ae2409 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_scenario_version_client.py @@ -0,0 +1,96 @@ +import json + +from six.moves.urllib import parse +import testtools + +from testapiclient.client import scenarios +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils +from testapiclient.utils import clientmanager + + +class VersionClientTest(utils.TestCommand): + def setUp(self): + super(VersionClientTest, self).setUp() + self.scenario_name = 'scenrio1' + self.base_url = parse.urljoin( + self.api_url, + 'scenarios/{}/versions'.format(self.scenario_name)) + self.version_json = { + 'projects': [], + 'version': 'test-version', + 'owner': 'test_owner' + } + self.installer_name = 'installer' + self.version_client = scenarios.VersionsClient() + self.version_string = json.dumps(self.version_json) + + +class VersionClientCreateTest(VersionClientTest): + + def setUp(self): + super(VersionClientCreateTest, self).setUp() + self.succ_rsp = { + 'href': '{}/{}'.format( + self.base_url, self.version_json.get('name')) + } + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse( + data=self.succ_rsp) + self.version_client.create( + self.scenario_name, self.installer_name, self.version_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.version_client.create( + self.scenario_name, self.installer_name, self.version_json) + + +class VersionClientDeleteTest(VersionClientTest): + + def setUp(self): + super(VersionClientDeleteTest, self).setUp() + + def test_delete_success(self): + self.delete_mock.return_value = fakes.FakeResponse() + self.version_client.delete( + self.scenario_name, self.installer_name, 'def') + kall = self.delete_mock.call_args + args, kwargs = kall + self.assert_url( + args[0], + self.base_url + '?installer=installer') + + def test_delete_failure(self): + with testtools.ExpectedException(Exception, 'Delete failed: Error'): + self.delete_mock.return_value = utils.FAKE_FAILURE + self.version_client.delete( + self.scenario_name, self.installer_name, 'def') + + +class VersionClientUpdateTest(VersionClientTest): + + def setUp(self): + super(VersionClientUpdateTest, self).setUp() + + def test_update_success(self): + self.put_mock.return_value = fakes.FakeResponse() + self.version_client.update( + self.scenario_name, + self.installer_name, + self.version_json) + self.put_mock.assert_called_once_with( + self.base_url + '?installer=installer', + data=self.version_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.version_client.update( + self.scenario_name, + self.installer_name, + self.version_json) diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_testcase_client.py b/testapi/testapi-client/testapiclient/tests/unit/test_testcase_client.py new file mode 100644 index 0000000..d80ae27 --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_testcase_client.py @@ -0,0 +1,118 @@ +import json + +from six.moves.urllib import parse +import testtools + +from testapiclient.client import testcases +from testapiclient.tests.unit import fakes +from testapiclient.tests.unit import utils +from testapiclient.utils import clientmanager + + +class TestcaseClientTest(utils.TestCommand): + def setUp(self): + super(TestcaseClientTest, self).setUp() + self.base_url = parse.urljoin(self.api_url, 'projects/{}/cases') + self.project_name = 'functest' + self.testcase_json = { + 'run': '', + 'name': 'test-case', + 'ci_loop': '', + 'tags': '', + 'url': '', + 'blocking': '', + 'domains': '', + 'dependencies': '', + 'version': '', + 'criteria': '', + 'tier': '', + 'trust': '', + 'catalog_description': '', + 'description': '' + } + self.testcase_client = testcases.TestcasesClient() + self.testcase_string = json.dumps(self.testcase_json) + + +class TestcaseClientGetTest(TestcaseClientTest): + + def setUp(self): + super(TestcaseClientGetTest, self).setUp() + self.testcases_rsp = {'testcases': [self.testcase_json]} + + def test_get(self): + self.get_mock.return_value = fakes.FakeResponse( + data=self.testcases_rsp) + self.testcase_client.get(self.project_name) + self.get_mock.assert_called_once_with( + self.base_url.format(self.project_name), + headers=clientmanager.ClientManager.headers) + + def test_get_one(self): + self.get_mock.return_value = fakes.FakeResponse( + data=self.testcase_json) + self.testcase_client.get_one(self.project_name, 'def') + self.get_mock.assert_called_once_with( + self.base_url.format(self.project_name) + '/def', + headers=clientmanager.ClientManager.headers) + + +class TestcaseClientCreateTest(TestcaseClientTest): + + def setUp(self): + super(TestcaseClientCreateTest, self).setUp() + self.succ_rsp = { + 'href': '{}/{}'.format( + self.base_url, self.testcase_json.get('name')) + } + + def test_create_success(self): + self.post_mock.return_value = fakes.FakeResponse( + data=self.succ_rsp) + self.testcase_client.create(self.project_name, self.testcase_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.testcase_client.create(self.project_name, self.testcase_json) + + +class TestcaseClientDeleteTest(TestcaseClientTest): + + def setUp(self): + super(TestcaseClientDeleteTest, self).setUp() + + def test_delete_success(self): + self.delete_mock.return_value = fakes.FakeResponse() + self.testcase_client.delete(self.project_name, 'def') + self.delete_mock.assert_called_once_with( + self.base_url.format(self.project_name) + '/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.testcase_client.delete(self.project_name, 'def') + + +class TestcaseClientUpdateTest(TestcaseClientTest): + + def setUp(self): + super(TestcaseClientUpdateTest, self).setUp() + + def test_update_success(self): + self.put_mock.return_value = fakes.FakeResponse() + self.testcase_client.update( + self.project_name, 'def', self.testcase_json) + self.put_mock.assert_called_once_with( + self.base_url.format(self.project_name) + '/def', + data=self.testcase_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.testcase_client.update( + self.project_name, 'def', self.testcase_json) |