annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 # modify it under the terms of the GNU General Public License as
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # published by the Free Software Foundation, either version 3 of the
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 #
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # General Public License for more details.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 #
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # You should have received a copy of the GNU General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 import re
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 import sys
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 import argparse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import subprocess
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import unittest
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
26 import pprint
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 from ExternalCommandThread import *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 from Toolbox import *
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
30 from Tests import *
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 ##
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 ## Parse the command-line arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 ##
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 parser = argparse.ArgumentParser(description = 'Run the integration tests on some instance of Orthanc.')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 parser.add_argument('--server',
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 default = GetDockerHostAddress(),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 help = 'Address of the Orthanc server to test')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 parser.add_argument('--aet',
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 default = 'ORTHANC',
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 help = 'AET of the Orthanc instance to test')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 parser.add_argument('--dicom',
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 type = int,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 default = 4242,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 help = 'DICOM port of the Orthanc instance to test')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 parser.add_argument('--rest',
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 type = int,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 default = 8042,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 help = 'Port to the REST API')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 parser.add_argument('--username',
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
53 default = 'alice',
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 help = 'Username to the REST API')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 parser.add_argument('--password',
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
56 default = 'orthanctest',
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 help = 'Password to the REST API')
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
58 parser.add_argument('--force', help = 'Do not warn the user',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
59 action = 'store_true')
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 args = parser.parse_args()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 if not args.force:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 print("""
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 WARNING: This test will remove all the content of your
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 Orthanc instance running on %s!
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 Are you sure ["yes" to go on]?""" % args.server)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 if sys.stdin.readline().strip() != 'yes':
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 print('Aborting...')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 exit(0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ##
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 ## Generate the configuration file for the anciliary instance of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 ## Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ##
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 CONFIG = '/tmp/Configuration.json'
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 subprocess.check_call([ 'Orthanc', '--config=%s' % CONFIG ])
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 with open(CONFIG, 'r') as f:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 config = f.read()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 config = re.sub(r'("StorageDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 config = re.sub(r'("IndexDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 config = re.sub(r'("DicomAet"\s*:)\s*".*?"', r'\1 "ORTHANCTEST"', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 config = re.sub(r'("RemoteAccessAllowed"\s*:)\s*false', r'\1 true', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 config = re.sub(r'("AuthenticationEnabled"\s*:)\s*false', r'\1 true', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 config = re.sub(r'("RegisteredUsers"\s*:)\s*{', r'\1 { "alice" : [ "orthanctest" ]', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 config = re.sub(r'("DicomModalities"\s*:)\s*{', r'\1 { "orthanc" : [ "%s", "%s", "%s" ]' %
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 (args.aet, args.server, args.dicom), config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 localOrthanc = ExternalCommandThread([
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 'Orthanc', CONFIG, #'--verbose'
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 ])
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 LOCAL = DefineOrthanc(aet = 'ORTHANCTEST')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 REMOTE = DefineOrthanc(url = 'http://%s:%d/' % (args.server, args.rest),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 username = args.username,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 password = args.password,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 aet = args.aet,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 dicomPort = args.dicom)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
110 print('Parameters of the instance of Orthanc to test:')
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
111 pprint.pprint(REMOTE)
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
112 print('')
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
115 print('Waiting for the internal Orthanc to start...')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
116 while True:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
117 try:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
118 DoGet(LOCAL, '/instances')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
119 break
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
120 except:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
121 time.sleep(0.1)
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 try:
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
125 print('\nStarting the tests...')
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
126 SetOrthancParameters(LOCAL, REMOTE)
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 unittest.main(argv = [ sys.argv[0] ]) #argv = args)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 finally:
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
130 print('\nDone')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
131
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 # The tests have stopped or "Ctrl-C" has been hit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 try:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 localOrthanc.stop()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 except:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 pass