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