Mercurial > hg > orthanc-tests
comparison Plugins/DicomWeb/Run.py @ 32:682c4e2a1162
integration tests for wado
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 02 Aug 2015 13:14:58 +0200 |
parents | |
children | eb6d219af210 |
comparison
equal
deleted
inserted
replaced
31:e07deb07289d | 32:682c4e2a1162 |
---|---|
1 #!/usr/bin/python | |
2 | |
3 # Orthanc - A Lightweight, RESTful DICOM Store | |
4 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics | |
5 # Department, University Hospital of Liege, Belgium | |
6 # | |
7 # This program is free software: you can redistribute it and/or | |
8 # modify it under the terms of the GNU General Public License as | |
9 # published by the Free Software Foundation, either version 3 of the | |
10 # License, or (at your option) any later version. | |
11 # | |
12 # This program is distributed in the hope that it will be useful, but | |
13 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 # General Public License for more details. | |
16 # | |
17 # You should have received a copy of the GNU General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 import os | |
22 import sys | |
23 import argparse | |
24 import unittest | |
25 | |
26 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests')) | |
27 from Toolbox import * | |
28 | |
29 | |
30 ## | |
31 ## Parse the command-line arguments | |
32 ## | |
33 | |
34 parser = argparse.ArgumentParser(description = 'Run the integration tests for the DICOMweb plugin.') | |
35 | |
36 parser.add_argument('--server', | |
37 default = 'localhost', | |
38 help = 'Address of the Orthanc server to test') | |
39 parser.add_argument('--rest', | |
40 type = int, | |
41 default = 8042, | |
42 help = 'Port to the REST API') | |
43 parser.add_argument('--username', | |
44 default = 'alice', | |
45 help = 'Username to the REST API') | |
46 parser.add_argument('--password', | |
47 default = 'orthanctest', | |
48 help = 'Password to the REST API') | |
49 parser.add_argument('--wado', | |
50 default = '/wado', | |
51 help = 'Path to the WADO API') | |
52 parser.add_argument('--dicom-web', | |
53 default = '/dicom-web/', | |
54 help = 'Path to the DICOMweb API') | |
55 parser.add_argument('--force', help = 'Do not warn the user', | |
56 action = 'store_true') | |
57 parser.add_argument('options', metavar = 'N', nargs = '*', | |
58 help='Arguments to Python unittest') | |
59 | |
60 args = parser.parse_args() | |
61 | |
62 | |
63 ## | |
64 ## Configure the testing context | |
65 ## | |
66 | |
67 if not args.force: | |
68 print(""" | |
69 WARNING: This test will remove all the content of your | |
70 Orthanc instance running on %s! | |
71 | |
72 Are you sure ["yes" to go on]?""" % args.server) | |
73 | |
74 if sys.stdin.readline().strip() != 'yes': | |
75 print('Aborting...') | |
76 exit(0) | |
77 | |
78 | |
79 ORTHANC = DefineOrthanc(server = args.server, | |
80 username = args.username, | |
81 password = args.password, | |
82 restPort = args.rest) | |
83 | |
84 | |
85 ## | |
86 ## The tests | |
87 ## | |
88 | |
89 class Orthanc(unittest.TestCase): | |
90 def setUp(self): | |
91 DropOrthanc(ORTHANC) | |
92 | |
93 def test_wado_dicom(self): | |
94 UploadInstance(ORTHANC, 'Brainix/Flair/IM-0001-0001.dcm') | |
95 | |
96 SIZE = 169478 | |
97 INSTANCE = '1.3.46.670589.11.0.0.11.4.2.0.8743.5.5396.2006120114314079549' | |
98 SERIES = '1.3.46.670589.11.0.0.11.4.2.0.8743.5.5396.2006120114285654497' | |
99 STUDY = '2.16.840.1.113669.632.20.1211.10000357775' | |
100 | |
101 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado)) | |
102 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?requestType=WADO')) | |
103 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?objectUID=%s' % INSTANCE)) | |
104 | |
105 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s' % INSTANCE) | |
106 self.assertEqual(SIZE, len(dicom)) | |
107 | |
108 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s&seriesUID=%s' % (INSTANCE, SERIES)) | |
109 self.assertEqual(SIZE, len(dicom)) | |
110 | |
111 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s&seriesUID=%s&studyUID=%s' % (INSTANCE, SERIES, STUDY)) | |
112 self.assertEqual(SIZE, len(dicom)) | |
113 | |
114 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s&seriesUID=%s' % (INSTANCE, SERIES)) | |
115 self.assertEqual(SIZE, len(dicom)) | |
116 | |
117 dicom = DoGet(ORTHANC, args.wado + '?contentType=application/dicom&requestType=WADO&objectUID=%s&studyUID=%s' % (INSTANCE, STUDY)) | |
118 self.assertEqual(SIZE, len(dicom)) | |
119 | |
120 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s&seriesUID=nope' % INSTANCE)) | |
121 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s&studyUID=nope' % INSTANCE)) | |
122 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s&seriesUID=nope&studyUID=nope' % INSTANCE)) | |
123 | |
124 def test_wado_image(self): | |
125 UploadInstance(ORTHANC, 'Phenix/IM-0001-0001.dcm') | |
126 INSTANCE = '1.2.840.113704.7.1.1.6632.1127829031.2' | |
127 | |
128 im = GetImage(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s' % INSTANCE) | |
129 self.assertEqual('JPEG', im.format) | |
130 self.assertEqual('L', im.mode) | |
131 self.assertEqual(512, im.size[0]) | |
132 self.assertEqual(358, im.size[1]) | |
133 | |
134 im = GetImage(ORTHANC, args.wado + '?contentType=image/jpg&requestType=WADO&objectUID=%s' % INSTANCE) | |
135 self.assertEqual('JPEG', im.format) | |
136 | |
137 im = GetImage(ORTHANC, args.wado + '?contentType=image/png&requestType=WADO&objectUID=%s' % INSTANCE) | |
138 self.assertEqual('PNG', im.format) | |
139 self.assertEqual('L', im.mode) | |
140 self.assertEqual(512, im.size[0]) | |
141 self.assertEqual(358, im.size[1]) | |
142 | |
143 | |
144 | |
145 try: | |
146 print('\nStarting the tests...') | |
147 unittest.main(argv = [ sys.argv[0] ] + args.options) | |
148 | |
149 finally: | |
150 print('\nDone') |