1
1
# coding=utf-8
2
2
import logging
3
3
import re
4
+ from requests import HTTPError
4
5
from .rest_client import AtlassianRestAPI
5
6
6
7
log = logging .getLogger (__name__ )
@@ -13,6 +14,25 @@ def __init__(self, *args, **kwargs):
13
14
kwargs ["api_root" ] = "rest/raven"
14
15
super (Xray , self ).__init__ (* args , ** kwargs )
15
16
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
+
16
36
def resource_url (self , resource , api_root = None , api_version = None ):
17
37
"""
18
38
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):
463
483
url = self .resource_url ("testrun/{0}" .format (test_run_id ))
464
484
return self .put (url , update )
465
485
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
+
466
496
def get_test_run_status (self , test_run_id ):
467
497
"""
468
498
Retrieve the status for the given test run.
0 commit comments