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