annotate Plugins/Recycling/Run.py @ 280:5daa3896981c

testing storage commitment reports
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Mar 2020 20:54:57 +0100
parents 943166deebcb
children 79ce0f7a9714
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
203
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
260
943166deebcb upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
6 # Copyright (C) 2017-2020 Osimis S.A., Belgium
203
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 #
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # modify it under the terms of the GNU General Public License as
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # published by the Free Software Foundation, either version 3 of the
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # License, or (at your option) any later version.
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 #
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful, but
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # General Public License for more details.
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 #
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # You should have received a copy of the GNU General Public License
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 # You must add the following to the configuration file:
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 # {
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 # "MaximumPatientCount" : 4
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 # }
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 import os
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 import pprint
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 import sys
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 import argparse
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 import unittest
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 import re
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests'))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 from Toolbox import *
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 ##
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 ## Parse the command-line arguments
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 ##
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 parser = argparse.ArgumentParser(description = 'Run the integration tests for the patient recycling behavior.')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 parser.add_argument('--server',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 default = 'localhost',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 help = 'Address of the Orthanc server to test')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 parser.add_argument('--rest',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 type = int,
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 default = 8042,
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 help = 'Port to the REST API')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 parser.add_argument('--username',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 default = 'alice',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 help = 'Username to the REST API')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 parser.add_argument('--password',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 default = 'orthanctest',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 help = 'Password to the REST API')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 parser.add_argument('--force', help = 'Do not warn the user',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 action = 'store_true')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 parser.add_argument('options', metavar = 'N', nargs = '*',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 help='Arguments to Python unittest')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 args = parser.parse_args()
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ##
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ## Configure the testing context
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ##
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 if not args.force:
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 print("""
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 WARNING: This test will remove all the content of your
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 Orthanc instance running on %s!
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 Are you sure ["yes" to go on]?""" % args.server)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 if sys.stdin.readline().strip() != 'yes':
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 print('Aborting...')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 exit(0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 ORTHANC = DefineOrthanc(server = args.server,
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 username = args.username,
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 password = args.password,
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 restPort = args.rest)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 ##
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ## The tests
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 ##
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 DICOM = {
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 'brainix' : [
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 'Brainix/Flair/IM-0001-0001.dcm',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 'Brainix/Epi/IM-0001-0001.dcm',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 ],
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 'knee' : [
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 'Knee/T1/IM-0001-0001.dcm',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 'Knee/T2/IM-0001-0001.dcm',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 ],
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 'beaufix' : [
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 'Beaufix/IM-0001-0001.dcm',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 ],
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 'phenix' : [
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 'Phenix/IM-0001-0001.dcm',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 ],
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 'dummy' : [
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 'DummyCT.dcm',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 ],
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 'comunix' : [
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 'Comunix/Pet/IM-0001-0001.dcm',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 'Comunix/Pet/IM-0001-0002.dcm',
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 ],
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 PATIENTS = list(DICOM.keys())
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 def UploadAndGetPatientId(patient, instance):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 a = UploadInstance(ORTHANC, DICOM[patient][instance])['ID']
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 return DoGet(ORTHANC, '/instances/%s/patient' % a)['ID']
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 def TestContent(expectedPatients):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 patients = DoGet(ORTHANC, '/patients')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 if len(patients) != len(expectedPatients):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 return False
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 for i in expectedPatients:
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 if not i in patients:
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 return False
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 for i in patients:
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 if not i in expectedPatients:
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 return False
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 return True
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 class Orthanc(unittest.TestCase):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 def setUp(self):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 if (sys.version_info >= (3, 0)):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 # Remove annoying warnings about unclosed socket in Python 3
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 import warnings
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 warnings.simplefilter("ignore", ResourceWarning)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 DropOrthanc(ORTHANC)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 def test_config(self):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 # Make sure that "MaximumPatientCount" equals 4
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 a = UploadAndGetPatientId('brainix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 b = UploadAndGetPatientId('knee', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 c = UploadAndGetPatientId('beaufix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 d = UploadAndGetPatientId('phenix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 self.assertEqual(4, len(DoGet(ORTHANC, '/instances')))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 e = UploadAndGetPatientId('dummy', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 self.assertTrue(TestContent([b, c, d, e ]))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 def test_loop(self):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 ids = []
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 for i in range(5):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 ids.append(UploadAndGetPatientId(PATIENTS[i], 0))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 self.assertEqual(4, len(DoGet(ORTHANC, '/instances')))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 for i in range(20):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 expected = set(ids)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 expected.remove(ids[i % 5])
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 TestContent(expected)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 self.assertEqual(ids[i % 5], UploadAndGetPatientId(PATIENTS[i % 5], 0))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 def test_protection(self):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 a = UploadAndGetPatientId('brainix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 b = UploadAndGetPatientId('knee', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 c = UploadAndGetPatientId('beaufix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 d = UploadAndGetPatientId('phenix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 DoPut(ORTHANC, '/patients/%s/protected' % b, '1')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 UploadAndGetPatientId('knee', 1)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 e = UploadAndGetPatientId('dummy', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 f = UploadAndGetPatientId('comunix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 self.assertTrue(TestContent([ d, e, f, b ]))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 # This puts "b" at the end of the recycling order
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 DoPut(ORTHANC, '/patients/%s/protected' % b, '0')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 a = UploadAndGetPatientId('brainix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 self.assertTrue(TestContent([ e, f, b, a ]))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 c = UploadAndGetPatientId('beaufix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 self.assertTrue(TestContent([ f, b, a, c ]))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 d = UploadAndGetPatientId('phenix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 self.assertTrue(TestContent([ b, a, c, d ]))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 e = UploadAndGetPatientId('dummy', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 self.assertTrue(TestContent([ a, c, d, e ]))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 def test_bitbucket_issue_58(self):
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 a = UploadAndGetPatientId('brainix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 b = UploadAndGetPatientId('knee', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 c = UploadAndGetPatientId('beaufix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 d = UploadAndGetPatientId('phenix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 self.assertEqual(4, len(DoGet(ORTHANC, '/instances')))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 e = UploadAndGetPatientId('dummy', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 self.assertTrue(TestContent([b, c, d, e ]))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 UploadAndGetPatientId('knee', 1)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 self.assertTrue(TestContent([c, d, e, b ]))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 f = UploadAndGetPatientId('comunix', 0)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 self.assertTrue(TestContent([d, e, b, f ]))
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 try:
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 print('\nStarting the tests...')
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 unittest.main(argv = [ sys.argv[0] ] + args.options)
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 finally:
89ed88b2f1a0 integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 print('\nDone')