Skip to content

Commit df25ee5

Browse files
authored
[XRAY] add get_test_run_iteration method and add more meaningful error raising for incorrect token in XRAY (atlassian-api#1504)
* [XRAY] add get_test_run_iteration method * [XRAY] added raise_for_status method - could solve atlassian-api#1059, atlassian-api#1159 * [XRAY] updated docs --------- Co-authored-by: Maksym Charuta <your_jlr_email>
1 parent b9852b8 commit df25ee5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

atlassian/xray.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# coding=utf-8
22
import logging
33
import re
4+
from requests import HTTPError
45
from .rest_client import AtlassianRestAPI
56

67
log = logging.getLogger(__name__)
@@ -13,6 +14,25 @@ def __init__(self, *args, **kwargs):
1314
kwargs["api_root"] = "rest/raven"
1415
super(Xray, self).__init__(*args, **kwargs)
1516

17+
def raise_for_status(self, response):
18+
"""
19+
Checks the response for an error status and raises an exception with the error message provided by the server
20+
:param response:
21+
:return:
22+
"""
23+
if response.status_code == 401 and response.headers.get("Content-Type") != "application/json;charset=UTF-8":
24+
raise HTTPError("Unauthorized (401)", response=response)
25+
26+
if 400 <= response.status_code < 600:
27+
try:
28+
j = response.json()
29+
error_msg = j["message"]
30+
except Exception as e:
31+
log.error(e)
32+
response.raise_for_status()
33+
else:
34+
raise HTTPError(error_msg, response=response)
35+
1636
def resource_url(self, resource, api_root=None, api_version=None):
1737
"""
1838
Overloading the method from AtlassianRestAPI to be compatible with the "middle man" version used by Xray.
@@ -463,6 +483,16 @@ def update_test_run_assignee(self, test_run_id, assignee):
463483
url = self.resource_url("testrun/{0}".format(test_run_id))
464484
return self.put(url, update)
465485

486+
def get_test_run_iteration(self, test_run_id, iteration_id):
487+
"""
488+
Retrieve the specified iteration for the given test run.
489+
:param test_run_id: ID of the test run (e.g. 100).
490+
:param iteration_id: ID of the iteration.
491+
:return: Returns the specified iteration for the given test run.
492+
"""
493+
url = self.resource_url("testrun/{0}/iteration/{1}".format(test_run_id, iteration_id))
494+
return self.get(url)
495+
466496
def get_test_run_status(self, test_run_id):
467497
"""
468498
Retrieve the status for the given test run.

docs/xray.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ Manage Test Runs
136136
# Update the assignee for the given test run
137137
xray.update_test_run_assignee(100, 'bob')
138138
139+
# Retrieve a iteration of the given test run
140+
xray.get_test_run_iteration(100, 200)
141+
139142
# Retrieve the status for the given test run
140143
xray.get_test_run_status(100)
141144

0 commit comments

Comments
 (0)