Skip to content

Commit acf1ed6

Browse files
Hani YacoubHani Yacoub
authored andcommitted
adding pagination
1 parent 7d7973b commit acf1ed6

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

modules/testrail_script_set_all_subs_to_functional.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,33 @@
99

1010
# Set TestRail credentials
1111
os.environ["TESTRAIL_BASE_URL"] = "https://mozilla.testrail.io"
12-
os.environ["TESTRAIL_USERNAME"] = ""
13-
os.environ["TESTRAIL_API_KEY"] = ""
12+
os.environ["TESTRAIL_USERNAME"] = "[email protected]"
13+
os.environ["TESTRAIL_API_KEY"] = "HrENZ5FSSxiI1xl3DTMF-NMm1qGug2bVZM3NCALhV"
1414

1515

1616
def get_all_cases_from_suite(tr, project_id, suite_id):
17-
"""Fetch all test cases in the suite"""
18-
response = tr._get_test_cases(project_id, suite_id)
19-
cases = response.get("cases", [])
20-
logging.info(f"Total cases fetched from suite {suite_id}: {len(cases)}")
21-
return cases
17+
"""Fetch all test cases from a suite by handling pagination."""
18+
all_cases = []
19+
offset = 0
20+
limit = 240 # Default limit for TestRail API is 250
21+
22+
while True:
23+
# Build endpoint with pagination parameters
24+
endpoint = (
25+
f"get_cases/{project_id}&suite_id={suite_id}&limit={limit}&offset={offset}"
26+
)
27+
response = tr.client.send_get(endpoint)
28+
cases = response.get("cases", [])
29+
if not cases:
30+
break
31+
all_cases.extend(cases)
32+
# If the number of cases returned is less than the limit, we've reached the last page.
33+
if len(cases) < limit:
34+
break
35+
offset += limit
36+
37+
logging.info(f"Total cases fetched from suite {suite_id}: {len(all_cases)}")
38+
return all_cases
2239

2340

2441
if __name__ == "__main__":

0 commit comments

Comments
 (0)