From d4d3bfca3c9d74abc2526f4b2414544664a65e61 Mon Sep 17 00:00:00 2001 From: whlpatricia <113727646+whlpatricia@users.noreply.github.com> Date: Tue, 25 Mar 2025 18:17:48 -0400 Subject: [PATCH] Finished exercise --- modules/testrail.py | 4 ++++ update_test_cases.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 update_test_cases.py diff --git a/modules/testrail.py b/modules/testrail.py index 1a46bf90..549f4009 100644 --- a/modules/testrail.py +++ b/modules/testrail.py @@ -159,6 +159,10 @@ def __init__(self, host, username, password, local=False): def get_test_case(self, case_id): """Get a given Test Case""" return self.client.send_get(f"get_case/{case_id}") + + def get_suites(self, project_id): + """Get all suites for project""" + return self.client.send_get(f"get_suites/{project_id}") def update_cases_in_suite(self, suite_id, case_ids, **kwargs): """Given a suite and a list of test cases, update all listed diff --git a/update_test_cases.py b/update_test_cases.py new file mode 100644 index 00000000..d0c60179 --- /dev/null +++ b/update_test_cases.py @@ -0,0 +1,28 @@ +import os, logging +import modules.testrail_integration as tri + +SUITES = ["Form Autofill", "Geolocation", "Language Packs"] +FULL_COVERAGE_VALUE = 3 + + +def main(): + # Set env variables for testrail_init function + os.environ["TESTRAIL_BASE_URL"] = "https://mozilla.testrail.io" + os.environ["TESTRAIL_USERNAME"] = "user" + os.environ["TESTRAIL_API_KEY"] = "api_key" + tr = tri.testrail_init() + + # Get all suites from our project + for suite in tr.get_suites(17): + if suite["name"] not in SUITES: + continue + # Loop through all the test cases in the target suite + for case in tr._get_test_cases(17, suite["id"])["cases"]: + # Check if the custom automated field is set to see if we automated it + if case["custom_automated_test_names"]: + logging.info(f"Updating test case {case['id']} coverage status for full") + tr.update_case_field(case['id'], "custom_automation_coverage", FULL_COVERAGE_VALUE) + + +if __name__ == "__main__": + main()