Mercurial > hg > orthanc-tests
annotate Plugins/DicomWeb/Run.py @ 161:27b3b0df5f90
2 upload tests
author | am@osimis.io |
---|---|
date | Fri, 17 Aug 2018 17:24:11 +0200 |
parents | 90e5331ddee9 |
children | e244312964d6 |
rev | line source |
---|---|
32
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 # Orthanc - A Lightweight, RESTful DICOM Store |
73 | 4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
32
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 # Department, University Hospital of Liege, Belgium |
130
50cd127e5330
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
129
diff
changeset
|
6 # Copyright (C) 2017-2018 Osimis S.A., Belgium |
32
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 # |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # This program is free software: you can redistribute it and/or |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # modify it under the terms of the GNU General Public License as |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # published by the Free Software Foundation, either version 3 of the |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # License, or (at your option) any later version. |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, but |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # WITHOUT ANY WARRANTY; without even the implied warranty of |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # General Public License for more details. |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # You should have received a copy of the GNU General Public License |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
85 | 22 |
23 # You must add the following to the configuration file: | |
24 # | |
25 # "DicomWeb" : { | |
26 # "Servers" : { | |
27 # "sample" : [ "http://localhost:8042/dicom-web/", "alice", "orthanctest" ] | |
28 # } | |
29 # } | |
30 | |
31 | |
32 | |
33 | |
32
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 import os |
33 | 35 import pprint |
32
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 import sys |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 import argparse |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 import unittest |
83 | 39 import re |
33 | 40 from DicomWeb import * |
32
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests')) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 from Toolbox import * |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 ## |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 ## Parse the command-line arguments |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 ## |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 parser = argparse.ArgumentParser(description = 'Run the integration tests for the DICOMweb plugin.') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 parser.add_argument('--server', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 default = 'localhost', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 help = 'Address of the Orthanc server to test') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 parser.add_argument('--rest', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 type = int, |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 default = 8042, |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 help = 'Port to the REST API') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 parser.add_argument('--username', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 default = 'alice', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 help = 'Username to the REST API') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 parser.add_argument('--password', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 default = 'orthanctest', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 help = 'Password to the REST API') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 parser.add_argument('--wado', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 default = '/wado', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 help = 'Path to the WADO API') |
33 | 68 parser.add_argument('--dicomweb', |
32
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 default = '/dicom-web/', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 help = 'Path to the DICOMweb API') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 parser.add_argument('--force', help = 'Do not warn the user', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 action = 'store_true') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 parser.add_argument('options', metavar = 'N', nargs = '*', |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 help='Arguments to Python unittest') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 args = parser.parse_args() |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 ## |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 ## Configure the testing context |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 ## |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 if not args.force: |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 print(""" |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 WARNING: This test will remove all the content of your |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 Orthanc instance running on %s! |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 Are you sure ["yes" to go on]?""" % args.server) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 if sys.stdin.readline().strip() != 'yes': |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 print('Aborting...') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 exit(0) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 ORTHANC = DefineOrthanc(server = args.server, |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 username = args.username, |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 password = args.password, |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 restPort = args.rest) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 ## |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 ## The tests |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 ## |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 class Orthanc(unittest.TestCase): |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 def setUp(self): |
83 | 107 if (sys.version_info >= (3, 0)): |
108 # Remove annoying warnings about unclosed socket in Python 3 | |
109 import warnings | |
110 warnings.simplefilter("ignore", ResourceWarning) | |
111 | |
32
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 DropOrthanc(ORTHANC) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 def test_wado_dicom(self): |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 UploadInstance(ORTHANC, 'Brainix/Flair/IM-0001-0001.dcm') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 SIZE = 169478 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 INSTANCE = '1.3.46.670589.11.0.0.11.4.2.0.8743.5.5396.2006120114314079549' |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 SERIES = '1.3.46.670589.11.0.0.11.4.2.0.8743.5.5396.2006120114285654497' |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 STUDY = '2.16.840.1.113669.632.20.1211.10000357775' |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?requestType=WADO')) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?objectUID=%s' % INSTANCE)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s' % INSTANCE) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 self.assertEqual(SIZE, len(dicom)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s&seriesUID=%s' % (INSTANCE, SERIES)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 self.assertEqual(SIZE, len(dicom)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s&seriesUID=%s&studyUID=%s' % (INSTANCE, SERIES, STUDY)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 self.assertEqual(SIZE, len(dicom)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s&seriesUID=%s' % (INSTANCE, SERIES)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 self.assertEqual(SIZE, len(dicom)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s&studyUID=%s' % (INSTANCE, STUDY)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 self.assertEqual(SIZE, len(dicom)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s&seriesUID=nope' % INSTANCE)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s&studyUID=nope' % INSTANCE)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s&seriesUID=nope&studyUID=nope' % INSTANCE)) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 def test_wado_image(self): |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 UploadInstance(ORTHANC, 'Phenix/IM-0001-0001.dcm') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 INSTANCE = '1.2.840.113704.7.1.1.6632.1127829031.2' |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 im = GetImage(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s' % INSTANCE) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 self.assertEqual('JPEG', im.format) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 self.assertEqual('L', im.mode) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 self.assertEqual(512, im.size[0]) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 self.assertEqual(358, im.size[1]) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 im = GetImage(ORTHANC, args.wado + '?contentType=image/jpg&requestType=WADO&objectUID=%s' % INSTANCE) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 self.assertEqual('JPEG', im.format) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 im = GetImage(ORTHANC, args.wado + '?contentType=image/png&requestType=WADO&objectUID=%s' % INSTANCE) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 self.assertEqual('PNG', im.format) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 self.assertEqual('L', im.mode) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 self.assertEqual(512, im.size[0]) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 self.assertEqual(358, im.size[1]) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 |
33 | 164 def test_stow(self): |
165 self.assertEqual(0, len(DoGet(ORTHANC, '/instances'))) | |
166 SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Phenix/IM-0001-0001.dcm')) | |
167 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) | |
168 a = SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Phenix/IM-0001-0001.dcm')) | |
169 self.assertEqual(1, len(DoGet(ORTHANC, '/instances'))) | |
170 | |
171 self.assertEqual(0, len(a['00081198']['Value'])) # No error | |
172 self.assertEqual(1, len(a['00081199']['Value'])) # 1 success | |
173 | |
174 self.assertTrue(a['00081190']['Value'][0].endswith('studies/2.16.840.1.113669.632.20.1211.10000098591')) | |
175 self.assertTrue(a['00081199']['Value'][0]['00081190']['Value'][0]. | |
176 endswith('series/1.2.840.113704.1.111.5692.1127828999.2/instances/1.2.840.113704.7.1.1.6632.1127829031.2')) | |
177 | |
83 | 178 # Remove the "http://localhost:8042" prefix |
179 url = a['00081190']['Value'][0] | |
180 url = re.sub(r'(http|https)://[^/]+(/.*)', r'\2', url) | |
181 | |
182 # Get the content-length of all the multiparts of this WADO-RS request | |
183 b = DoGet(ORTHANC, url).decode('utf-8', 'ignore') | |
184 parts = re.findall(r'^Content-Length:\s*(\d+)\s*', b, re.IGNORECASE | re.MULTILINE) | |
185 self.assertEqual(1, len(parts)) | |
186 self.assertEqual(os.path.getsize(GetDatabasePath('Phenix/IM-0001-0001.dcm')), int(parts[0])) | |
33 | 187 |
84 | 188 def test_server_get(self): |
189 UploadInstance(ORTHANC, 'Knee/T1/IM-0001-0001.dcm') | |
190 | |
191 self.assertEqual(1, len(DoGet(ORTHANC, '/dicom-web/servers'))) | |
192 self.assertTrue('sample' in DoGet(ORTHANC, '/dicom-web/servers')) | |
193 | |
129 | 194 serversReadback = DoGet(ORTHANC, '/dicom-web/servers?expand') |
195 self.assertEqual('http://localhost:8042/dicom-web/', serversReadback['sample']['Url']) | |
196 self.assertEqual('alice', serversReadback['sample']['Username']) | |
197 | |
84 | 198 sample = DoGet(ORTHANC, '/dicom-web/servers/sample') |
199 self.assertEqual(3, len(sample)) | |
200 self.assertTrue('stow' in sample) | |
201 self.assertTrue('retrieve' in sample) | |
202 self.assertTrue('get' in sample) | |
203 | |
204 # application/dicom+xml | |
131
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
205 self.assertEqual(2, len(re.findall('^--', DoGet(ORTHANC, '/dicom-web/studies', |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
206 headers = { 'Accept' : 'application/dicom+xml' }), |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
207 re.MULTILINE))) |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
208 self.assertEqual(2, len(re.findall('^--', DoPost |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
209 (ORTHANC, '/dicom-web/servers/sample/get', |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
210 { 'Uri' : '/studies', |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
211 'HttpHeaders' : { 'Accept' : 'application/dicom+xml' } |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
212 }), re.MULTILINE))) |
84 | 213 |
214 # application/dicom+json | |
131
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
215 self.assertEqual(1, len(DoGet(ORTHANC, '/dicom-web/studies', |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
216 headers = { 'Accept' : 'application/dicom+json' }))) |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
217 self.assertEqual(1, len(DoPost(ORTHANC, '/dicom-web/servers/sample/get', |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
218 { 'Uri' : '/studies', |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
219 'HttpHeaders' : { 'Accept' : 'application/dicom+json' }}))) |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
220 |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
221 # application/json |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
222 self.assertEqual(1, len(DoGet(ORTHANC, '/dicom-web/studies', |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
223 headers = { 'Accept' : 'application/json' }))) |
84 | 224 self.assertEqual(1, len(DoPost(ORTHANC, '/dicom-web/servers/sample/get', |
225 { 'Uri' : '/studies', | |
226 'HttpHeaders' : { 'Accept' : 'application/json' }}))) | |
227 | |
131
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
228 # application/dicom+json is the default as of OrthancDicomWeb-0.5 |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
229 self.assertEqual(1, len(DoGet(ORTHANC, '/dicom-web/studies'))) |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
230 self.assertEqual(1, len(DoPost(ORTHANC, '/dicom-web/servers/sample/get', |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
231 { 'Uri' : '/studies' }))) |
90e5331ddee9
application/dicom+json is now the default in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
232 |
84 | 233 |
234 def test_server_stow(self): | |
235 UploadInstance(ORTHANC, 'Knee/T1/IM-0001-0001.dcm') | |
236 | |
237 self.assertRaises(Exception, lambda: | |
238 DoPost(ORTHANC, '/dicom-web/servers/sample/stow', | |
239 { 'Resources' : [ 'nope' ]})) # inexisting resource | |
240 | |
241 self.assertEqual(0, len(DoPost(ORTHANC, '/dicom-web/servers/sample/stow', | |
242 { 'Resources' : [ 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17' ]}))) # patient | |
243 | |
244 self.assertEqual(0, len(DoPost(ORTHANC, '/dicom-web/servers/sample/stow', | |
245 { 'Resources' : [ '0a9b3153-2512774b-2d9580de-1fc3dcf6-3bd83918' ]}))) # study | |
246 | |
247 self.assertEqual(0, len(DoPost(ORTHANC, '/dicom-web/servers/sample/stow', | |
248 { 'Resources' : [ '6de73705-c4e65c1b-9d9ea1b5-cabcd8e7-f15e4285' ]}))) # series | |
249 | |
250 self.assertEqual(0, len(DoPost(ORTHANC, '/dicom-web/servers/sample/stow', | |
251 { 'Resources' : [ 'c8df6478-d7794217-0f11c293-a41237c9-31d98357' ]}))) # instance | |
252 | |
253 self.assertEqual(0, len(DoPost(ORTHANC, '/dicom-web/servers/sample/stow', | |
254 { 'Resources' : [ | |
255 'ca29faea-b6a0e17f-067743a1-8b778011-a48b2a17', | |
256 '0a9b3153-2512774b-2d9580de-1fc3dcf6-3bd83918', | |
257 '6de73705-c4e65c1b-9d9ea1b5-cabcd8e7-f15e4285', | |
258 'c8df6478-d7794217-0f11c293-a41237c9-31d98357' ]}))) # altogether | |
259 | |
260 | |
261 def test_server_retrieve(self): | |
262 UploadInstance(ORTHANC, 'Knee/T1/IM-0001-0001.dcm') | |
263 UploadInstance(ORTHANC, 'Knee/T1/IM-0001-0002.dcm') | |
264 UploadInstance(ORTHANC, 'Knee/T2/IM-0001-0001.dcm') | |
265 | |
266 self.assertRaises(Exception, lambda: | |
267 DoPost(ORTHANC, '/dicom-web/servers/sample/retrieve', | |
268 { 'Resources' : [ { 'Study' : 'nope' } ]})) # inexisting resource | |
269 | |
270 t = DoPost(ORTHANC, '/dicom-web/servers/sample/retrieve', | |
271 { 'Resources' : [ { 'Study' : '2.16.840.1.113669.632.20.121711.10000160881' } ] }) | |
272 self.assertEqual(3, len(t['Instances'])) | |
273 | |
274 # Missing "Study" field | |
275 self.assertRaises(Exception, lambda: | |
276 DoPost(ORTHANC, '/dicom-web/servers/sample/retrieve', | |
277 { 'Resources' : [ { 'Series' : '1.3.46.670589.11.17521.5.0.3124.2008081908564160709' } ]})) | |
278 | |
279 t = DoPost(ORTHANC, '/dicom-web/servers/sample/retrieve', | |
280 { 'Resources' : [ { 'Study' : '2.16.840.1.113669.632.20.121711.10000160881', | |
281 'Series' : '1.3.46.670589.11.17521.5.0.3124.2008081908564160709' } ] }) | |
282 self.assertEqual(2, len(t['Instances'])) | |
283 | |
284 t = DoPost(ORTHANC, '/dicom-web/servers/sample/retrieve', | |
285 { 'Resources' : [ { 'Study' : '2.16.840.1.113669.632.20.121711.10000160881', | |
286 'Series' : '1.3.46.670589.11.17521.5.0.3124.2008081909090037350' } ] }) | |
287 self.assertEqual(1, len(t['Instances'])) | |
288 | |
289 t = DoPost(ORTHANC, '/dicom-web/servers/sample/retrieve', | |
290 { 'Resources' : [ { 'Study' : '2.16.840.1.113669.632.20.121711.10000160881', | |
291 'Series' : '1.3.46.670589.11.17521.5.0.3124.2008081909090037350' }, | |
292 { 'Study' : '2.16.840.1.113669.632.20.121711.10000160881', | |
293 'Series' : '1.3.46.670589.11.17521.5.0.3124.2008081908564160709' } ] }) | |
294 self.assertEqual(3, len(t['Instances'])) | |
295 | |
296 t = DoPost(ORTHANC, '/dicom-web/servers/sample/retrieve', | |
297 { 'Resources' : [ { 'Study' : '2.16.840.1.113669.632.20.121711.10000160881', | |
298 'Series' : '1.3.46.670589.11.17521.5.0.3124.2008081909090037350', | |
299 'Instance' : '1.3.46.670589.11.17521.5.0.3124.2008081909113806560' } ] }) | |
300 self.assertEqual(1, len(t['Instances'])) | |
301 | |
302 | |
114
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
303 def test_bitbucket_issue_53(self): |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
304 # DICOMWeb plugin support for "limit" and "offset" parameters in QIDO-RS |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
305 # https://bitbucket.org/sjodogne/orthanc/issues/53 |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
306 |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
307 UploadInstance(ORTHANC, 'Brainix/Flair/IM-0001-0001.dcm') |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
308 UploadInstance(ORTHANC, 'Knee/T1/IM-0001-0001.dcm') |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
309 |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
310 brainix = '2.16.840.1.113669.632.20.1211.10000357775' |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
311 knee = '2.16.840.1.113669.632.20.121711.10000160881' |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
312 |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
313 a = DoGet(ORTHANC, '/dicom-web/studies', |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
314 headers = { 'accept' : 'application/json' }) |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
315 self.assertEqual(2, len(a)) |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
316 |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
317 b = [] |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
318 a = DoGet(ORTHANC, '/dicom-web/studies?limit=1', |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
319 headers = { 'accept' : 'application/json' }) |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
320 self.assertEqual(1, len(a)) |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
321 b.append(a[0]['0020000D']['Value'][0]) |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
322 |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
323 a = DoGet(ORTHANC, '/dicom-web/studies?limit=1&offset=1', |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
324 headers = { 'accept' : 'application/json' }) |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
325 self.assertEqual(1, len(a)) |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
326 b.append(a[0]['0020000D']['Value'][0]) |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
327 |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
328 self.assertTrue(brainix in b) |
a6019560272f
test_bitbucket_issue_53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
329 self.assertTrue(knee in b) |
32
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 try: |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
333 print('\nStarting the tests...') |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
334 unittest.main(argv = [ sys.argv[0] ] + args.options) |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
335 |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
336 finally: |
682c4e2a1162
integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 print('\nDone') |