Mercurial > hg > orthanc-tests
comparison Tests/Toolbox.py @ 398:9528e2a03d3c
adapt DICOMweb tests following fix of issue #196 (STOW-RS: Should return 200 only when successfully stored all instances)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 May 2021 18:59:08 +0200 |
parents | 227d9a932467 |
children | 931be0125954 |
comparison
equal
deleted
inserted
replaced
397:eb87ec525b53 | 398:9528e2a03d3c |
---|---|
54 from cStringIO import StringIO | 54 from cStringIO import StringIO |
55 except: | 55 except: |
56 from StringIO import StringIO | 56 from StringIO import StringIO |
57 | 57 |
58 | 58 |
59 def _DecodeJson(s): | 59 def DecodeJson(s): |
60 t = s | 60 t = s |
61 | 61 |
62 if (sys.version_info >= (3, 0)): | 62 if (sys.version_info >= (3, 0)): |
63 try: | 63 try: |
64 t = s.decode() | 64 t = s.decode() |
119 (resp, content) = DoGetRaw(orthanc, uri, data = data, body = body, headers = headers) | 119 (resp, content) = DoGetRaw(orthanc, uri, data = data, body = body, headers = headers) |
120 | 120 |
121 if not (resp.status in [ 200 ]): | 121 if not (resp.status in [ 200 ]): |
122 raise Exception(resp.status, resp) | 122 raise Exception(resp.status, resp) |
123 else: | 123 else: |
124 return _DecodeJson(content) | 124 return DecodeJson(content) |
125 | 125 |
126 def _DoPutOrPost(orthanc, uri, method, data, contentType, headers): | 126 def _DoPutOrPost(orthanc, uri, method, data, contentType, headers): |
127 http = httplib2.Http() | 127 http = httplib2.Http() |
128 http.follow_redirects = False | 128 http.follow_redirects = False |
129 _SetupCredentials(orthanc, http) | 129 _SetupCredentials(orthanc, http) |
154 def DoDelete(orthanc, uri, headers = {}): | 154 def DoDelete(orthanc, uri, headers = {}): |
155 (resp, content) = DoDeleteRaw(orthanc, uri, headers) | 155 (resp, content) = DoDeleteRaw(orthanc, uri, headers) |
156 if not (resp.status in [ 200 ]): | 156 if not (resp.status in [ 200 ]): |
157 raise Exception(resp.status, resp) | 157 raise Exception(resp.status, resp) |
158 else: | 158 else: |
159 return _DecodeJson(content) | 159 return DecodeJson(content) |
160 | 160 |
161 def DoPutRaw(orthanc, uri, data = {}, contentType = '', headers = {}): | 161 def DoPutRaw(orthanc, uri, data = {}, contentType = '', headers = {}): |
162 return _DoPutOrPost(orthanc, uri, 'PUT', data, contentType, headers) | 162 return _DoPutOrPost(orthanc, uri, 'PUT', data, contentType, headers) |
163 | 163 |
164 def DoPut(orthanc, uri, data = {}, contentType = '', headers = {}): | 164 def DoPut(orthanc, uri, data = {}, contentType = '', headers = {}): |
165 (resp, content) = DoPutRaw(orthanc, uri, data, contentType, headers) | 165 (resp, content) = DoPutRaw(orthanc, uri, data, contentType, headers) |
166 if not (resp.status in [ 200, 201, 302 ]): | 166 if not (resp.status in [ 200, 201, 302 ]): |
167 raise Exception(resp.status, resp) | 167 raise Exception(resp.status, resp) |
168 else: | 168 else: |
169 return _DecodeJson(content) | 169 return DecodeJson(content) |
170 | 170 |
171 def DoPostRaw(orthanc, uri, data = {}, contentType = '', headers = {}): | 171 def DoPostRaw(orthanc, uri, data = {}, contentType = '', headers = {}): |
172 return _DoPutOrPost(orthanc, uri, 'POST', data, contentType, headers) | 172 return _DoPutOrPost(orthanc, uri, 'POST', data, contentType, headers) |
173 | 173 |
174 def DoPost(orthanc, uri, data = {}, contentType = '', headers = {}): | 174 def DoPost(orthanc, uri, data = {}, contentType = '', headers = {}): |
175 (resp, content) = DoPostRaw(orthanc, uri, data, contentType, headers) | 175 (resp, content) = DoPostRaw(orthanc, uri, data, contentType, headers) |
176 if not (resp.status in [ 200, 201, 302 ]): | 176 if not (resp.status in [ 200, 201, 302 ]): |
177 raise Exception(resp.status, resp) | 177 raise Exception(resp.status, resp) |
178 else: | 178 else: |
179 return _DecodeJson(content) | 179 return DecodeJson(content) |
180 | 180 |
181 def GetDatabasePath(filename): | 181 def GetDatabasePath(filename): |
182 return os.path.join(os.path.dirname(__file__), '..', 'Database', filename) | 182 return os.path.join(os.path.dirname(__file__), '..', 'Database', filename) |
183 | 183 |
184 def UploadInstance(orthanc, filename): | 184 def UploadInstance(orthanc, filename): |