annotate Plugins/WebDav/Run.py @ 620:8ba9b20ae95f debug-pg-transactions

debug pg transactions tests
author Alain Mazy <am@osimis.io>
date Mon, 05 Feb 2024 22:32:39 +0100
parents 61e8cf2d78fd
children 9f8276ac1cdd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
610
ec657d1a62a6 fix compatibility with python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1 #!/usr/bin/python3
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
511
933fe1bbce4f upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 449
diff changeset
6 # Copyright (C) 2017-2023 Osimis S.A., Belgium
933fe1bbce4f upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 449
diff changeset
7 # Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 #
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # This program is free software: you can redistribute it and/or
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # modify it under the terms of the GNU General Public License as
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # published by the Free Software Foundation, either version 3 of the
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # License, or (at your option) any later version.
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 #
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # This program is distributed in the hope that it will be useful, but
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # General Public License for more details.
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 #
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # You should have received a copy of the GNU General Public License
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
614
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
23 # Note about easywebdav: This test is compatible with version 1.2.0 of
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
24 # the "python3-easywebdav" package in Ubuntu/Debian. Beware that this
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
25 # package includes a patch that is not available in the upstream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
26 # version of easywebdav:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
27 # https://salsa.debian.org/python-team/packages/python-easywebdav/-/blob/master/debian/patches/python3.patch
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 import argparse
614
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 613
diff changeset
30 import easywebdav
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 import io
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 import os
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 import pprint
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 import re
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 import sys
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 import unittest
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
339
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
38 # https://stackoverflow.com/a/49336105/881731
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
39 if ((3, 0) <= sys.version_info <= (3, 9)):
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
40 from urllib.parse import unquote
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
41 elif ((2, 0) <= sys.version_info <= (2, 9)):
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
42 from urlparse import unquote
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
43
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests'))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 from Toolbox import *
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 ##
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ## Parse the command-line arguments
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 ##
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
375
08fac54c8555 CheckDicomTls.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 363
diff changeset
52 parser = argparse.ArgumentParser(description = 'Run the integration tests for the WebDAV server.')
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 parser.add_argument('--server',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 default = 'localhost',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 help = 'Address of the Orthanc server to test')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 parser.add_argument('--rest',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 type = int,
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 default = 8042,
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 help = 'Port to the REST API')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 parser.add_argument('--username',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 default = 'alice',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 help = 'Username to the REST API')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 parser.add_argument('--password',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 default = 'orthanctest',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 help = 'Password to the REST API')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 parser.add_argument('--force', help = 'Do not warn the user',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 action = 'store_true')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 parser.add_argument('options', metavar = 'N', nargs = '*',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 help='Arguments to Python unittest')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 args = parser.parse_args()
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ##
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ## Configure the testing context
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 ##
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if not args.force:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 print("""
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 WARNING: This test will remove all the content of your
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 Orthanc instance running on %s!
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 Are you sure ["yes" to go on]?""" % args.server)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 if sys.stdin.readline().strip() != 'yes':
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 print('Aborting...')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 exit(0)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 ORTHANC = DefineOrthanc(server = args.server,
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 username = args.username,
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 password = args.password,
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 restPort = args.rest)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 WEBDAV = easywebdav.connect(args.server,
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 port = args.rest,
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 username = args.username,
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 password = args.password)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 ##
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 ## The tests
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 ##
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 def ListFiles(path, recursive):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 result = [ ]
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 for i in WEBDAV.ls(path):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 if i.name == path:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 pass
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 elif i.contenttype == '':
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 if recursive:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 result += ListFiles(i.name + '/', True)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 else:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 result.append(i.name)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 return result
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 def GetFileInfo(path):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 for i in WEBDAV.ls(path[0 : path.rfind('/')]):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 if i.name == path:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 return i
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 raise Exception('Cannot find: %s' % path)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 def DownloadFile(path):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 with tempfile.NamedTemporaryFile(delete = False) as f:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 f.close()
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 WEBDAV.download(path, f.name)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 with open(f.name, 'rb') as g:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 result = g.read()
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 os.unlink(f.name)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 return result
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 class Orthanc(unittest.TestCase):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 def setUp(self):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 if (sys.version_info >= (3, 0)):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 # Remove annoying warnings about unclosed socket in Python 3
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 import warnings
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 warnings.simplefilter("ignore", ResourceWarning)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 DropOrthanc(ORTHANC)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 def test_root(self):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 self.assertEqual(6, len(WEBDAV.ls('/webdav/')))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 for i in WEBDAV.ls('/webdav/'):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 self.assertTrue(i.name in [
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 '/webdav/',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 '/webdav/by-dates',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 '/webdav/by-patients',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 '/webdav/by-studies',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 '/webdav/by-uids',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 '/webdav/uploads'
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 ])
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 self.assertEqual(0, i.size)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 self.assertEqual('', i.contenttype)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 patients = WEBDAV.ls('/webdav/by-patients/')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 self.assertEqual(1, len(patients))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 self.assertEqual(patients[0].name, '/webdav/by-patients/')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 self.assertEqual(0, patients[0].size)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 self.assertEqual('', patients[0].contenttype)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
342
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
167 self.assertRaises(Exception, lambda: WEBDAV.delete('/webdav/nope'))
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
168 self.assertRaises(Exception, lambda: WEBDAV.delete('/webdav/by-uids'))
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
169
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 def test_upload(self):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 self.assertEqual(0, len(ListFiles('/webdav/uploads/', True)))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 uploads = WEBDAV.ls('/webdav/uploads/')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 for i in uploads:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 self.assertEqual(i.contenttype, '') # Only folders are allowed
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 self.assertEqual(0, len(DoGet(ORTHANC, '/studies')))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 WEBDAV.upload(GetDatabasePath('DummyCT.dcm'), '/webdav/uploads/DummyCT.dcm')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 while len(ListFiles('/webdav/uploads/', True)) > 1:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 time.sleep(0.1)
343
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
183 time.sleep(0.1) # Give some more delay to be sure that the store has succeeded (necessary for Wine)
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 instances = DoGet(ORTHANC, '/instances?expand')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 self.assertEqual(1, len(instances))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109',
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 instances[0]['MainDicomTags']['SOPInstanceUID'])
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 def test_upload_folders(self):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 self.assertEqual(0, len(ListFiles('/webdav/uploads/', True)))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 self.assertEqual(0, len(DoGet(ORTHANC, '/studies')))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 try:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 WEBDAV.mkdir('/webdav/uploads/a')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 except:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 pass
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 try:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 WEBDAV.mkdir('/webdav/uploads/b')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 except:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 pass
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 WEBDAV.upload(GetDatabasePath('DummyCT.dcm'), '/webdav/uploads/a/DummyCT.dcm')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 WEBDAV.upload(GetDatabasePath('ColorTestMalaterre.dcm'), '/webdav/uploads/b/ColorTestMalaterre.dcm')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 while len(ListFiles('/webdav/uploads/', True)) > 1:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 time.sleep(0.1)
343
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 342
diff changeset
209 time.sleep(0.1) # Give some more delay to be sure that the store has succeeded (necessary for Wine)
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 self.assertEqual(2, len(DoGet(ORTHANC, '/instances')))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 def test_by_uids(self):
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 self.assertEqual(1, len(WEBDAV.ls('/webdav/by-uids/')))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', True)))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID']
339
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
220 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
221 studyUid = tags['StudyInstanceUID']
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
222 seriesUid = tags['SeriesInstanceUID']
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
223 sopUid = tags['SOPInstanceUID']
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', False)))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 self.assertEqual(1, len(ListFiles('/webdav/by-uids/%s/' % studyUid, False)))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 self.assertEqual(2, len(ListFiles('/webdav/by-uids/%s/%s/' % (studyUid, seriesUid), False)))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 content = ListFiles('/webdav/by-uids/', True)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 self.assertEqual(3, len(content))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 self.assertTrue(('/webdav/by-uids/%s/study.json' % studyUid) in content)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 self.assertTrue(('/webdav/by-uids/%s/%s/series.json' % (studyUid, seriesUid)) in content)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 self.assertTrue(('/webdav/by-uids/%s/%s/%s.dcm' % (studyUid, seriesUid, sopUid)) in content)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
342
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
235 # Deleting the virtual files "study|series.json" has no
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
236 # effect, but is needed for recursive DELETE in some file explorers
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
237 WEBDAV.delete('/webdav/by-uids/%s/study.json' % studyUid)
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
238 WEBDAV.delete('/webdav/by-uids/%s/%s/series.json' % (studyUid, seriesUid))
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
239
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 info = GetFileInfo('/webdav/by-uids/%s/study.json' % studyUid)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 self.assertEqual(info.contenttype, 'application/json')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 info = GetFileInfo('/webdav/by-uids/%s/%s/series.json' % (studyUid, seriesUid))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 self.assertEqual(info.contenttype, 'application/json')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 info = GetFileInfo('/webdav/by-uids/%s/%s/%s.dcm' % (studyUid, seriesUid, sopUid))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 self.assertEqual(info.contenttype, 'application/dicom')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 self.assertEqual(info.size, os.stat(GetDatabasePath('DummyCT.dcm')).st_size)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 a = DownloadFile('/webdav/by-uids/%s/%s/%s.dcm' % (studyUid, seriesUid, sopUid))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 self.assertEqual(len(a), info.size)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 self.assertEqual(a, f.read())
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 self.assertEqual(studyUid, json.loads(DownloadFile('/webdav/by-uids/%s/study.json' % studyUid))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 ['MainDicomTags']['StudyInstanceUID'])
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 self.assertEqual(seriesUid, json.loads(DownloadFile('/webdav/by-uids/%s/%s/series.json' % (studyUid, seriesUid)))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 ['MainDicomTags']['SeriesInstanceUID'])
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 WEBDAV.delete('/webdav/by-uids/%s/%s/%s.dcm' % (studyUid, seriesUid, sopUid))
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
339
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
265 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
266
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
267
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
268 def test_by_patients(self):
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
269 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
270 self.assertEqual(0, len(ListFiles('/webdav/by-patients/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
271 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
272 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
273
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
274 self.assertEqual(1, len(WEBDAV.ls('/webdav/by-patients/')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
275 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
276
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
277 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID']
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
278 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
279 patient = '%s - %s' % (tags['PatientID'], tags['PatientName'])
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
280 study = '%s - %s' % (tags['StudyDate'], tags['StudyDescription'])
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
281 series = '%s - %s' % (tags['Modality'], tags['SeriesDescription'])
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
282 self.assertEqual('ozp00SjY2xG - KNIX', patient)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
283 self.assertEqual('20070101 - Knee (R)', study)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
284 self.assertEqual('MR - AX. FSE PD', series)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
285
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
286 self.assertEqual(1, len(ListFiles('/webdav/by-dates/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
287 self.assertEqual(1, len(ListFiles('/webdav/by-patients/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
288 self.assertEqual(1, len(ListFiles('/webdav/by-studies/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
289 self.assertEqual(3, len(ListFiles('/webdav/by-uids/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
290
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
291 self.assertEqual(0, len(ListFiles('/webdav/by-patients/', False)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
292 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-patients/')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
293 self.assertEqual(0, len(ListFiles('/webdav/by-patients/%s' % patient, False)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
294 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-patients/%s' % patient)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
295 self.assertEqual(0, len(ListFiles('/webdav/by-patients/%s/%s' % (patient, study), False)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
296 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-patients/%s/%s' % (patient, study))))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
297
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
298 folder = '/webdav/by-patients/%s/%s/%s' % (patient, study, series)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
299 self.assertEqual(1, len(ListFiles(folder, False)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
300 self.assertEqual(2, len(WEBDAV.ls(folder)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
301 self.assertEqual('%s/%s.dcm' % (folder, i), unquote(ListFiles(folder, False) [0]))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
302
340
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
303 files = ListFiles('/webdav/by-patients/', True)
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
304 self.assertEqual(1, len(files))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
305 self.assertEqual('%s/%s.dcm' % (folder, i), unquote(files[0]))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
306
339
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
307 a = DownloadFile('%s/%s.dcm' % (folder, i))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
308 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f:
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
309 self.assertEqual(a, f.read())
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
310
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
311 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
312 WEBDAV.delete('%s/%s.dcm' % (folder, i))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
313 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
314
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
315 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
316 self.assertEqual(0, len(ListFiles('/webdav/by-patients/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
317 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
318 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
319
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
320
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
321 def test_by_studies(self):
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
322 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
323 self.assertEqual(1, len(WEBDAV.ls('/webdav/by-patients/')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
324 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
325
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
326 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID']
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
327 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
328 study = '%s - %s - %s' % (tags['PatientID'], tags['PatientName'], tags['StudyDescription'])
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
329 series = '%s - %s' % (tags['Modality'], tags['SeriesDescription'])
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
330 self.assertEqual('ozp00SjY2xG - KNIX - Knee (R)', study)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
331 self.assertEqual('MR - AX. FSE PD', series)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
332
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
333 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', False)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
334 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-studies/')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
335 self.assertEqual(0, len(ListFiles('/webdav/by-studies/%s' % study, False)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
336 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-studies/%s' % study)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
337
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
338 folder = '/webdav/by-studies/%s/%s' % (study, series)
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
339 self.assertEqual(1, len(ListFiles(folder, False)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
340 self.assertEqual(2, len(WEBDAV.ls(folder)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
341 self.assertEqual('%s/%s.dcm' % (folder, i), unquote(ListFiles(folder, False) [0]))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
342
340
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
343 files = ListFiles('/webdav/by-studies/', True)
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
344 self.assertEqual(1, len(files))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
345 self.assertEqual('%s/%s.dcm' % (folder, i), unquote(files[0]))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
346
339
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
347 a = DownloadFile('%s/%s.dcm' % (folder, i))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
348 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f:
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
349 self.assertEqual(a, f.read())
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
350
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
351 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
352 WEBDAV.delete('%s/%s.dcm' % (folder, i))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
353 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
354 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', True)))
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
355
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
356
340
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
357 def test_by_dates(self):
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
358 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True)))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
359 self.assertEqual(1, len(WEBDAV.ls('/webdav/by-patients/')))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
360 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
361
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
362 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID']
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
363 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i)
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
364 year = tags['StudyDate'][0:4]
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
365 month = tags['StudyDate'][4:6]
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
366 study = '%s - %s - %s' % (tags['PatientID'], tags['PatientName'], tags['StudyDescription'])
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
367 series = '%s - %s' % (tags['Modality'], tags['SeriesDescription'])
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
368 self.assertEqual('ozp00SjY2xG - KNIX - Knee (R)', study)
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
369 self.assertEqual('MR - AX. FSE PD', series)
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
370
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
371 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', False)))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
372 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-dates/')))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
373 self.assertEqual(0, len(ListFiles('/webdav/by-dates/%s' % year, False)))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
374 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-dates/%s' % year)))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
375 self.assertEqual(0, len(ListFiles('/webdav/by-dates/%s/%s-%s' % (year, year, month), False)))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
376 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-dates/%s/%s-%s' % (year, year, month))))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
377
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
378 folder = '/webdav/by-dates/%s/%s-%s/%s/%s' % (year, year, month, study, series)
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
379 self.assertEqual(1, len(ListFiles(folder, False)))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
380 self.assertEqual(2, len(WEBDAV.ls(folder)))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
381 self.assertEqual('%s/%s.dcm' % (folder, i), unquote(ListFiles(folder, False) [0]))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
382
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
383 files = ListFiles('/webdav/by-dates/', True)
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
384 self.assertEqual(1, len(files))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
385 self.assertEqual('%s/%s.dcm' % (folder, i), unquote(files[0]))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
386
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
387 a = DownloadFile('%s/%s.dcm' % (folder, i))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
388 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f:
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
389 self.assertEqual(a, f.read())
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
390
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
391 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
392 WEBDAV.delete('%s/%s.dcm' % (folder, i))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
393 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
60775134a406 finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 339
diff changeset
394 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True)))
339
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
395
342
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
396
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
397 def test_delete_folder(self):
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
398 # These deletes should have no effect
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
399 UploadInstance(ORTHANC, 'DummyCT.dcm')
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
400 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
401 WEBDAV.delete('/webdav/by-uids/1.2.840.113619.2.176.2025.1499492.7391.1171285944.390/study.json')
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
402 WEBDAV.delete('/webdav/by-uids/1.2.840.113619.2.176.2025.1499492.7391.1171285944.390/1.2.840.113619.2.176.2025.1499492.7391.1171285944.394/series.json')
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
403 WEBDAV.delete('/webdav/by-dates/2007/2007-02')
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
404 WEBDAV.delete('/webdav/by-dates/2006')
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
405 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
406
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
407 for path in [
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
408 '/webdav/by-uids/1.2.840.113619.2.176.2025.1499492.7391.1171285944.390/1.2.840.113619.2.176.2025.1499492.7391.1171285944.394/1.2.840.113619.2.176.2025.1499492.7040.1171286242.109.dcm',
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
409 '/webdav/by-patients/ozp00SjY2xG - KNIX/20070101 - Knee (R)/MR - AX. FSE PD/66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d.dcm',
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
410 '/webdav/by-studies/ozp00SjY2xG - KNIX - Knee (R)/MR - AX. FSE PD/66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d.dcm',
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
411 '/webdav/by-dates/2007/2007-01/ozp00SjY2xG - KNIX - Knee (R)/MR - AX. FSE PD/66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d.dcm',
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
412 ]:
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
413 tokens = path.split('/')
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
414 for i in range(4, len(tokens) + 1):
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
415 p = '/'.join(tokens[0:i])
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
416 UploadInstance(ORTHANC, 'DummyCT.dcm')
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
417 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
418 WEBDAV.delete(p)
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
419 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
bf8369ea3ff1 more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 340
diff changeset
420
358
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
421
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
422 def test_upload_zip(self):
610
ec657d1a62a6 fix compatibility with python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
423 f = BytesIO()
358
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
424 with zipfile.ZipFile(f, 'w') as z:
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
425 z.writestr('hello/world/invalid.txt', 'Hello world')
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
426 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as g:
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
427 c = g.read()
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
428 z.writestr('hello/world/dicom1.dcm', c)
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
429 z.writestr('hello/world/dicom2.dcm', c)
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
430
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
431 f.seek(0)
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
432 archive = f.read()
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
433
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
434 self.assertEqual(0, len(DoGet(ORTHANC, '/studies')))
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
435
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
436 with tempfile.NamedTemporaryFile(delete = True) as f:
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
437 f.close()
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
438 with open(f.name, 'wb') as g:
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
439 g.write(archive)
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
440 WEBDAV.upload(f.name, '/webdav/uploads/DummyCT.zip')
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
441 os.unlink(f.name)
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
442
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
443 while len(ListFiles('/webdav/uploads/', True)) > 1:
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
444 time.sleep(0.1)
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
445 time.sleep(0.1) # Give some more delay to be sure that the store has succeeded (necessary for Wine)
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
446
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
447 instances = DoGet(ORTHANC, '/instances')
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
448 self.assertEqual(1, len(instances))
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
449 self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', instances[0])
458b2d887ea0 WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 343
diff changeset
450
339
44ab919be2e9 cont webdav tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 338
diff changeset
451
338
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 try:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 print('\nStarting the tests...')
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 unittest.main(argv = [ sys.argv[0] ] + args.options)
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 finally:
edaeb57bf01f creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 print('\nDone')