comparison Tests/Toolbox.py @ 391:227d9a932467

testing revisions in metadata
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Apr 2021 17:13:53 +0200
parents 79ce0f7a9714
children 9528e2a03d3c
comparison
equal deleted inserted replaced
390:5c2472f008eb 391:227d9a932467
139 headers['expect'] = '' 139 headers['expect'] = ''
140 140
141 resp, content = http.request(orthanc['Url'] + uri, method, 141 resp, content = http.request(orthanc['Url'] + uri, method,
142 body = body, 142 body = body,
143 headers = headers) 143 headers = headers)
144 if not (resp.status in [ 200, 201, 302 ]): 144 return (resp, content)
145 raise Exception(resp.status, resp) 145
146 else: 146 def DoDeleteRaw(orthanc, uri, headers = {}):
147 return _DecodeJson(content)
148
149 def DoDelete(orthanc, uri):
150 http = httplib2.Http() 147 http = httplib2.Http()
151 http.follow_redirects = False 148 http.follow_redirects = False
152 _SetupCredentials(orthanc, http) 149 _SetupCredentials(orthanc, http)
153 150
154 resp, content = http.request(orthanc['Url'] + uri, 'DELETE') 151 resp, content = http.request(orthanc['Url'] + uri, 'DELETE', headers = headers)
152 return (resp, content)
153
154 def DoDelete(orthanc, uri, headers = {}):
155 (resp, content) = DoDeleteRaw(orthanc, uri, headers)
155 if not (resp.status in [ 200 ]): 156 if not (resp.status in [ 200 ]):
156 raise Exception(resp.status, resp) 157 raise Exception(resp.status, resp)
157 else: 158 else:
158 return _DecodeJson(content) 159 return _DecodeJson(content)
159 160
160 def DoPut(orthanc, uri, data = {}, contentType = ''): 161 def DoPutRaw(orthanc, uri, data = {}, contentType = '', headers = {}):
161 return _DoPutOrPost(orthanc, uri, 'PUT', data, contentType, {}) 162 return _DoPutOrPost(orthanc, uri, 'PUT', data, contentType, headers)
162 163
164 def DoPut(orthanc, uri, data = {}, contentType = '', headers = {}):
165 (resp, content) = DoPutRaw(orthanc, uri, data, contentType, headers)
166 if not (resp.status in [ 200, 201, 302 ]):
167 raise Exception(resp.status, resp)
168 else:
169 return _DecodeJson(content)
170
171 def DoPostRaw(orthanc, uri, data = {}, contentType = '', headers = {}):
172 return _DoPutOrPost(orthanc, uri, 'POST', data, contentType, headers)
173
163 def DoPost(orthanc, uri, data = {}, contentType = '', headers = {}): 174 def DoPost(orthanc, uri, data = {}, contentType = '', headers = {}):
164 return _DoPutOrPost(orthanc, uri, 'POST', data, contentType, headers) 175 (resp, content) = DoPostRaw(orthanc, uri, data, contentType, headers)
176 if not (resp.status in [ 200, 201, 302 ]):
177 raise Exception(resp.status, resp)
178 else:
179 return _DecodeJson(content)
165 180
166 def GetDatabasePath(filename): 181 def GetDatabasePath(filename):
167 return os.path.join(os.path.dirname(__file__), '..', 'Database', filename) 182 return os.path.join(os.path.dirname(__file__), '..', 'Database', filename)
168 183
169 def UploadInstance(orthanc, filename): 184 def UploadInstance(orthanc, filename):