comparison Run.py @ 2:a15734e7f0af

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 17 Jun 2015 09:56:44 +0200
parents 08dadea8f40a
children
comparison
equal deleted inserted replaced
1:08dadea8f40a 2:a15734e7f0af
28 import subprocess 28 import subprocess
29 import unittest 29 import unittest
30 30
31 from ExternalCommandThread import * 31 from ExternalCommandThread import *
32 from Toolbox import * 32 from Toolbox import *
33 from Tests import *
33 34
34 35
35 ## 36 ##
36 ## Parse the command-line arguments 37 ## Parse the command-line arguments
37 ## 38 ##
50 parser.add_argument('--rest', 51 parser.add_argument('--rest',
51 type = int, 52 type = int,
52 default = 8042, 53 default = 8042,
53 help = 'Port to the REST API') 54 help = 'Port to the REST API')
54 parser.add_argument('--username', 55 parser.add_argument('--username',
55 default = None, 56 default = 'alice',
56 help = 'Username to the REST API') 57 help = 'Username to the REST API')
57 parser.add_argument('--password', 58 parser.add_argument('--password',
58 default = None, 59 default = 'orthanctest',
59 help = 'Password to the REST API') 60 help = 'Password to the REST API')
60 parser.add_argument("--force", help = "Do not warn the user", 61 parser.add_argument('--force', help = 'Do not warn the user',
61 action = "store_true") 62 action = 'store_true')
62 63
63 args = parser.parse_args() 64 args = parser.parse_args()
64 65
65 if not args.force: 66 if not args.force:
66 print(""" 67 print("""
107 aet = args.aet, 108 aet = args.aet,
108 dicomPort = args.dicom) 109 dicomPort = args.dicom)
109 110
110 111
111 112
112 class Orthanc(unittest.TestCase): 113 print('Parameters of the instance of Orthanc to test:')
113 def setUp(self): 114 print(REMOTE)
114 DropOrthanc(LOCAL) 115 print('')
115 DropOrthanc(REMOTE)
116
117 def test_system(self):
118 self.assertTrue('Version' in DoGet(REMOTE, '/system'))
119 self.assertEqual('0', DoGet(REMOTE, '/statistics')['TotalDiskSize'])
120 self.assertEqual('0', DoGet(REMOTE, '/statistics')['TotalUncompressedSize'])
121
122 def test_upload(self):
123 u = UploadInstance(REMOTE, 'DummyCT.dcm')
124 self.assertEqual('Success', u['Status'])
125 u = UploadInstance(REMOTE, 'DummyCT.dcm')
126 self.assertEqual('AlreadyStored', u['Status'])
127 self.assertEqual(1, len(DoGet(REMOTE, '/patients')))
128 self.assertEqual(1, len(DoGet(REMOTE, '/studies')))
129 self.assertEqual(1, len(DoGet(REMOTE, '/series')))
130 self.assertEqual(1, len(DoGet(REMOTE, '/instances')))
131
132 i = DoGet(REMOTE, '/instances/%s/simplified-tags' % u['ID'])
133 self.assertEqual('20070101', i['StudyDate'])
134 116
135 117
136 def test_rest_grid(self): 118 print('Waiting for the internal Orthanc to start...')
137 i = UploadInstance(REMOTE, 'DummyCT.dcm')['ID'] 119 while True:
138 instance = DoGet(REMOTE, '/instances/%s' % i) 120 try:
139 self.assertEqual(i, instance['ID']) 121 DoGet(LOCAL, '/instances')
140 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', 122 break
141 instance['MainDicomTags']['SOPInstanceUID']) 123 except:
142 124 time.sleep(0.1)
143 series = DoGet(REMOTE, '/series/%s' % instance['ParentSeries'])
144 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.394',
145 series['MainDicomTags']['SeriesInstanceUID'])
146
147 study = DoGet(REMOTE, '/studies/%s' % series['ParentStudy'])
148 self.assertEqual('1.2.840.113619.2.176.2025.1499492.7391.1171285944.390',
149 study['MainDicomTags']['StudyInstanceUID'])
150
151 patient = DoGet(REMOTE, '/patients/%s' % study['ParentPatient'])
152 self.assertEqual('ozp00SjY2xG',
153 patient['MainDicomTags']['PatientID'])
154
155 dicom = DoGet(REMOTE, '/instances/%s/file' % instance['ID'])
156 self.assertEqual(2472, len(dicom))
157 self.assertEqual('3e29b869978b6db4886355a2b1132124', ComputeMD5(dicom))
158 self.assertEqual(1, len(DoGet(REMOTE, '/instances/%s/frames' % i)))
159 self.assertEqual('TWINOW', DoGet(REMOTE, '/instances/%s/simplified-tags' % i)['StationName'])
160 self.assertEqual('TWINOW', DoGet(REMOTE, '/instances/%s/tags' % i)['0008,1010']['Value'])
161 125
162 126
163 try: 127 try:
164 print('Waiting for the internal Orthanc to start...')
165 while True:
166 try:
167 DoGet(LOCAL, '/instances')
168 break
169 except:
170 time.sleep(0.1)
171
172 print('Starting the tests...') 128 print('Starting the tests...')
129 SetOrthancParameters(LOCAL, REMOTE)
173 unittest.main(argv = [ sys.argv[0] ]) #argv = args) 130 unittest.main(argv = [ sys.argv[0] ]) #argv = args)
174 131
175 finally: 132 finally:
176 # The tests have stopped or "Ctrl-C" has been hit 133 # The tests have stopped or "Ctrl-C" has been hit
177 try: 134 try: