def add_test_results(self, test_run_list: list, suite_runs: list): """ :param test_run_list: a list of runs that were generated in the test plan creation :param suite_runs: a list of suite objects :return: None status_id = 1 for Passed status_id = 5 for Failed status_id = 2 for Blocked """ for run in test_run_list: if isinstance(run, dict): run_id = run.get("id") else: logger.error("Invalid API response.") break for suite in suite_runs: object_list = [] results = {} if isinstance(suite, TestSuiteMap): if suite.suite_name in run.get("name"): suite_id_tests = suite.test_results_list for test in suite_id_tests: payload = {} test_results = test.get_test_status() if (test.blocked_by) is not None: payload["status_id"] = 2 payload["defects"] = str(test.blocked_by) elif test_results.__contains__( "FAILED") or test_results.__contains__( "ERROR"): payload["status_id"] = 5 else: payload["status_id"] = 1 # payload['comment'] = complete_test_assert payload["case_id"] = test.test_case_id object_list.append(payload) results["results"] = object_list if run_id is not None: try: self.client.send_post( "add_results_for_cases/%s" % run_id, results) except Exception: raise TestRailError( "Failed to Update Test_Rail run %s", run.get("name")) else: logger.info( "Successfully added test results in test run name: %s" % run.get("name")) else: raise TestRailError("Invalid run_id") else: continue else: raise TestRailError("Invalid API Response")
def get_specific_run_id(self, project_name, test_run_name): """Return a specific run id based on project name. :param project_name: name of TestRail Project (Ex. Firefox Desktop) :param test_run_name: name of TestRail test run (Bx. Bookmarks, History) :return: Id of the Test Run (Ex 17,34) """ test_runs = self.get_all_runs(project_name) for test_run in test_runs: if test_run["name"] == test_run_name: run_id = test_run["id"] return run_id else: logger.error("Test run not found: %s", test_run_name)