comparison Tests/Toolbox.py @ 28:156c7ae164b5

new test
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 12:10:30 +0200
parents 2a29bcff60a7
children ffa542cce638
comparison
equal deleted inserted replaced
27:cde1691838d3 28:156c7ae164b5
68 def _SetupCredentials(orthanc, http): 68 def _SetupCredentials(orthanc, http):
69 if (orthanc['Username'] != None and 69 if (orthanc['Username'] != None and
70 orthanc['Password'] != None): 70 orthanc['Password'] != None):
71 http.add_credentials(orthanc['Username'], orthanc['Password']) 71 http.add_credentials(orthanc['Username'], orthanc['Password'])
72 72
73 73 def DoGetRaw(orthanc, uri, data = {}, body = None, headers = {}):
74 def DoGet(orthanc, uri, data = {}, body = None, headers = {}):
75 d = '' 74 d = ''
76 if len(data.keys()) > 0: 75 if len(data.keys()) > 0:
77 d = '?' + urlencode(data) 76 d = '?' + urlencode(data)
78 77
79 http = httplib2.Http() 78 http = httplib2.Http()
80 http.follow_redirects = False 79 http.follow_redirects = False
81 _SetupCredentials(orthanc, http) 80 _SetupCredentials(orthanc, http)
82 81
83 resp, content = http.request(orthanc['Url'] + uri + d, 'GET', body = body, 82 resp, content = http.request(orthanc['Url'] + uri + d, 'GET', body = body,
84 headers = headers) 83 headers = headers)
84 return (resp, content)
85
86
87 def DoGet(orthanc, uri, data = {}, body = None, headers = {}):
88 (resp, content) = DoGetRaw(orthanc, uri, data = data, body = body, headers = headers)
89
85 if not (resp.status in [ 200 ]): 90 if not (resp.status in [ 200 ]):
86 raise Exception(resp.status) 91 raise Exception(resp.status)
87 else: 92 else:
88 try: 93 try:
89 return json.loads(content) 94 return json.loads(content)