Mercurial > hg > orthanc-tests
annotate Plugins/WebDav/Run.py @ 520:a06d0a45c62f
Python 3 compatibility of GenerateConfigurationForTests.py
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 Apr 2023 10:48:04 +0200 |
parents | 933fe1bbce4f |
children | ec657d1a62a6 |
rev | line source |
---|---|
338
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
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 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import argparse |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 import easywebdav |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import io |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import os |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 import pprint |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 import re |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 import sys |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 import unittest |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
339 | 33 # https://stackoverflow.com/a/49336105/881731 |
34 if ((3, 0) <= sys.version_info <= (3, 9)): | |
35 from urllib.parse import unquote | |
36 elif ((2, 0) <= sys.version_info <= (2, 9)): | |
37 from urlparse import unquote | |
38 | |
338
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 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
|
40 from Toolbox import * |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 ## |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 ## Parse the command-line arguments |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 ## |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
375 | 47 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
|
48 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 parser.add_argument('--server', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 default = 'localhost', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 help = 'Address of the Orthanc server to test') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 parser.add_argument('--rest', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 type = int, |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 default = 8042, |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 help = 'Port to the REST API') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 parser.add_argument('--username', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 default = 'alice', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 help = 'Username to the REST API') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 parser.add_argument('--password', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 default = 'orthanctest', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 help = 'Password to the REST API') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 parser.add_argument('--force', help = 'Do not warn the user', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 action = 'store_true') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 parser.add_argument('options', metavar = 'N', nargs = '*', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 help='Arguments to Python unittest') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 args = parser.parse_args() |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 ## |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 ## Configure the testing context |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 ## |
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 if not args.force: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 print(""" |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 WARNING: This test will remove all the content of your |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 Orthanc instance running on %s! |
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 Are you sure ["yes" to go on]?""" % args.server) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 if sys.stdin.readline().strip() != 'yes': |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 print('Aborting...') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 exit(0) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
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 ORTHANC = DefineOrthanc(server = args.server, |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 username = args.username, |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 password = args.password, |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 restPort = args.rest) |
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 WEBDAV = easywebdav.connect(args.server, |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 port = args.rest, |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 username = args.username, |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 password = args.password) |
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 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 ## |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 ## The tests |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 ## |
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 def ListFiles(path, recursive): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 result = [ ] |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 for i in WEBDAV.ls(path): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 if i.name == path: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 pass |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 elif i.contenttype == '': |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 if recursive: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 result += ListFiles(i.name + '/', True) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 else: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 result.append(i.name) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 return result |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 def GetFileInfo(path): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 for i in WEBDAV.ls(path[0 : path.rfind('/')]): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 if i.name == path: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 return i |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 raise Exception('Cannot find: %s' % path) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 def DownloadFile(path): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 with tempfile.NamedTemporaryFile(delete = False) as f: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 f.close() |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 WEBDAV.download(path, f.name) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 with open(f.name, 'rb') as g: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 result = g.read() |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 os.unlink(f.name) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 return result |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 class Orthanc(unittest.TestCase): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 def setUp(self): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 if (sys.version_info >= (3, 0)): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 # Remove annoying warnings about unclosed socket in Python 3 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 import warnings |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 warnings.simplefilter("ignore", ResourceWarning) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 DropOrthanc(ORTHANC) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 def test_root(self): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 self.assertEqual(6, len(WEBDAV.ls('/webdav/'))) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 for i in WEBDAV.ls('/webdav/'): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 self.assertTrue(i.name in [ |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 '/webdav/', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 '/webdav/by-dates', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 '/webdav/by-patients', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 '/webdav/by-studies', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 '/webdav/by-uids', |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 '/webdav/uploads' |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 ]) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 self.assertEqual(0, i.size) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 self.assertEqual('', i.contenttype) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 patients = WEBDAV.ls('/webdav/by-patients/') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 self.assertEqual(1, len(patients)) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 self.assertEqual(patients[0].name, '/webdav/by-patients/') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 self.assertEqual(0, patients[0].size) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 self.assertEqual('', patients[0].contenttype) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 |
342
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
162 self.assertRaises(Exception, lambda: WEBDAV.delete('/webdav/nope')) |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
163 self.assertRaises(Exception, lambda: WEBDAV.delete('/webdav/by-uids')) |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
164 |
338
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 def test_upload(self): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 self.assertEqual(0, len(ListFiles('/webdav/uploads/', True))) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 uploads = WEBDAV.ls('/webdav/uploads/') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 for i in uploads: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 self.assertEqual(i.contenttype, '') # Only folders are allowed |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 self.assertEqual(0, len(DoGet(ORTHANC, '/studies'))) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 WEBDAV.upload(GetDatabasePath('DummyCT.dcm'), '/webdav/uploads/DummyCT.dcm') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 while len(ListFiles('/webdav/uploads/', True)) > 1: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 time.sleep(0.1) |
343 | 178 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
|
179 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 instances = DoGet(ORTHANC, '/instances?expand') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 self.assertEqual(1, len(instances)) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 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
|
183 instances[0]['MainDicomTags']['SOPInstanceUID']) |
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 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 def test_upload_folders(self): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 self.assertEqual(0, len(ListFiles('/webdav/uploads/', True))) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 self.assertEqual(0, len(DoGet(ORTHANC, '/studies'))) |
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 try: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 WEBDAV.mkdir('/webdav/uploads/a') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 except: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 pass |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 try: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 WEBDAV.mkdir('/webdav/uploads/b') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 except: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 pass |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 WEBDAV.upload(GetDatabasePath('DummyCT.dcm'), '/webdav/uploads/a/DummyCT.dcm') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 WEBDAV.upload(GetDatabasePath('ColorTestMalaterre.dcm'), '/webdav/uploads/b/ColorTestMalaterre.dcm') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 while len(ListFiles('/webdav/uploads/', True)) > 1: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 time.sleep(0.1) |
343 | 204 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
|
205 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 self.assertEqual(2, len(DoGet(ORTHANC, '/instances'))) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 def test_by_uids(self): |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 self.assertEqual(1, len(WEBDAV.ls('/webdav/by-uids/'))) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', True))) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) |
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 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID'] |
339 | 215 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) |
216 studyUid = tags['StudyInstanceUID'] | |
217 seriesUid = tags['SeriesInstanceUID'] | |
218 sopUid = tags['SOPInstanceUID'] | |
338
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', False))) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 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
|
222 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
|
223 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 content = ListFiles('/webdav/by-uids/', True) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 self.assertEqual(3, len(content)) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 |
342
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
230 # Deleting the virtual files "study|series.json" has no |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
231 # 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
|
232 WEBDAV.delete('/webdav/by-uids/%s/study.json' % studyUid) |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
233 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
|
234 |
338
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 info = GetFileInfo('/webdav/by-uids/%s/study.json' % studyUid) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 self.assertEqual(info.contenttype, 'application/json') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 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
|
239 self.assertEqual(info.contenttype, 'application/json') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 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
|
242 self.assertEqual(info.contenttype, 'application/dicom') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 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
|
244 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 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
|
246 self.assertEqual(len(a), info.size) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 self.assertEqual(a, f.read()) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 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
|
252 ['MainDicomTags']['StudyInstanceUID']) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 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
|
255 ['MainDicomTags']['SeriesInstanceUID']) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 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
|
259 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) |
339 | 260 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', True))) |
261 | |
262 | |
263 def test_by_patients(self): | |
264 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True))) | |
265 self.assertEqual(0, len(ListFiles('/webdav/by-patients/', True))) | |
266 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', True))) | |
267 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', True))) | |
268 | |
269 self.assertEqual(1, len(WEBDAV.ls('/webdav/by-patients/'))) | |
270 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) | |
271 | |
272 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID'] | |
273 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) | |
274 patient = '%s - %s' % (tags['PatientID'], tags['PatientName']) | |
275 study = '%s - %s' % (tags['StudyDate'], tags['StudyDescription']) | |
276 series = '%s - %s' % (tags['Modality'], tags['SeriesDescription']) | |
277 self.assertEqual('ozp00SjY2xG - KNIX', patient) | |
278 self.assertEqual('20070101 - Knee (R)', study) | |
279 self.assertEqual('MR - AX. FSE PD', series) | |
280 | |
281 self.assertEqual(1, len(ListFiles('/webdav/by-dates/', True))) | |
282 self.assertEqual(1, len(ListFiles('/webdav/by-patients/', True))) | |
283 self.assertEqual(1, len(ListFiles('/webdav/by-studies/', True))) | |
284 self.assertEqual(3, len(ListFiles('/webdav/by-uids/', True))) | |
285 | |
286 self.assertEqual(0, len(ListFiles('/webdav/by-patients/', False))) | |
287 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-patients/'))) | |
288 self.assertEqual(0, len(ListFiles('/webdav/by-patients/%s' % patient, False))) | |
289 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-patients/%s' % patient))) | |
290 self.assertEqual(0, len(ListFiles('/webdav/by-patients/%s/%s' % (patient, study), False))) | |
291 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-patients/%s/%s' % (patient, study)))) | |
292 | |
293 folder = '/webdav/by-patients/%s/%s/%s' % (patient, study, series) | |
294 self.assertEqual(1, len(ListFiles(folder, False))) | |
295 self.assertEqual(2, len(WEBDAV.ls(folder))) | |
296 self.assertEqual('%s/%s.dcm' % (folder, i), unquote(ListFiles(folder, False) [0])) | |
297 | |
340
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
298 files = ListFiles('/webdav/by-patients/', True) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
299 self.assertEqual(1, len(files)) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
300 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
|
301 |
339 | 302 a = DownloadFile('%s/%s.dcm' % (folder, i)) |
303 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f: | |
304 self.assertEqual(a, f.read()) | |
305 | |
306 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) | |
307 WEBDAV.delete('%s/%s.dcm' % (folder, i)) | |
308 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) | |
309 | |
310 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True))) | |
311 self.assertEqual(0, len(ListFiles('/webdav/by-patients/', True))) | |
312 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', True))) | |
313 self.assertEqual(0, len(ListFiles('/webdav/by-uids/', True))) | |
314 | |
315 | |
316 def test_by_studies(self): | |
317 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', True))) | |
318 self.assertEqual(1, len(WEBDAV.ls('/webdav/by-patients/'))) | |
319 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) | |
320 | |
321 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID'] | |
322 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) | |
323 study = '%s - %s - %s' % (tags['PatientID'], tags['PatientName'], tags['StudyDescription']) | |
324 series = '%s - %s' % (tags['Modality'], tags['SeriesDescription']) | |
325 self.assertEqual('ozp00SjY2xG - KNIX - Knee (R)', study) | |
326 self.assertEqual('MR - AX. FSE PD', series) | |
327 | |
328 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', False))) | |
329 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-studies/'))) | |
330 self.assertEqual(0, len(ListFiles('/webdav/by-studies/%s' % study, False))) | |
331 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-studies/%s' % study))) | |
332 | |
333 folder = '/webdav/by-studies/%s/%s' % (study, series) | |
334 self.assertEqual(1, len(ListFiles(folder, False))) | |
335 self.assertEqual(2, len(WEBDAV.ls(folder))) | |
336 self.assertEqual('%s/%s.dcm' % (folder, i), unquote(ListFiles(folder, False) [0])) | |
337 | |
340
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
338 files = ListFiles('/webdav/by-studies/', True) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
339 self.assertEqual(1, len(files)) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
340 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
|
341 |
339 | 342 a = DownloadFile('%s/%s.dcm' % (folder, i)) |
343 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f: | |
344 self.assertEqual(a, f.read()) | |
345 | |
346 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) | |
347 WEBDAV.delete('%s/%s.dcm' % (folder, i)) | |
348 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) | |
349 self.assertEqual(0, len(ListFiles('/webdav/by-studies/', True))) | |
350 | |
351 | |
340
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
352 def test_by_dates(self): |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
353 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True))) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
354 self.assertEqual(1, len(WEBDAV.ls('/webdav/by-patients/'))) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
355 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
356 |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
357 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID'] |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
358 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
359 year = tags['StudyDate'][0:4] |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
360 month = tags['StudyDate'][4:6] |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
361 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
|
362 series = '%s - %s' % (tags['Modality'], tags['SeriesDescription']) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
363 self.assertEqual('ozp00SjY2xG - KNIX - Knee (R)', study) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
364 self.assertEqual('MR - AX. FSE PD', series) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
365 |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
366 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', False))) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
367 self.assertEqual(2, len(WEBDAV.ls('/webdav/by-dates/'))) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 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
|
372 |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
373 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
|
374 self.assertEqual(1, len(ListFiles(folder, False))) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
375 self.assertEqual(2, len(WEBDAV.ls(folder))) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
376 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
|
377 |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
378 files = ListFiles('/webdav/by-dates/', True) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
379 self.assertEqual(1, len(files)) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
380 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
|
381 |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
382 a = DownloadFile('%s/%s.dcm' % (folder, i)) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
383 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as f: |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
384 self.assertEqual(a, f.read()) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
385 |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
386 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
387 WEBDAV.delete('%s/%s.dcm' % (folder, i)) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
388 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) |
60775134a406
finalized webdav standalone tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
339
diff
changeset
|
389 self.assertEqual(0, len(ListFiles('/webdav/by-dates/', True))) |
339 | 390 |
342
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
391 |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
392 def test_delete_folder(self): |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
393 # These deletes should have no effect |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
394 UploadInstance(ORTHANC, 'DummyCT.dcm') |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
395 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
396 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
|
397 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
|
398 WEBDAV.delete('/webdav/by-dates/2007/2007-02') |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
399 WEBDAV.delete('/webdav/by-dates/2006') |
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 |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
402 for path in [ |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
403 '/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
|
404 '/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
|
405 '/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
|
406 '/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
|
407 ]: |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
408 tokens = path.split('/') |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
409 for i in range(4, len(tokens) + 1): |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
410 p = '/'.join(tokens[0:i]) |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
411 UploadInstance(ORTHANC, 'DummyCT.dcm') |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
412 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
413 WEBDAV.delete(p) |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
414 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
340
diff
changeset
|
415 |
358
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
416 |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
417 def test_upload_zip(self): |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
418 f = StringIO() |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
419 with zipfile.ZipFile(f, 'w') as z: |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
420 z.writestr('hello/world/invalid.txt', 'Hello world') |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
421 with open(GetDatabasePath('DummyCT.dcm'), 'rb') as g: |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
422 c = g.read() |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
423 z.writestr('hello/world/dicom1.dcm', c) |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
424 z.writestr('hello/world/dicom2.dcm', c) |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
425 |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
426 f.seek(0) |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
427 archive = f.read() |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
428 |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
429 self.assertEqual(0, len(DoGet(ORTHANC, '/studies'))) |
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 with tempfile.NamedTemporaryFile(delete = True) as f: |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
432 f.close() |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
433 with open(f.name, 'wb') as g: |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
434 g.write(archive) |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
435 WEBDAV.upload(f.name, '/webdav/uploads/DummyCT.zip') |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
436 os.unlink(f.name) |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
437 |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
438 while len(ListFiles('/webdav/uploads/', True)) > 1: |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
439 time.sleep(0.1) |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
440 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
|
441 |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
442 instances = DoGet(ORTHANC, '/instances') |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
443 self.assertEqual(1, len(instances)) |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
444 self.assertEqual('66a662ce-7430e543-bad44d47-0dc5a943-ec7a538d', instances[0]) |
458b2d887ea0
WebDAV: test_upload_zip
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
343
diff
changeset
|
445 |
339 | 446 |
338
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
447 try: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
448 print('\nStarting the tests...') |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
449 unittest.main(argv = [ sys.argv[0] ] + args.options) |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
450 |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
451 finally: |
edaeb57bf01f
creating tests for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
452 print('\nDone') |