Mercurial > hg > orthanc-tests
annotate Tests/Run.py @ 158:df1f9946571c
perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
author | am@osimis.io |
---|---|
date | Fri, 17 Aug 2018 11:58:26 +0200 |
parents | 50cd127e5330 |
children | af8e034f4262 |
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 |
130
50cd127e5330
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
107
diff
changeset
|
6 # Copyright (C) 2017-2018 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 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
108 with open(CONFIG, 'wt') as f: |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
109 f.write(config) |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
110 |
1 | 111 localOrthanc = ExternalCommandThread([ |
27 | 112 'Orthanc', CONFIG, #'--verbose', |
113 #'/home/jodogne/Subversion/Orthanc/i/Orthanc', CONFIG, '--verbose' | |
114 ]) | |
1 | 115 |
116 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
117 LOCAL = DefineOrthanc(aet = 'ORTHANCTEST', |
30 | 118 server = 'localhost', |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
119 dicomPort = 5001, |
13 | 120 restPort = 5000, |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
121 username = 'alice', |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
122 password = 'orthanctest') |
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
123 |
13 | 124 REMOTE = DefineOrthanc(server = args.server, |
1 | 125 username = args.username, |
126 password = args.password, | |
127 aet = args.aet, | |
13 | 128 dicomPort = args.dicom, |
129 restPort = args.rest) | |
1 | 130 |
131 | |
132 | |
8
f8d781d1d267
test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
6
diff
changeset
|
133 print('Parameters of the instance of Orthanc being tested:') |
3 | 134 pprint.pprint(REMOTE) |
2 | 135 print('') |
1 | 136 |
137 | |
2 | 138 print('Waiting for the internal Orthanc to start...') |
139 while True: | |
140 try: | |
44
ffa542cce638
Toolbox.FindExecutable()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
141 Toolbox.DoGet(LOCAL, '/instances') |
2 | 142 break |
143 except: | |
144 time.sleep(0.1) | |
1 | 145 |
146 | |
147 try: | |
3 | 148 print('\nStarting the tests...') |
2 | 149 SetOrthancParameters(LOCAL, REMOTE) |
83 | 150 |
6 | 151 unittest.main(argv = [ sys.argv[0] ] + args.options) |
1 | 152 |
83 | 153 |
1 | 154 finally: |
3 | 155 print('\nDone') |
156 | |
1 | 157 # The tests have stopped or "Ctrl-C" has been hit |
158 try: | |
159 localOrthanc.stop() | |
160 except: | |
161 pass |