Skip to content

Commit 40d4776

Browse files
dsaylingCopilot
andauthored
chore: add bulk methods for get_suites and get_users (#119)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent e8b7bff commit 40d4776

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

testrail_api/_category.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,22 @@ def get_suites(self, project_id: int, offset: Optional[int] = None, limit: Optio
19701970
"""
19711971
return self.s.get(endpoint=f"get_suites/{project_id}", params=self._opt({"offset": offset, "limit": limit}))
19721972

1973+
def get_suites_bulk(self, project_id: int, **kwargs) -> list[dict]:
1974+
"""
1975+
Return a list of test suites for a project with pagination.
1976+
1977+
:param project_id:
1978+
The ID of the project
1979+
:param kwargs:
1980+
:key offset: int
1981+
Where to start counting the suites from (the offset)
1982+
:key limit: int
1983+
The number of suites the response should return
1984+
:return: List of test suites
1985+
:returns: list[dict]
1986+
"""
1987+
return _bulk_api_method(self.get_suites, "suites", project_id, **kwargs)
1988+
19731989
def add_suite(self, project_id: int, name: str, **kwargs) -> dict:
19741990
"""
19751991
Creates a new test suite.
@@ -2143,6 +2159,23 @@ def get_users(
21432159
params=self._opt({"offset": offset, "limit": limit}),
21442160
)
21452161

2162+
def get_users_bulk(self, project_id: Optional[int] = None, **kwargs) -> list[dict]:
2163+
"""
2164+
Return a list of users with pagination.
2165+
2166+
:param project_id:
2167+
The ID of the project for which you would like to retrieve user information.
2168+
(Required for non-administrators. Requires TestRail 6.6 or later.)
2169+
:param kwargs:
2170+
:key offset: int
2171+
Where to start counting the users from (the offset)
2172+
:key limit: int
2173+
The number of users the response should return
2174+
:return: List of users
2175+
:returns: list[dict]
2176+
"""
2177+
return _bulk_api_method(self.get_users, "users", project_id, **kwargs)
2178+
21462179

21472180
class SharedSteps(_MetaCategory):
21482181
"""https://www.gurock.com/testrail/docs/api/reference/api-shared-steps."""

tests/test_suites.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ def test_get_suites(api, mock, url, offset, limit):
4545
assert resp["suites"][1]["description"] == "Suite2"
4646

4747

48+
def test_get_suites_bulk(api, mock, url):
49+
mock.add_callback(responses.GET, url("get_suites/5"), get_suites)
50+
resp = api.suites.get_suites_bulk(5)
51+
assert resp[0]["id"] == 1
52+
assert resp[1]["description"] == "Suite2"
53+
54+
4855
def test_add_suite(api, mock, url):
4956
mock.add_callback(responses.POST, url("add_suite/7"), add_suite)
5057
resp = api.suites.add_suite(7, "New suite", description="My new suite")

tests/test_users.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ def test_get_users_no_project_id(api, mock, url, offset, limit):
6161
assert response["users"][0]["name"] == "John Smith"
6262

6363

64+
def test_get_users_bulk(api, mock, url):
65+
mock.add_callback(responses.GET, url("get_users/15"), get_users)
66+
resp = api.users.get_users_bulk(15)
67+
assert resp[0]["id"] == 1
68+
assert resp[1]["name"] == "Jane Smith"
69+
70+
71+
def test_get_users_bulk_no_project_id(api, mock, url):
72+
mock.add_callback(responses.GET, url("get_users"), get_users)
73+
resp = api.users.get_users_bulk()
74+
assert resp[0]["id"] == 1
75+
assert resp[1]["name"] == "Jane Smith"
76+
77+
6478
def test_get_current_user(api, mock, url):
6579
mock.add_callback(
6680
responses.GET,

0 commit comments

Comments
 (0)