diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /taskcluster/scripts/lib | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'taskcluster/scripts/lib')
-rw-r--r-- | taskcluster/scripts/lib/testrail_api.py | 126 |
1 files changed, 71 insertions, 55 deletions
diff --git a/taskcluster/scripts/lib/testrail_api.py b/taskcluster/scripts/lib/testrail_api.py index 44474ebe9d..786ae8552c 100644 --- a/taskcluster/scripts/lib/testrail_api.py +++ b/taskcluster/scripts/lib/testrail_api.py @@ -37,82 +37,98 @@ from testrail_conn import APIClient class TestRail: def __init__(self, host, username, password): + if not all([host, username, password]): + raise ValueError("TestRail host, username, and password must be provided.") self.client = APIClient(host) self.client.user = username self.client.password = password # Public Methods - def create_milestone(self, testrail_project_id, title, description): + def create_milestone(self, project_id, title, description): + if not all([project_id, title, description]): + raise ValueError("Project ID, title, and description must be provided.") data = {"name": title, "description": description} - return self.client.send_post(f"add_milestone/{testrail_project_id}", data) - - def create_milestone_and_test_runs( - self, project_id, milestone_name, milestone_description, devices, test_suite_id - ): - # Create milestone - milestone_id = self._retry_api_call( - self.create_milestone, project_id, milestone_name, milestone_description - )["id"] - - # Create test runs for each device - for device in devices: - test_run_id = self._retry_api_call( - self.create_test_run, project_id, milestone_id, device, test_suite_id - )["id"] - self._retry_api_call( - self.update_test_cases_to_passed, project_id, test_run_id, test_suite_id - ) - - return milestone_id + return self.client.send_post(f"add_milestone/{project_id}", data) def create_test_run( - self, testrail_project_id, testrail_milestone_id, name_run, testrail_suite_id + self, + project_id, + milestone_id, + test_run_name, + suite_id, ): + if not all([project_id, milestone_id, test_run_name, suite_id]): + raise ValueError( + "Project ID, milestone ID, test run name, and suite ID must be provided." + ) data = { - "name": name_run, - "milestone_id": testrail_milestone_id, - "suite_id": testrail_suite_id, + "name": test_run_name, + "milestone_id": milestone_id, + "suite_id": suite_id, } - return self.client.send_post(f"add_run/{testrail_project_id}", data) - - def does_milestone_exist(self, testrail_project_id, milestone_name): - num_of_milestones_to_check = 10 # check last 10 milestones - milestones = self._get_milestones( - testrail_project_id - ) # returns reverse chronological order - for milestone in milestones[ - -num_of_milestones_to_check: - ]: # check last 10 api responses - if milestone_name == milestone["name"]: - return True - return False - - def update_test_cases_to_passed( - self, testrail_project_id, testrail_run_id, testrail_suite_id - ): - test_cases = self._get_test_cases(testrail_project_id, testrail_suite_id) + return self.client.send_post(f"add_run/{project_id}", data) + + def does_milestone_exist(self, project_id, milestone_name, num_of_milestones=10): + if not all([project_id, milestone_name]): + raise ValueError("Project ID and milestone name must be provided.") + # returns reverse chronological order of milestones, check last 10 milestones + milestones = self._get_milestones(project_id)[-num_of_milestones:] + return any(milestone_name == milestone["name"] for milestone in milestones) + + def update_test_run_tests(self, test_run_id, test_status): + if not all([test_run_id, test_status]): + raise ValueError("Test run ID and test status must be provided.") + tests = self._get_tests(test_run_id) data = { "results": [ - {"case_id": test_case["id"], "status_id": 1} for test_case in test_cases + {"test_id": test["id"], "status_id": test_status} for test in tests ] } - return self._update_test_run_results(testrail_run_id, data) + return self.client.send_post(f"add_results/{test_run_id}", data) # Private Methods - def _get_test_cases(self, testrail_project_id, testrail_test_suite_id): - return self.client.send_get( - f"get_cases/{testrail_project_id}&suite_id={testrail_test_suite_id}" - ) - - def _update_test_run_results(self, testrail_run_id, data): - return self.client.send_post(f"add_results_for_cases/{testrail_run_id}", data) - - def _get_milestones(self, testrail_project_id): - return self.client.send_get(f"get_milestones/{testrail_project_id}") + def _get_test_cases(self, project_id, suite_id): + if not all([project_id, suite_id]): + raise ValueError("Project ID and suite ID must be provided.") + return self.client.send_get(f"get_cases/{project_id}&suite_id={suite_id}")[ + "cases" + ] + + def _get_milestone(self, milestone_id): + if not milestone_id: + raise ValueError("Milestone ID must be provided.") + return self.client.send_get(f"get_milestone/{milestone_id}") + + def _get_milestones(self, project_id): + if not project_id: + raise ValueError("Project ID must be provided.") + return self.client.send_get(f"get_milestones/{project_id}")["milestones"] + + def _get_tests(self, test_run_id): + if not test_run_id: + raise ValueError("Test run ID must be provided.") + return self.client.send_get(f"get_tests/{test_run_id}")["tests"] + + def _get_test_run(self, test_run_id): + if not test_run_id: + raise ValueError("Test run ID must be provided.") + return self.client.send_get(f"get_run/{test_run_id}") + + def _get_test_runs(self, project_id): + if not project_id: + raise ValueError("Project ID must be provided.") + return self.client.send_get(f"get_runs/{project_id}")["runs"] + + def _get_test_run_results(self, test_run_id): + if not test_run_id: + raise ValueError("Test run ID must be provided.") + return self.client.send_get(f"get_results_for_run/{test_run_id}")["results"] def _retry_api_call(self, api_call, *args, max_retries=3, delay=5): + if not all([api_call, args]): + raise ValueError("API call and arguments must be provided.") """ Retries the given API call up to max_retries times with a delay between attempts. |