Mercurial > hg > orthanc-tests
annotate Tests/Run.py @ 660:2f6686a3cd16
conditional test
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 24 Jun 2024 18:32:13 +0200 |
parents | 5d7b6e43ab7d |
children |
rev | line source |
---|---|
1 | 1 #!/usr/bin/python |
2 | |
3 # Orthanc - A Lightweight, RESTful DICOM Store | |
73 | 4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1 | 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:
511
diff
changeset
|
8 # Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1 | 9 # |
10 # This program is free software: you can redistribute it and/or | |
11 # modify it under the terms of the GNU General Public License as | |
12 # published by the Free Software Foundation, either version 3 of the | |
13 # License, or (at your option) any later version. | |
14 # | |
15 # This program is distributed in the hope that it will be useful, but | |
16 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 # General Public License for more details. | |
19 # | |
20 # You should have received a copy of the GNU General Public License | |
21 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
22 | |
23 | |
24 import re | |
25 import sys | |
26 import argparse | |
27 import subprocess | |
28 import unittest | |
3 | 29 import pprint |
1 | 30 |
2 | 31 from Tests import * |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
32 import Toolbox |
1 | 33 |
34 | |
35 ## | |
36 ## Parse the command-line arguments | |
37 ## | |
38 | |
39 parser = argparse.ArgumentParser(description = 'Run the integration tests on some instance of Orthanc.') | |
40 parser.add_argument('--server', | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
41 default = 'localhost', |
1 | 42 help = 'Address of the Orthanc server to test') |
43 parser.add_argument('--aet', | |
44 default = 'ORTHANC', | |
45 help = 'AET of the Orthanc instance to test') | |
46 parser.add_argument('--dicom', | |
47 type = int, | |
48 default = 4242, | |
49 help = 'DICOM port of the Orthanc instance to test') | |
50 parser.add_argument('--rest', | |
51 type = int, | |
52 default = 8042, | |
53 help = 'Port to the REST API') | |
54 parser.add_argument('--username', | |
2 | 55 default = 'alice', |
1 | 56 help = 'Username to the REST API') |
57 parser.add_argument('--password', | |
2 | 58 default = 'orthanctest', |
1 | 59 help = 'Password to the REST API') |
2 | 60 parser.add_argument('--force', help = 'Do not warn the user', |
61 action = 'store_true') | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
62 parser.add_argument('--docker', help = 'These tests are run from Docker', |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
63 action = 'store_true') |
342
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
64 parser.add_argument('--orthanc', |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
65 default = 'Orthanc', |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
66 help = 'Path to the executable of Orthanc') |
6 | 67 parser.add_argument('options', metavar = 'N', nargs = '*', |
68 help='Arguments to Python unittest') | |
1 | 69 |
70 args = parser.parse_args() | |
71 | |
72 if not args.force: | |
73 print(""" | |
74 WARNING: This test will remove all the content of your | |
75 Orthanc instance running on %s! | |
76 | |
77 Are you sure ["yes" to go on]?""" % args.server) | |
78 | |
79 if sys.stdin.readline().strip() != 'yes': | |
80 print('Aborting...') | |
81 exit(0) | |
82 | |
83 | |
84 | |
85 ## | |
86 ## Generate the configuration file for the anciliary instance of | |
87 ## Orthanc | |
88 ## | |
89 | |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
13
diff
changeset
|
90 CONFIG = '/tmp/IntegrationTestsConfiguration.json' |
342
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
91 subprocess.check_call([ Toolbox.FindExecutable(args.orthanc), |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
92 '--config=%s' % CONFIG ]) |
1 | 93 |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
94 with open(CONFIG, 'rt') as f: |
1 | 95 config = f.read() |
96 | |
30 | 97 if args.docker and args.server == 'localhost': |
98 args.server = GetDockerHostAddress() | |
99 | |
1 | 100 config = re.sub(r'("StorageDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config) |
101 config = re.sub(r'("IndexDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config) | |
102 config = re.sub(r'("DicomAet"\s*:)\s*".*?"', r'\1 "ORTHANCTEST"', config) | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
103 config = re.sub(r'("DicomPort"\s*:)\s*.*?,', r'\1 5001,', config) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
104 config = re.sub(r'("HttpPort"\s*:)\s*.*?,', r'\1 5000,', config) |
1 | 105 config = re.sub(r'("RemoteAccessAllowed"\s*:)\s*false', r'\1 true', config) |
407
ad98466353c6
test_modify_subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
106 config = re.sub(r'("AuthenticationEnabled"\s*:)\s*false,', r'', config) # Set with "RegisteredUsers" |
ad98466353c6
test_modify_subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
107 config = re.sub(r'("RegisteredUsers"\s*:)\s*{', r'"AuthenticationEnabled" : true, \1 { "alice" : "orthanctest"', config) |
ad98466353c6
test_modify_subsequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
108 config = re.sub(r'("ExecuteLuaEnabled"\s*:)\s*false', r'\1 true', config) |
35 | 109 config = re.sub(r'("HttpCompressionEnabled"\s*:)\s*true', r'\1 false', config) |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
13
diff
changeset
|
110 config = re.sub(r'("DicomAssociationCloseDelay"\s*:)\s*[0-9]*', r'\1 0', config) |
107
fddb35f7289d
test_bitbucket_issue_44
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
111 config = re.sub(r'("DicomModalities"\s*:)\s*{', r'\1 { "orthanc" : [ "%s", "%s", %s ]' % |
1 | 112 (args.aet, args.server, args.dicom), config) |
113 | |
289
4a70411ac9ad
test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
260
diff
changeset
|
114 # New to test transcoding over DICOM (1.7.0) |
4a70411ac9ad
test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
260
diff
changeset
|
115 config = re.sub(r'("RleTransferSyntaxAccepted"\s*:)\s*true', r'\1 false', config) |
4a70411ac9ad
test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
260
diff
changeset
|
116 |
4a70411ac9ad
test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
260
diff
changeset
|
117 |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
118 with open(CONFIG, 'wt') as f: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
119 f.write(config) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
120 |
1 | 121 localOrthanc = ExternalCommandThread([ |
342
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
122 Toolbox.FindExecutable(args.orthanc), |
bf8369ea3ff1
more tests of webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
123 CONFIG, |
294
192665e6113f
instruction to run on Windows (with WSL)
Alain Mazy <alain@mazy.be>
parents:
289
diff
changeset
|
124 #'--verbose', |
192665e6113f
instruction to run on Windows (with WSL)
Alain Mazy <alain@mazy.be>
parents:
289
diff
changeset
|
125 #'--no-jobs' |
27 | 126 #'/home/jodogne/Subversion/Orthanc/i/Orthanc', CONFIG, '--verbose' |
127 ]) | |
1 | 128 |
129 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
130 LOCAL = DefineOrthanc(aet = 'ORTHANCTEST', |
30 | 131 server = 'localhost', |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
132 dicomPort = 5001, |
13 | 133 restPort = 5000, |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
134 username = 'alice', |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
135 password = 'orthanctest') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
136 |
13 | 137 REMOTE = DefineOrthanc(server = args.server, |
1 | 138 username = args.username, |
139 password = args.password, | |
140 aet = args.aet, | |
13 | 141 dicomPort = args.dicom, |
142 restPort = args.rest) | |
1 | 143 |
144 | |
145 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
146 print('Parameters of the instance of Orthanc being tested:') |
3 | 147 pprint.pprint(REMOTE) |
2 | 148 print('') |
1 | 149 |
150 | |
2 | 151 print('Waiting for the internal Orthanc to start...') |
152 while True: | |
153 try: | |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
154 Toolbox.DoGet(LOCAL, '/instances') |
2 | 155 break |
156 except: | |
157 time.sleep(0.1) | |
1 | 158 |
159 | |
160 try: | |
3 | 161 print('\nStarting the tests...') |
306
da2be3ff2db5
fix getscu binaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
294
diff
changeset
|
162 SetOrthancParameters(LOCAL, REMOTE, args.docker) |
83 | 163 |
378
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
164 # Change the order of the tests |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
165 # https://stackoverflow.com/a/4006044/881731 |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
166 # https://stackoverflow.com/a/54923706/881731 |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
167 |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
168 # Reverse order |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
169 # unittest.TestLoader.sortTestMethodsUsing = lambda _, x, y: cmp(y, x) |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
170 |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
171 # import random |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
172 # random.seed(25) |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
173 # unittest.TestLoader.sortTestMethodsUsing = lambda self, a, b: random.choice([1, 0, -1]) |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
174 |
6 | 175 unittest.main(argv = [ sys.argv[0] ] + args.options) |
1 | 176 |
83 | 177 |
1 | 178 finally: |
3 | 179 print('\nDone') |
180 | |
1 | 181 # The tests have stopped or "Ctrl-C" has been hit |
182 try: | |
183 localOrthanc.stop() | |
184 except: | |
185 pass |