Mercurial > hg > orthanc-tests
changeset 341:66a36befb208
extending Toolbox.DoPropFind()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 14 Oct 2020 19:55:26 +0200 |
parents | 60775134a406 |
children | bf8369ea3ff1 |
files | Tests/Tests.py Tests/Toolbox.py |
diffstat | 2 files changed, 47 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Tests/Tests.py Wed Oct 14 17:57:38 2020 +0200 +++ b/Tests/Tests.py Wed Oct 14 19:55:26 2020 +0200 @@ -6018,9 +6018,12 @@ self.assertRaises(Exception, lambda: DoPropFind(_REMOTE, '/webdav/', 2)) xml = DoPropFind(_REMOTE, '/webdav/', 1) + pprint.pprint(xml.keys()) + print(xml['/webdav/'].toprettyxml()) + #print(xml.toprettyxml()) - for i in xml.getElementsByTagName('D:response'): - print(i.getElementsByTagName('D:href')[0].childNodes[0].data) + #for i in xml.getElementsByTagName('D:response'): + # print(i.getElementsByTagName('D:href')[0].childNodes[0].data) # print(i.getElementsByTagName('D:prop')[0].toprettyxml())
--- a/Tests/Toolbox.py Wed Oct 14 17:57:38 2020 +0200 +++ b/Tests/Toolbox.py Wed Oct 14 19:55:26 2020 +0200 @@ -43,9 +43,11 @@ from urllib.parse import urlencode from io import StringIO from io import BytesIO + from urllib.parse import unquote else: from urllib import urlencode + from urlparse import unquote # http://stackoverflow.com/a/1313868/881731 try: @@ -53,7 +55,7 @@ except: from StringIO import StringIO - + def _DecodeJson(s): t = s @@ -442,5 +444,43 @@ if not (resp.status in [ 207 ]): raise Exception(resp.status, resp) else: - return minidom.parseString(content) + xml = minidom.parseString(content) + + if (xml.documentElement.nodeName != 'D:multistatus' or + xml.documentElement.attributes['xmlns:D'].value != 'DAV:'): + raise Exception() + result = {} + + for i in xml.documentElement.childNodes: + if i.nodeType == minidom.Node.ELEMENT_NODE: + if i.nodeName != 'D:response': + raise Exception() + href = None + prop = None + for j in i.childNodes: + if j.nodeType == minidom.Node.ELEMENT_NODE: + if j.nodeName == 'D:href': + if href == None: + href = unquote(j.firstChild.nodeValue) + else: + raise Exception() + elif j.nodeName == 'D:propstat': + for k in j.childNodes: + if k.nodeName == 'D:status': + if k.firstChild.nodeValue != 'HTTP/1.1 200 OK': + raise Exception() + elif k.nodeType == minidom.Node.ELEMENT_NODE: + if (k.nodeName != 'D:prop' or + prop != None): + raise Exception() + prop = k + else: + raise Exception() + if href == None or prop == None: + raise Exception() + result[href] = prop + elif i.nodeType != minidom.Node.TEXT_NODE: + raise Exception() + + return result