annotate Tests/Run.py @ 8:f8d781d1d267

test_changes, test_archive, test_media_archive
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 17 Jun 2015 13:45:54 +0200
parents 6d645b3011e1
children 7b69a561f4d3
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
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
28 from Tests import *
5
19eb87a45685 test_images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4
diff changeset
29 from Toolbox import DoGet
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
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 ## Parse the command-line arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 ##
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 parser = argparse.ArgumentParser(description = 'Run the integration tests on some instance of Orthanc.')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 help = 'Address of the Orthanc server to test')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 parser.add_argument('--aet',
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 default = 'ORTHANC',
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 help = 'AET of the Orthanc instance to test')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 parser.add_argument('--dicom',
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 type = int,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 default = 4242,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 help = 'DICOM port of the Orthanc instance to test')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 parser.add_argument('--rest',
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 type = int,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 default = 8042,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 help = 'Port to the REST API')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 parser.add_argument('--username',
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
52 default = 'alice',
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 help = 'Username to the REST API')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 parser.add_argument('--password',
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
55 default = 'orthanctest',
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 help = 'Password to the REST API')
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
57 parser.add_argument('--force', help = 'Do not warn the user',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
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
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
61 parser.add_argument('options', metavar = 'N', nargs = '*',
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
62 help='Arguments to Python unittest')
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 args = parser.parse_args()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 if not args.force:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 print("""
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 WARNING: This test will remove all the content of your
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 Orthanc instance running on %s!
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 Are you sure ["yes" to go on]?""" % args.server)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 if sys.stdin.readline().strip() != 'yes':
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 print('Aborting...')
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 exit(0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ##
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ## Generate the configuration file for the anciliary instance of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 ## Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 ##
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
8
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
84 if args.docker:
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
85 args.server = GetDockerHostAddress()
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
86
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 CONFIG = '/tmp/Configuration.json'
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 subprocess.check_call([ 'Orthanc', '--config=%s' % CONFIG ])
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
8
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
90 with open(CONFIG, 'rt') as f:
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 config = f.read()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 config = re.sub(r'("StorageDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 config = re.sub(r'("IndexDirectory"\s*:)\s*".*?"', r'\1 "/tmp/OrthancStorage"', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 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
96 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
97 config = re.sub(r'("HttpPort"\s*:)\s*.*?,', r'\1 5000,', config)
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 config = re.sub(r'("RemoteAccessAllowed"\s*:)\s*false', r'\1 true', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 config = re.sub(r'("AuthenticationEnabled"\s*:)\s*false', r'\1 true', config)
8
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
100 config = re.sub(r'("RegisteredUsers"\s*:)\s*{', r'\1 { "alice" : "orthanctest"', config)
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 config = re.sub(r'("DicomModalities"\s*:)\s*{', r'\1 { "orthanc" : [ "%s", "%s", "%s" ]' %
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 (args.aet, args.server, args.dicom), config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
8
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
104 with open(CONFIG, 'wt') as f:
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
105 f.write(config)
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
106
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 localOrthanc = ExternalCommandThread([
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 'Orthanc', CONFIG, #'--verbose'
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 ])
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
8
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
112 LOCAL = DefineOrthanc(aet = 'ORTHANCTEST',
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
113 url = 'http://localhost:5000',
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
114 dicomPort = 5001,
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
115 username = 'alice',
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
116 password = 'orthanctest')
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
117
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 REMOTE = DefineOrthanc(url = 'http://%s:%d/' % (args.server, args.rest),
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 username = args.username,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 password = args.password,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 aet = args.aet,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 dicomPort = args.dicom)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
8
f8d781d1d267 test_changes, test_archive, test_media_archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 6
diff changeset
126 print('Parameters of the instance of Orthanc being tested:')
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
127 pprint.pprint(REMOTE)
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
128 print('')
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
131 print('Waiting for the internal Orthanc to start...')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
132 while True:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
133 try:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
134 DoGet(LOCAL, '/instances')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
135 break
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
136 except:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
137 time.sleep(0.1)
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 try:
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
141 print('\nStarting the tests...')
2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
142 SetOrthancParameters(LOCAL, REMOTE)
6
6d645b3011e1 test_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
143 unittest.main(argv = [ sys.argv[0] ] + args.options)
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 finally:
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
146 print('\nDone')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
147
1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 # The tests have stopped or "Ctrl-C" has been hit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 try:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 localOrthanc.stop()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 except:
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 pass