Skip to content

Commit 7702923

Browse files
Xray: add pagination support for api methods (#595)
This commit adds the missing pagination support to `get_tests_with_test_set()` and `get_tests_with_test_execution()`. In addition, it will provide to option to retrieve detailed Test execution details.
1 parent 31fef54 commit 7702923

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

atlassian/xray.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ def update_precondition(self, precondition_key, add=None, remove=None):
168168
"""
169169
Associate tests with the given pre-condition.
170170
:param precondition_key: Precondition key (eg. 'TEST-001').
171-
:param add: OPTIONAL List of Test Keys to associate with the pre-condition (eg. ['TEST-2', 'TEST-3'])
172-
:param remove: OPTIONAL List of Test Keys no longer associate with the pre-condition (eg. ['TEST-4', 'TEST-5'])
171+
:param add: OPTIONAL: List of Test Keys to associate with the pre-condition (eg. ['TEST-2', 'TEST-3'])
172+
:param remove: OPTIONAL: List of Test Keys no longer associate with the pre-condition (eg. ['TEST-4', 'TEST-5'])
173173
:return:
174174
"""
175175
if remove is None:
@@ -191,21 +191,30 @@ def delete_test_from_precondition(self, precondition_key, test_key):
191191
return self.delete(url)
192192

193193
# Test Set API
194-
def get_tests_with_test_set(self, test_set_key):
194+
def get_tests_with_test_set(self, test_set_key, limit=None, page=None):
195195
"""
196196
Retrieve the tests associated with the given test set.
197197
:param test_set_key: Test set key (eg. 'SET-001').
198+
:param limit: OPTIONAL: Limits the number of results per page.
199+
:param page: OPTIONAL: Number of the page to be returned.
198200
:return: Return a list of the test associated with the test set.
199201
"""
200202
url = 'rest/raven/1.0/api/testset/{0}/test'.format(test_set_key)
201-
return self.get(url)
203+
params = {}
204+
205+
if limit:
206+
params['limit'] = limit
207+
if page:
208+
params['page'] = page
209+
210+
return self.get(url, params=params)
202211

203212
def update_test_set(self, test_set_key, add=None, remove=None):
204213
"""
205214
Associate tests with the given test set.
206215
:param test_set_key: Test set key (eg. 'SET-001').
207-
:param add: OPTIONAL List of Test Keys to associate with the test set (eg. ['TEST-002', 'TEST-003'])
208-
:param remove: OPTIONAL List of Test Keys no longer associate with the test set (eg. ['TEST-004', 'TEST-005'])
216+
:param add: OPTIONAL: List of Test Keys to associate with the test set (eg. ['TEST-002', 'TEST-003'])
217+
:param remove: OPTIONAL: List of Test Keys no longer associate with the test set (eg. ['TEST-004', 'TEST-005'])
209218
:return:
210219
"""
211220
if add is None:
@@ -240,8 +249,8 @@ def update_test_plan(self, test_plan_key, add=None, remove=None):
240249
"""
241250
Associate tests with the given test plan.
242251
:param test_plan_key: Test plan key (eg. 'PLAN-001').
243-
:param add: OPTIONAL List of Test Keys to associate with the test plan (eg. ['TEST-002', 'TEST-003'])
244-
:param remove: OPTIONAL List of Test Keys no longer associate with the test plan (eg. ['TEST-004', 'TEST-005'])
252+
:param add: OPTIONAL: List of Test Keys to associate with the test plan (eg. ['TEST-002', 'TEST-003'])
253+
:param remove: OPTIONAL: List of Test Keys no longer associate with the test plan (eg. ['TEST-004', 'TEST-005'])
245254
:return:
246255
"""
247256
if add is None:
@@ -263,21 +272,33 @@ def delete_test_from_test_plan(self, test_plan_key, test_key):
263272
return self.delete(url)
264273

265274
# Test Executions API
266-
def get_tests_with_test_execution(self, test_exec_key):
275+
def get_tests_with_test_execution(self, test_exec_key, detailed=False, limit=None, page=None):
267276
"""
268277
Retrieve the tests associated with the given test execution.
269278
:param test_exec_key: Test execution key (eg. 'EXEC-001').
279+
:param detailed: OPTIONAL: (bool) Retrieve detailed information about the testrun
280+
:param limit: OPTIONAL: Limits the number of results per page.
281+
:param page: OPTIONAL: Number of the page to be returned.
270282
:return: Return a list of the test associated with the test execution.
271283
"""
272284
url = 'rest/raven/1.0/api/testexec/{0}/test'.format(test_exec_key)
273-
return self.get(url)
285+
params = {}
286+
287+
if detailed:
288+
params['detailed'] = detailed
289+
if limit:
290+
params['limit'] = limit
291+
if page:
292+
params['page'] = page
293+
294+
return self.get(url, params=params)
274295

275296
def update_test_execution(self, test_exec_key, add=None, remove=None):
276297
"""
277298
Associate tests with the given test execution.
278299
:param test_exec_key: Test execution key (eg. 'EXEC-001').
279-
:param add: OPTIONAL List of Test Keys to associate with the test execution (eg. ['TEST-2', 'TEST-3'])
280-
:param remove: OPTIONAL List of Test Keys no longer associate with the test execution (eg. ['TEST-4', 'TEST-5'])
300+
:param add: OPTIONAL: List of Test Keys to associate with the test execution (eg. ['TEST-2', 'TEST-3'])
301+
:param remove: OPTIONAL: List of Test Keys no longer associate with the test execution (eg. ['TEST-4', 'TEST-5'])
281302
:return:
282303
"""
283304
if add is None:
@@ -361,8 +382,8 @@ def update_test_run_defects(self, test_run_id, add=None, remove=None):
361382
"""
362383
Update the defects associated with the given test run.
363384
:param test_run_id: ID of the test run (eg. 100).
364-
:param add: OPTIONAL List of defects to associate to the test run (eg. ['BUG-001', 'BUG-002'])
365-
:param remove: OPTIONAL List of defects which no longer need to be associated to the test run (eg. ['BUG-003'])
385+
:param add: OPTIONAL: List of defects to associate to the test run (eg. ['BUG-001', 'BUG-002'])
386+
:param remove: OPTIONAL: List of defects which no longer need to be associated to the test run (eg. ['BUG-003'])
366387
:return:
367388
"""
368389
if add is None:

docs/xray.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Manage Test sets
7575
.. code-block:: python
7676
7777
# Retrieve the tests associated with the given test set
78-
xray.get_tests_with_test_set('SET-001')
78+
xray.get_tests_with_test_set('SET-001', page=1, limit=10)
7979
8080
# Associate tests with the given test set
8181
xray.update_test_set('SET-001',add=['TEST-001','TEST-002'], remove=['TEST-003'])
@@ -103,7 +103,7 @@ Manage Test Executions
103103
.. code-block:: python
104104
105105
# Retrieve the tests associated with the given test execution
106-
xray.get_tests_with_test_execution('EXEC-001')
106+
xray.get_tests_with_test_execution('EXEC-001', detailed=True, page=1, limit=10)
107107
108108
# Associate tests with the given test execution
109109
xray.update_test_execution('EXEC-001', add=['TEST-001', 'TEST-002'], remove=['TEST-003'])

0 commit comments

Comments
 (0)