comparison Tests/Run.py @ 3:2dbba2e6aa4b

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 17 Jun 2015 10:03:49 +0200
parents Run.py@a15734e7f0af
children 292a46fe374c
comparison
equal deleted inserted replaced
2:a15734e7f0af 3:2dbba2e6aa4b
1 #!/usr/bin/python
2
3 # Orthanc - A Lightweight, RESTful DICOM Store
4 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
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
26 import pprint
27
28 from ExternalCommandThread import *
29 from Toolbox import *
30 from Tests import *
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',
39 default = GetDockerHostAddress(),
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',
53 default = 'alice',
54 help = 'Username to the REST API')
55 parser.add_argument('--password',
56 default = 'orthanctest',
57 help = 'Password to the REST API')
58 parser.add_argument('--force', help = 'Do not warn the user',
59 action = 'store_true')
60
61 args = parser.parse_args()
62
63 if not args.force:
64 print("""
65 WARNING: This test will remove all the content of your
66 Orthanc instance running on %s!
67
68 Are you sure ["yes" to go on]?""" % args.server)
69
70 if sys.stdin.readline().strip() != 'yes':
71 print('Aborting...')
72 exit(0)
73
74
75
76 ##
77 ## Generate the configuration file for the anciliary instance of
78 ## Orthanc
79 ##
80
81 CONFIG = '/tmp/Configuration.json'
82 subprocess.check_call([ 'Orthanc', '--config=%s' % CONFIG ])
83
84 with open(CONFIG, 'r') as f:
85 config = f.read()
86
87 config = re.sub(r'("StorageDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config)
88 config = re.sub(r'("IndexDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config)
89 config = re.sub(r'("DicomAet"\s*:)\s*".*?"', r'\1 "ORTHANCTEST"', config)
90 config = re.sub(r'("RemoteAccessAllowed"\s*:)\s*false', r'\1 true', config)
91 config = re.sub(r'("AuthenticationEnabled"\s*:)\s*false', r'\1 true', config)
92 config = re.sub(r'("RegisteredUsers"\s*:)\s*{', r'\1 { "alice" : [ "orthanctest" ]', config)
93 config = re.sub(r'("DicomModalities"\s*:)\s*{', r'\1 { "orthanc" : [ "%s", "%s", "%s" ]' %
94 (args.aet, args.server, args.dicom), config)
95
96 localOrthanc = ExternalCommandThread([
97 'Orthanc', CONFIG, #'--verbose'
98 ])
99
100
101 LOCAL = DefineOrthanc(aet = 'ORTHANCTEST')
102 REMOTE = DefineOrthanc(url = 'http://%s:%d/' % (args.server, args.rest),
103 username = args.username,
104 password = args.password,
105 aet = args.aet,
106 dicomPort = args.dicom)
107
108
109
110 print('Parameters of the instance of Orthanc to test:')
111 pprint.pprint(REMOTE)
112 print('')
113
114
115 print('Waiting for the internal Orthanc to start...')
116 while True:
117 try:
118 DoGet(LOCAL, '/instances')
119 break
120 except:
121 time.sleep(0.1)
122
123
124 try:
125 print('\nStarting the tests...')
126 SetOrthancParameters(LOCAL, REMOTE)
127 unittest.main(argv = [ sys.argv[0] ]) #argv = args)
128
129 finally:
130 print('\nDone')
131
132 # The tests have stopped or "Ctrl-C" has been hit
133 try:
134 localOrthanc.stop()
135 except:
136 pass