comparison Tests/Toolbox.py @ 342:bf8369ea3ff1

more tests of webdav
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 15 Oct 2020 17:34:01 +0200
parents 66a36befb208
children 79ce0f7a9714
comparison
equal deleted inserted replaced
341:66a36befb208 342:bf8369ea3ff1
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, 302 ]): 144 if not (resp.status in [ 200, 201, 302 ]):
145 raise Exception(resp.status, resp) 145 raise Exception(resp.status, resp)
146 else: 146 else:
147 return _DecodeJson(content) 147 return _DecodeJson(content)
148 148
149 def DoDelete(orthanc, uri): 149 def DoDelete(orthanc, uri):
239 239
240 def WaitEmpty(orthanc): 240 def WaitEmpty(orthanc):
241 while True: 241 while True:
242 if len(DoGet(orthanc, '/instances')) == 0: 242 if len(DoGet(orthanc, '/instances')) == 0:
243 return 243 return
244 time.sleep(0.1) 244 time.sleep(0.01)
245 245
246 def WaitJobDone(orthanc, job): 246 def WaitJobDone(orthanc, job):
247 while True: 247 while True:
248 s = DoGet(orthanc, '/jobs/%s' % job) ['State'] 248 s = DoGet(orthanc, '/jobs/%s' % job) ['State']
249 249
250 if s == 'Success': 250 if s == 'Success':
251 return True 251 return True
252 elif s == 'Failure': 252 elif s == 'Failure':
253 return False 253 return False
254 254
255 time.sleep(0.1) 255 time.sleep(0.01)
256 256
257 def MonitorJob(orthanc, func): # "func" is a lambda 257 def MonitorJob(orthanc, func): # "func" is a lambda
258 a = set(DoGet(orthanc, '/jobs')) 258 a = set(DoGet(orthanc, '/jobs'))
259 func() 259 func()
260 b = set(DoGet(orthanc, '/jobs')) 260 b = set(DoGet(orthanc, '/jobs'))
477 prop = k 477 prop = k
478 else: 478 else:
479 raise Exception() 479 raise Exception()
480 if href == None or prop == None: 480 if href == None or prop == None:
481 raise Exception() 481 raise Exception()
482 result[href] = prop 482
483 info = {}
484
485 for j in prop.childNodes:
486 if j.nodeType == minidom.Node.ELEMENT_NODE:
487 if j.nodeName == 'D:displayname':
488 info['displayname'] = j.firstChild.nodeValue if j.firstChild != None else ''
489 elif j.nodeName == 'D:creationdate':
490 info['creationdate'] = j.firstChild.nodeValue
491 elif j.nodeName == 'D:getlastmodified':
492 info['lastmodified'] = j.firstChild.nodeValue
493 elif j.nodeName == 'D:resourcetype':
494 k = j.getElementsByTagName('D:collection')
495 info['folder'] = (len(k) == 1)
496
497 result[href] = info
483 elif i.nodeType != minidom.Node.TEXT_NODE: 498 elif i.nodeType != minidom.Node.TEXT_NODE:
484 raise Exception() 499 raise Exception()
485 500
486 return result 501 return result