Mercurial > hg > orthanc-tests
annotate Plugins/Recycling/Run.py @ 476:77f868063bb3
cleanup
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 03 May 2022 17:10:29 +0200 |
parents | 06eea14c5906 |
children | 933fe1bbce4f |
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 |
449
06eea14c5906
upgrade year to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
437
diff
changeset
|
6 # Copyright (C) 2017-2022 Osimis S.A., Belgium |
06eea14c5906
upgrade year to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
437
diff
changeset
|
7 # Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
203
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # 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
|
10 # 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
|
11 # 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
|
12 # License, or (at your option) any later version. |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # 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
|
15 # WITHOUT ANY WARRANTY; without even the implied warranty of |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # 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
|
17 # General Public License for more details. |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # 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
|
20 # 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
|
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 # You must add the following to the configuration file: |
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 # { |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 # "MaximumPatientCount" : 4 |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 import os |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 import pprint |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 import sys |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 import argparse |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 import unittest |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 import re |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 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
|
40 from Toolbox import * |
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 ## |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 ## Parse the command-line arguments |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 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
|
48 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 parser.add_argument('--server', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 default = 'localhost', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 help = 'Address of the Orthanc server to test') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 parser.add_argument('--rest', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 type = int, |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 default = 8042, |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 help = 'Port to the REST API') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 parser.add_argument('--username', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 default = 'alice', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 help = 'Username to the REST API') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 parser.add_argument('--password', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 default = 'orthanctest', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 help = 'Password to the REST API') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 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
|
63 action = 'store_true') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 parser.add_argument('options', metavar = 'N', nargs = '*', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 help='Arguments to Python unittest') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 args = parser.parse_args() |
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 ## |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 ## Configure the testing context |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 if not args.force: |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 print(""" |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 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
|
77 Orthanc instance running on %s! |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 Are you sure ["yes" to go on]?""" % args.server) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 if sys.stdin.readline().strip() != 'yes': |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 print('Aborting...') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 exit(0) |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 ORTHANC = DefineOrthanc(server = args.server, |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 username = args.username, |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 password = args.password, |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 restPort = args.rest) |
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 ## |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 ## The tests |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 DICOM = { |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 'brainix' : [ |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 'Brainix/Flair/IM-0001-0001.dcm', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 'Brainix/Epi/IM-0001-0001.dcm', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 ], |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 'knee' : [ |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 'Knee/T1/IM-0001-0001.dcm', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 'Knee/T2/IM-0001-0001.dcm', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 ], |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 'beaufix' : [ |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 'Beaufix/IM-0001-0001.dcm', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 ], |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 'phenix' : [ |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 'Phenix/IM-0001-0001.dcm', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 ], |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 'dummy' : [ |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 'DummyCT.dcm', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 ], |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 'comunix' : [ |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 'Comunix/Pet/IM-0001-0001.dcm', |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 'Comunix/Pet/IM-0001-0002.dcm', |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 PATIENTS = list(DICOM.keys()) |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 def UploadAndGetPatientId(patient, instance): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 a = UploadInstance(ORTHANC, DICOM[patient][instance])['ID'] |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 return DoGet(ORTHANC, '/instances/%s/patient' % a)['ID'] |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 def TestContent(expectedPatients): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 patients = DoGet(ORTHANC, '/patients') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 if len(patients) != len(expectedPatients): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 return False |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 for i in expectedPatients: |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 if not i in patients: |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 return False |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 for i in patients: |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 if not i in expectedPatients: |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 return False |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 return True |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 class Orthanc(unittest.TestCase): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 def setUp(self): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 if (sys.version_info >= (3, 0)): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 # Remove annoying warnings about unclosed socket in Python 3 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 import warnings |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 warnings.simplefilter("ignore", ResourceWarning) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 DropOrthanc(ORTHANC) |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 def test_config(self): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 # Make sure that "MaximumPatientCount" equals 4 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 a = UploadAndGetPatientId('brainix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 b = UploadAndGetPatientId('knee', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 c = UploadAndGetPatientId('beaufix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 d = UploadAndGetPatientId('phenix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 self.assertEqual(4, len(DoGet(ORTHANC, '/instances'))) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 e = UploadAndGetPatientId('dummy', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 self.assertTrue(TestContent([b, c, d, e ])) |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 def test_loop(self): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 ids = [] |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 for i in range(5): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 ids.append(UploadAndGetPatientId(PATIENTS[i], 0)) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 self.assertEqual(4, len(DoGet(ORTHANC, '/instances'))) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 for i in range(20): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 expected = set(ids) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 expected.remove(ids[i % 5]) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 TestContent(expected) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 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
|
181 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 def test_protection(self): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 a = UploadAndGetPatientId('brainix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 b = UploadAndGetPatientId('knee', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 c = UploadAndGetPatientId('beaufix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 d = UploadAndGetPatientId('phenix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 DoPut(ORTHANC, '/patients/%s/protected' % b, '1') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 UploadAndGetPatientId('knee', 1) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 e = UploadAndGetPatientId('dummy', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 f = UploadAndGetPatientId('comunix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 self.assertTrue(TestContent([ d, e, f, b ])) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 # 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
|
198 DoPut(ORTHANC, '/patients/%s/protected' % b, '0') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 a = UploadAndGetPatientId('brainix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 self.assertTrue(TestContent([ e, f, b, a ])) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 c = UploadAndGetPatientId('beaufix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 self.assertTrue(TestContent([ f, b, a, c ])) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 d = UploadAndGetPatientId('phenix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 self.assertTrue(TestContent([ b, a, c, d ])) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 e = UploadAndGetPatientId('dummy', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 self.assertTrue(TestContent([ a, c, d, e ])) |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 def test_bitbucket_issue_58(self): |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 a = UploadAndGetPatientId('brainix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 b = UploadAndGetPatientId('knee', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 c = UploadAndGetPatientId('beaufix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 d = UploadAndGetPatientId('phenix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 self.assertEqual(4, len(DoGet(ORTHANC, '/instances'))) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 e = UploadAndGetPatientId('dummy', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 self.assertTrue(TestContent([b, c, d, e ])) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 UploadAndGetPatientId('knee', 1) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 self.assertTrue(TestContent([c, d, e, b ])) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 f = UploadAndGetPatientId('comunix', 0) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 self.assertTrue(TestContent([d, e, b, f ])) |
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 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 try: |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 print('\nStarting the tests...') |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 unittest.main(argv = [ sys.argv[0] ] + args.options) |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 finally: |
89ed88b2f1a0
integration tests for patient recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 print('\nDone') |