Skip to content

Commit

Permalink
Don't hardcode limit
Browse files Browse the repository at this point in the history
  • Loading branch information
clarmso committed Dec 10, 2024
1 parent 94e1e56 commit 0b3600a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion backup-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 14 additions & 5 deletions backup-tools/backup_testrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions backup-tools/testrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0b3600a

Please sign in to comment.