Mercurial > hg > orthanc-tests
annotate Tests/Run.py @ 450:eb46265e214f
Added tag Orthanc-1.10.0 for changeset 06eea14c5906
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Feb 2022 14:11:03 +0100 |
parents | 06eea14c5906 |
children | 77f868063bb3 |
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 |
449
06eea14c5906
upgrade year to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
445
diff
changeset
|
6 # Copyright (C) 2017-2022 Osimis S.A., Belgium |
06eea14c5906
upgrade year to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
445
diff
changeset
|
7 # Copyright (C) 2021-2022 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 | |
445
09ebdee8eda2
added test for /attachments/../info
Alain Mazy <am@osimis.io>
parents:
437
diff
changeset
|
129 print "toto" |
09ebdee8eda2
added test for /attachments/../info
Alain Mazy <am@osimis.io>
parents:
437
diff
changeset
|
130 |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
131 LOCAL = DefineOrthanc(aet = 'ORTHANCTEST', |
30 | 132 server = 'localhost', |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
133 dicomPort = 5001, |
13 | 134 restPort = 5000, |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
135 username = 'alice', |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
136 password = 'orthanctest') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
137 |
13 | 138 REMOTE = DefineOrthanc(server = args.server, |
1 | 139 username = args.username, |
140 password = args.password, | |
141 aet = args.aet, | |
13 | 142 dicomPort = args.dicom, |
143 restPort = args.rest) | |
1 | 144 |
145 | |
146 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
147 print('Parameters of the instance of Orthanc being tested:') |
3 | 148 pprint.pprint(REMOTE) |
2 | 149 print('') |
1 | 150 |
151 | |
2 | 152 print('Waiting for the internal Orthanc to start...') |
153 while True: | |
154 try: | |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
155 Toolbox.DoGet(LOCAL, '/instances') |
2 | 156 break |
157 except: | |
158 time.sleep(0.1) | |
1 | 159 |
160 | |
161 try: | |
3 | 162 print('\nStarting the tests...') |
306
da2be3ff2db5
fix getscu binaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
294
diff
changeset
|
163 SetOrthancParameters(LOCAL, REMOTE, args.docker) |
83 | 164 |
378
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
165 # Change the order of the tests |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
166 # https://stackoverflow.com/a/4006044/881731 |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
167 # https://stackoverflow.com/a/54923706/881731 |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
168 |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
169 # Reverse order |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
170 # unittest.TestLoader.sortTestMethodsUsing = lambda _, x, y: cmp(y, x) |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
171 |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
172 # import random |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
173 # random.seed(25) |
a4b8450a1158
fix test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
174 # 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
|
175 |
6 | 176 unittest.main(argv = [ sys.argv[0] ] + args.options) |
1 | 177 |
83 | 178 |
1 | 179 finally: |
3 | 180 print('\nDone') |
181 | |
1 | 182 # The tests have stopped or "Ctrl-C" has been hit |
183 try: | |
184 localOrthanc.stop() | |
185 except: | |
186 pass |