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