Mercurial > hg > orthanc-tests
annotate Tests/Run.py @ 289:4a70411ac9ad
test_storescu_transcoding
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 May 2020 11:12:06 +0200 |
parents | 943166deebcb |
children | 192665e6113f |
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 |
260
943166deebcb
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
195
diff
changeset
|
6 # Copyright (C) 2017-2020 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') |
6 | 62 parser.add_argument('options', metavar = 'N', nargs = '*', |
63 help='Arguments to Python unittest') | |
1 | 64 |
65 args = parser.parse_args() | |
66 | |
67 if not args.force: | |
68 print(""" | |
69 WARNING: This test will remove all the content of your | |
70 Orthanc instance running on %s! | |
71 | |
72 Are you sure ["yes" to go on]?""" % args.server) | |
73 | |
74 if sys.stdin.readline().strip() != 'yes': | |
75 print('Aborting...') | |
76 exit(0) | |
77 | |
78 | |
79 | |
80 ## | |
81 ## Generate the configuration file for the anciliary instance of | |
82 ## Orthanc | |
83 ## | |
84 | |
21
2a29bcff60a7
tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
13
diff
changeset
|
85 CONFIG = '/tmp/IntegrationTestsConfiguration.json' |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
86 subprocess.check_call([ Toolbox.FindExecutable('Orthanc'), |
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
87 '--config=%s' % CONFIG ]) |
1 | 88 |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
89 with open(CONFIG, 'rt') as f: |
1 | 90 config = f.read() |
91 | |
30 | 92 if args.docker and args.server == 'localhost': |
93 args.server = GetDockerHostAddress() | |
94 | |
1 | 95 config = re.sub(r'("StorageDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config) |
96 config = re.sub(r'("IndexDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config) | |
97 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
|
98 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
|
99 config = re.sub(r'("HttpPort"\s*:)\s*.*?,', r'\1 5000,', config) |
1 | 100 config = re.sub(r'("RemoteAccessAllowed"\s*:)\s*false', r'\1 true', config) |
101 config = re.sub(r'("AuthenticationEnabled"\s*:)\s*false', r'\1 true', config) | |
35 | 102 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
|
103 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
|
104 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
|
105 config = re.sub(r'("DicomModalities"\s*:)\s*{', r'\1 { "orthanc" : [ "%s", "%s", %s ]' % |
1 | 106 (args.aet, args.server, args.dicom), config) |
107 | |
289
4a70411ac9ad
test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
260
diff
changeset
|
108 # New to test transcoding over DICOM (1.7.0) |
4a70411ac9ad
test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
260
diff
changeset
|
109 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
|
110 |
4a70411ac9ad
test_storescu_transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
260
diff
changeset
|
111 |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
112 with open(CONFIG, 'wt') as f: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
113 f.write(config) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
114 |
1 | 115 localOrthanc = ExternalCommandThread([ |
27 | 116 'Orthanc', CONFIG, #'--verbose', |
117 #'/home/jodogne/Subversion/Orthanc/i/Orthanc', CONFIG, '--verbose' | |
118 ]) | |
1 | 119 |
120 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
121 LOCAL = DefineOrthanc(aet = 'ORTHANCTEST', |
30 | 122 server = 'localhost', |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
123 dicomPort = 5001, |
13 | 124 restPort = 5000, |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
125 username = 'alice', |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
126 password = 'orthanctest') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
127 |
13 | 128 REMOTE = DefineOrthanc(server = args.server, |
1 | 129 username = args.username, |
130 password = args.password, | |
131 aet = args.aet, | |
13 | 132 dicomPort = args.dicom, |
133 restPort = args.rest) | |
1 | 134 |
135 | |
136 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
137 print('Parameters of the instance of Orthanc being tested:') |
3 | 138 pprint.pprint(REMOTE) |
2 | 139 print('') |
1 | 140 |
141 | |
2 | 142 print('Waiting for the internal Orthanc to start...') |
143 while True: | |
144 try: | |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
145 Toolbox.DoGet(LOCAL, '/instances') |
2 | 146 break |
147 except: | |
148 time.sleep(0.1) | |
1 | 149 |
150 | |
151 try: | |
3 | 152 print('\nStarting the tests...') |
2 | 153 SetOrthancParameters(LOCAL, REMOTE) |
83 | 154 |
6 | 155 unittest.main(argv = [ sys.argv[0] ] + args.options) |
1 | 156 |
83 | 157 |
1 | 158 finally: |
3 | 159 print('\nDone') |
160 | |
1 | 161 # The tests have stopped or "Ctrl-C" has been hit |
162 try: | |
163 localOrthanc.stop() | |
164 except: | |
165 pass |