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