Mercurial > hg > orthanc-tests
comparison Tests/CheckIngestTranscoding.py @ 370:7eb5b86508b1
added Tests/CheckHttpServerSecurity.py and Tests/CheckIngestTranscoding.py
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 21 Jan 2021 11:38:47 +0100 |
parents | |
children | e769bcf2b94f |
comparison
equal
deleted
inserted
replaced
369:24d93b42873a | 370:7eb5b86508b1 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 # Orthanc - A Lightweight, RESTful DICOM Store | |
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
5 # Department, University Hospital of Liege, Belgium | |
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium | |
7 # | |
8 # This program is free software: you can redistribute it and/or | |
9 # modify it under the terms of the GNU General Public License as | |
10 # published by the Free Software Foundation, either version 3 of the | |
11 # License, or (at your option) any later version. | |
12 # | |
13 # This program is distributed in the hope that it will be useful, but | |
14 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU General Public License | |
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | |
21 | |
22 import json | |
23 import os | |
24 import subprocess | |
25 import sys | |
26 import time | |
27 import Toolbox | |
28 | |
29 | |
30 if len(sys.argv) < 2: | |
31 print('Must provide a path to Orthanc binaries') | |
32 exit(-1) | |
33 | |
34 | |
35 TMP = '/tmp/OrthancTest' | |
36 CONFIG = os.path.join(TMP, 'Configuration.json') | |
37 ORTHANC = Toolbox.DefineOrthanc() | |
38 | |
39 if os.path.exists(TMP): | |
40 print('Temporary path already exists: %s' % TMP) | |
41 exit(-1) | |
42 | |
43 os.mkdir(TMP) | |
44 | |
45 | |
46 def DropOrthanc(): | |
47 while True: | |
48 try: | |
49 instances = Toolbox.DoGet(ORTHANC, '/instances') | |
50 if len(instances) == 0: | |
51 break | |
52 else: | |
53 for i in instances: | |
54 Toolbox.DoDelete(ORTHANC, '/instances/%s' % i) | |
55 except: | |
56 time.sleep(0.05) | |
57 | |
58 | |
59 | |
60 def TestTranscoding(config, tests): | |
61 with open(CONFIG, 'w') as f: | |
62 f.write(json.dumps(config)) | |
63 | |
64 process = subprocess.Popen( | |
65 sys.argv[1:] + [ CONFIG ], | |
66 cwd = TMP, | |
67 #stdout=subprocess.PIPE, | |
68 stderr=subprocess.PIPE, | |
69 #shell=True | |
70 ) | |
71 | |
72 success = True | |
73 | |
74 try: | |
75 for test in tests: | |
76 DropOrthanc() | |
77 with open(Toolbox.GetDatabasePath(test[0]), 'rb') as f: | |
78 Toolbox.DoPost(ORTHANC, '/instances', f.read(), 'application/dicom') | |
79 | |
80 instances = Toolbox.DoGet(ORTHANC, '/instances') | |
81 if len(instances) != 1: | |
82 print('BAD NUMBER OF INSTANCES') | |
83 success = False | |
84 break | |
85 | |
86 metadata = Toolbox.DoGet(ORTHANC, '/instances/%s/metadata?expand' % instances[0]) | |
87 if not 'TransferSyntax' in metadata: | |
88 print('NO METADATA') | |
89 success = False | |
90 break | |
91 | |
92 if metadata['TransferSyntax'] != test[1]: | |
93 print('TRANSFER SYNTAX MISMATCH: %s vs %s' % (metadata['TransferSyntax'], test[1])) | |
94 success = False | |
95 except: | |
96 success = False | |
97 | |
98 process.terminate() | |
99 process.wait() | |
100 | |
101 return success | |
102 | |
103 | |
104 def Assert(b): | |
105 if not b: | |
106 raise Exception('Bad result') | |
107 | |
108 | |
109 print('==== TEST 1 ====') # No transcoding by default | |
110 Assert(TestTranscoding({ }, [ | |
111 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.1'), | |
112 ('TransferSyntaxes/1.2.840.10008.1.2.2.dcm', '1.2.840.10008.1.2.2'), | |
113 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.4.51'), | |
114 ])) | |
115 | |
116 print('==== TEST 2 ====') | |
117 Assert(TestTranscoding({ | |
118 'IngestTranscoding' : '1.2.840.10008.1.2.1', | |
119 }, [ | |
120 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.1'), | |
121 ('TransferSyntaxes/1.2.840.10008.1.2.2.dcm', '1.2.840.10008.1.2.1'), | |
122 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.1'), | |
123 ])) | |
124 | |
125 print('==== TEST 3 ====') | |
126 Assert(TestTranscoding({ | |
127 'IngestTranscoding' : '1.2.840.10008.1.2.1', | |
128 'IngestTranscodingOfUncompressed' : True, | |
129 'IngestTranscodingOfCompressed' : True, | |
130 }, [ | |
131 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.1'), | |
132 ('TransferSyntaxes/1.2.840.10008.1.2.2.dcm', '1.2.840.10008.1.2.1'), | |
133 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.1'), | |
134 ])) | |
135 | |
136 print('==== TEST 4 ====') | |
137 Assert(TestTranscoding({ | |
138 'IngestTranscoding' : '1.2.840.10008.1.2.1', | |
139 'IngestTranscodingOfUncompressed' : True, | |
140 'IngestTranscodingOfCompressed' : False, | |
141 }, [ | |
142 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.1'), | |
143 ('TransferSyntaxes/1.2.840.10008.1.2.2.dcm', '1.2.840.10008.1.2.1'), | |
144 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.4.51'), | |
145 ])) | |
146 | |
147 print('==== TEST 5 ====') | |
148 Assert(TestTranscoding({ | |
149 'IngestTranscoding' : '1.2.840.10008.1.2.1', | |
150 'IngestTranscodingOfUncompressed' : False, | |
151 'IngestTranscodingOfCompressed' : True, | |
152 }, [ | |
153 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.1'), | |
154 ('TransferSyntaxes/1.2.840.10008.1.2.2.dcm', '1.2.840.10008.1.2.2'), | |
155 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.1'), | |
156 ])) | |
157 | |
158 print('==== TEST 6 ====') | |
159 Assert(TestTranscoding({ | |
160 'IngestTranscoding' : '1.2.840.10008.1.2.1', | |
161 'IngestTranscodingOfUncompressed' : False, | |
162 'IngestTranscodingOfCompressed' : False, | |
163 }, [ | |
164 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.1'), | |
165 ('TransferSyntaxes/1.2.840.10008.1.2.2.dcm', '1.2.840.10008.1.2.2'), | |
166 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.4.51'), | |
167 ])) | |
168 | |
169 print('==== TEST 7 ====') | |
170 Assert(TestTranscoding({ | |
171 'IngestTranscoding' : '1.2.840.10008.1.2.4.51', | |
172 'IngestTranscodingOfUncompressed' : True, | |
173 'IngestTranscodingOfCompressed' : True, | |
174 }, [ | |
175 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.4.51'), | |
176 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.4.51'), | |
177 ('TransferSyntaxes/1.2.840.10008.1.2.4.57.dcm', '1.2.840.10008.1.2.4.51'), | |
178 ])) | |
179 | |
180 print('==== TEST 8 ====') | |
181 Assert(TestTranscoding({ | |
182 'IngestTranscoding' : '1.2.840.10008.1.2.4.51', | |
183 'IngestTranscodingOfUncompressed' : True, | |
184 'IngestTranscodingOfCompressed' : False, | |
185 }, [ | |
186 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.4.51'), | |
187 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.4.51'), | |
188 ('TransferSyntaxes/1.2.840.10008.1.2.4.57.dcm', '1.2.840.10008.1.2.4.57'), | |
189 ])) | |
190 | |
191 print('==== TEST 9 ====') | |
192 Assert(TestTranscoding({ | |
193 'IngestTranscoding' : '1.2.840.10008.1.2.4.51', | |
194 'IngestTranscodingOfUncompressed' : False, | |
195 'IngestTranscodingOfCompressed' : True, | |
196 }, [ | |
197 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.1'), | |
198 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.4.51'), | |
199 ('TransferSyntaxes/1.2.840.10008.1.2.4.57.dcm', '1.2.840.10008.1.2.4.51'), | |
200 ])) | |
201 | |
202 print('==== TEST 10 ====') | |
203 Assert(TestTranscoding({ | |
204 'IngestTranscoding' : '1.2.840.10008.1.2.4.51', | |
205 'IngestTranscodingOfUncompressed' : False, | |
206 'IngestTranscodingOfCompressed' : False, | |
207 }, [ | |
208 ('TransferSyntaxes/1.2.840.10008.1.2.1.dcm', '1.2.840.10008.1.2.1'), | |
209 ('TransferSyntaxes/1.2.840.10008.1.2.4.51.dcm', '1.2.840.10008.1.2.4.51'), | |
210 ('TransferSyntaxes/1.2.840.10008.1.2.4.57.dcm', '1.2.840.10008.1.2.4.57'), | |
211 ])) | |
212 | |
213 | |
214 print('Success!') |