11# coding=utf-8
22import logging
33import re
4+ from requests import HTTPError
45from .rest_client import AtlassianRestAPI
56
67log = 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.
0 commit comments