diff --git a/backup-tools/README.md b/backup-tools/README.md index 446de74..5e0b5c4 100644 --- a/backup-tools/README.md +++ b/backup-tools/README.md @@ -25,7 +25,7 @@ Google Cloud bucket on a regular basis. ## Limitations -* Only the first 250 test cases are exported. +* Some test cases (max 5%) are not exported for unknown reasons. * Not all custom fields are captured in [testrail-import.cfg](https://github.com/mozilla-mobile/testops-tools/blob/main/backup-tools/testrail-import.cfg). * The following fields are known to be not imported: Automation, Automation Coverage, Sub Test Suite(s), Automated Test Name(s), Notes. * The following fields may not be imported properly: Type, Priority, AssignedTo, Estimate, References. diff --git a/backup-tools/backup_testrail.py b/backup-tools/backup_testrail.py index fd5b42f..d783f0f 100644 --- a/backup-tools/backup_testrail.py +++ b/backup-tools/backup_testrail.py @@ -10,15 +10,24 @@ def create_csv(project_id, project_name, suite_id, suite_name): now = datetime.now() testrail = TestRail() - response = testrail.test_cases(project_id, suite_id) - # Get only the cases only - cases = response['cases'] + # TestRail API limits 250 test cases to be fetched at a time. + # We repeatedly fetch test cases until there's no more left. + offset_count = 0 + cases = [] + more_cases = [{}] + while len(more_cases) > 0: + response = testrail.test_cases(project_id, suite_id, offset_count) + more_cases = response['cases'] + cases += more_cases + offset_count = len(cases) + print("TOTAL: {0} cases fetched".format(len(cases))) # Do not create backup for empty suites if len(cases) == 0: + print("No backup file is created because the test suite is empty.") return - + output_json_file = "backup_{project}_{suite}_{year}-{month}-{day}.json".format( project=project_name, suite=suite_name, @@ -47,7 +56,7 @@ def create_csv(project_id, project_name, suite_id, suite_name): csv_writer.writerow(backup_fields) # Print rows (including unravel the Steps and Expected Results) - for case in cases[1:]: + for case in cases: first_row = [case.get(field, '') for field in backup_fields[:-2]] # need treatment for steps steps = case['custom_steps_separated'] if steps: diff --git a/backup-tools/testrail.py b/backup-tools/testrail.py index f9053b0..e48c0ca 100644 --- a/backup-tools/testrail.py +++ b/backup-tools/testrail.py @@ -24,10 +24,10 @@ def project(self, testrail_project_id): 'get_project/{0}'.format(testrail_project_id)) # API: Cases - def test_cases(self, testrail_project_id, testrail_test_suite_id): + def test_cases(self, testrail_project_id, testrail_test_suite_id, offset = 0): return self.client.send_get( - 'get_cases/{0}&suite_id={1}' - .format(testrail_project_id, testrail_test_suite_id)) + 'get_cases/{0}&suite_id={1}&offset={2}' + .format(testrail_project_id, testrail_test_suite_id, offset)) def test_case(self, testrail_test_case_id): return self.client.send_get(