annotate Plugins/DicomWeb/Run.py @ 83:3f2170efa8d2

patches for python3
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 Jun 2016 18:04:59 +0200
parents 97acfdf0dbce
children dc90b87471a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 33
diff changeset
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
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 # 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
8 # 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
9 # 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
10 # License, or (at your option) any later version.
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 #
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # 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
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # General Public License for more details.
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 #
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # 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
18 # 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
19
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 import os
33
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
22 import pprint
32
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 import sys
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import argparse
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import unittest
83
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
26 import re
33
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
27 from DicomWeb import *
32
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 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
30 from Toolbox import *
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 ##
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 ## Parse the command-line arguments
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 ##
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 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
38
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 parser.add_argument('--server',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 default = 'localhost',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 help = 'Address of the Orthanc server to test')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 parser.add_argument('--rest',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 type = int,
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 default = 8042,
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 help = 'Port to the REST API')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 parser.add_argument('--username',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 default = 'alice',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 help = 'Username to the REST API')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 parser.add_argument('--password',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 default = 'orthanctest',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 help = 'Password to the REST API')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 parser.add_argument('--wado',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 default = '/wado',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 help = 'Path to the WADO API')
33
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
55 parser.add_argument('--dicomweb',
32
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 default = '/dicom-web/',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 help = 'Path to the DICOMweb API')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 parser.add_argument('--force', help = 'Do not warn the user',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 action = 'store_true')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 parser.add_argument('options', metavar = 'N', nargs = '*',
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 help='Arguments to Python unittest')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 args = parser.parse_args()
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ##
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 ## Configure the testing context
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 ##
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 if not args.force:
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 print("""
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 WARNING: This test will remove all the content of your
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 Orthanc instance running on %s!
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 Are you sure ["yes" to go on]?""" % args.server)
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 if sys.stdin.readline().strip() != 'yes':
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 print('Aborting...')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 exit(0)
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
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 ORTHANC = DefineOrthanc(server = args.server,
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 username = args.username,
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 password = args.password,
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 restPort = args.rest)
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
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 ##
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 ## The tests
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 ##
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 class Orthanc(unittest.TestCase):
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 def setUp(self):
83
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
94 if (sys.version_info >= (3, 0)):
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
95 # Remove annoying warnings about unclosed socket in Python 3
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
96 import warnings
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
97 warnings.simplefilter("ignore", ResourceWarning)
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
98
32
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 DropOrthanc(ORTHANC)
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 def test_wado_dicom(self):
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 UploadInstance(ORTHANC, 'Brainix/Flair/IM-0001-0001.dcm')
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 SIZE = 169478
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 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
106 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
107 STUDY = '2.16.840.1.113669.632.20.1211.10000357775'
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado))
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 self.assertRaises(Exception, lambda: DoGet(ORTHANC, args.wado + '?requestType=WADO'))
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 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
112
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 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
114 self.assertEqual(SIZE, len(dicom))
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 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
117 self.assertEqual(SIZE, len(dicom))
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 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
120 self.assertEqual(SIZE, len(dicom))
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 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
123 self.assertEqual(SIZE, len(dicom))
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 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
126 self.assertEqual(SIZE, len(dicom))
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 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
129 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
130 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
131
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 def test_wado_image(self):
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 UploadInstance(ORTHANC, 'Phenix/IM-0001-0001.dcm')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 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
135
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 im = GetImage(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s' % INSTANCE)
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 self.assertEqual('JPEG', im.format)
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 self.assertEqual('L', im.mode)
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 self.assertEqual(512, im.size[0])
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 self.assertEqual(358, im.size[1])
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 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
143 self.assertEqual('JPEG', im.format)
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 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
146 self.assertEqual('PNG', im.format)
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 self.assertEqual('L', im.mode)
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 self.assertEqual(512, im.size[0])
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 self.assertEqual(358, im.size[1])
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
33
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
151 def test_stow(self):
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
152 self.assertEqual(0, len(DoGet(ORTHANC, '/instances')))
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
153 SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Phenix/IM-0001-0001.dcm'))
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
154 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
155 a = SendStow(ORTHANC, args.dicomweb + '/studies', GetDatabasePath('Phenix/IM-0001-0001.dcm'))
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
156 self.assertEqual(1, len(DoGet(ORTHANC, '/instances')))
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
157
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
158 self.assertEqual(0, len(a['00081198']['Value'])) # No error
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
159 self.assertEqual(1, len(a['00081199']['Value'])) # 1 success
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
160
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
161 self.assertTrue(a['00081190']['Value'][0].endswith('studies/2.16.840.1.113669.632.20.1211.10000098591'))
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
162 self.assertTrue(a['00081199']['Value'][0]['00081190']['Value'][0].
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
163 endswith('series/1.2.840.113704.1.111.5692.1127828999.2/instances/1.2.840.113704.7.1.1.6632.1127829031.2'))
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
164
83
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
165 # Remove the "http://localhost:8042" prefix
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
166 url = a['00081190']['Value'][0]
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
167 url = re.sub(r'(http|https)://[^/]+(/.*)', r'\2', url)
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
168
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
169 # Get the content-length of all the multiparts of this WADO-RS request
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
170 b = DoGet(ORTHANC, url).decode('utf-8', 'ignore')
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
171 parts = re.findall(r'^Content-Length:\s*(\d+)\s*', b, re.IGNORECASE | re.MULTILINE)
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
172 self.assertEqual(1, len(parts))
3f2170efa8d2 patches for python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
173 self.assertEqual(os.path.getsize(GetDatabasePath('Phenix/IM-0001-0001.dcm')), int(parts[0]))
33
eb6d219af210 test stow
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
174
32
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 try:
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 print('\nStarting the tests...')
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 unittest.main(argv = [ sys.argv[0] ] + args.options)
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 finally:
682c4e2a1162 integration tests for wado
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 print('\nDone')