annotate Plugins/Transfers/Run.py @ 633:7bb22f87fc5b

fix auth test wrt plugin version
author Alain Mazy <am@osimis.io>
date Tue, 19 Mar 2024 08:51:56 +0100
parents 933fe1bbce4f
children 9f8276ac1cdd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
232
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Orthanc - A Lightweight, RESTful DICOM Store
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 # Department, University Hospital of Liege, Belgium
511
933fe1bbce4f upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 449
diff changeset
8 # Copyright (C) 2017-2023 Osimis S.A., Belgium
933fe1bbce4f upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 449
diff changeset
9 # Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
232
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 #
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # This program is free software: you can redistribute it and/or
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # modify it under the terms of the GNU General Public License as
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # published by the Free Software Foundation, either version 3 of the
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # License, or (at your option) any later version.
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 #
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # This program is distributed in the hope that it will be useful, but
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # General Public License for more details.
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 #
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 # You should have received a copy of the GNU General Public License
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import os
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 import pprint
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 import sys
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 import argparse
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 import unittest
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 import re
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests'))
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 from Toolbox import *
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 ##
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 ## Parse the command-line arguments
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 ##
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 parser = argparse.ArgumentParser(description = 'Run the integration tests for the DICOMweb plugin.')
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 parser.add_argument('--server',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 default = 'localhost',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 help = 'Address of the Orthanc server to test')
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 parser.add_argument('--rest',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 type = int,
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 default = 8042,
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 help = 'Port to the REST API')
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 parser.add_argument('--username',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 default = 'alice',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 help = 'Username to the REST API')
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 parser.add_argument('--password',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 default = 'orthanctest',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 help = 'Password to the REST API')
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 parser.add_argument('--force', help = 'Do not warn the user',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 action = 'store_true')
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 parser.add_argument('options', metavar = 'N', nargs = '*',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 help='Arguments to Python unittest')
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 args = parser.parse_args()
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 ##
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ## Configure the testing context
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ##
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 if not args.force:
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 print("""
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 WARNING: This test will remove all the content of your
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 Orthanc instance running on %s!
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 Are you sure ["yes" to go on]?""" % args.server)
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 if sys.stdin.readline().strip() != 'yes':
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 print('Aborting...')
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 exit(0)
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ORTHANC = DefineOrthanc(server = args.server,
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 username = args.username,
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 password = args.password,
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 restPort = args.rest)
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 ##
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ## The tests
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ##
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 class Orthanc(unittest.TestCase):
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 def setUp(self):
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (sys.version_info >= (3, 0)):
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 # Remove annoying warnings about unclosed socket in Python 3
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 import warnings
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 warnings.simplefilter("ignore", ResourceWarning)
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 DropOrthanc(ORTHANC)
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 def test_list_peers(self):
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 peers = DoGet(ORTHANC, '/transfers/peers')
330
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
102 self.assertEqual(4, len(peers)) # "self" peer was added in Orthanc 1.7.3
232
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 self.assertEqual('disabled', peers['peer'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 self.assertEqual('installed', peers['transfers-simple'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 self.assertEqual('bidirectional', peers['transfers-bidirectional'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 def test_pull(self):
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID']
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 a = DoPost(ORTHANC, '/transfers/pull', {
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 'Compression' : 'gzip',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 'Peer' : 'transfers-simple',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 'Resources' : [
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 'Level' : 'Instance',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 'ID' : i
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 },
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 ],
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 'Priority' : 10,
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 })
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 WaitJobDone(ORTHANC, a['ID'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 b = DoGet(ORTHANC, '/jobs/%s' % a['ID'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 self.assertEqual('PullTransfer', b['Type'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 self.assertEqual('Success', b['State'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 self.assertEqual(a['ID'], b['ID'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 self.assertEqual(10, b['Priority'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 self.assertEqual('gzip', b['Content']['Compression'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 self.assertEqual(1, b['Content']['CompletedHttpQueries'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 self.assertEqual('transfers-simple', b['Content']['Peer'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 self.assertEqual(1, b['Content']['TotalInstances'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 def test_send_push(self):
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID']
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 a = DoPost(ORTHANC, '/transfers/send', {
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 'Compression' : 'gzip',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 'Peer' : 'transfers-simple',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 'Resources' : [
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 'Level' : 'Instance',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 'ID' : i
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 },
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 ],
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 'Priority' : -10,
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 })
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 WaitJobDone(ORTHANC, a['ID'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 b = DoGet(ORTHANC, '/jobs/%s' % a['ID'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 self.assertEqual('PushTransfer', b['Type'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 self.assertEqual('Success', b['State'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 self.assertEqual(a['ID'], b['ID'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 self.assertEqual(-10, b['Priority'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 self.assertEqual('gzip', b['Content']['Compression'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 self.assertEqual(1, b['Content']['CompletedHttpQueries'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 self.assertEqual('transfers-simple', b['Content']['Peer'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 self.assertEqual(1, b['Content']['TotalInstances'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 def test_send_bidirectional(self):
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 i = UploadInstance(ORTHANC, 'DummyCT.dcm')['ID']
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 a = DoPost(ORTHANC, '/transfers/send', {
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 'Compression' : 'gzip',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 'Peer' : 'transfers-bidirectional',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 'Resources' : [
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 'Level' : 'Instance',
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 'ID' : i
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 },
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 ],
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 'Priority' : 42,
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 })
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 self.assertEqual(3, len(a))
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 self.assertEqual('transfers-bidirectional', a['Peer'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 self.assertTrue('RemoteJob' in a)
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 self.assertTrue('URL' in a)
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 # In this integration test, the remote peer is the same as the local peer
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 WaitJobDone(ORTHANC, a['RemoteJob'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 b = DoGet(ORTHANC, '/jobs/%s' % a['RemoteJob'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 self.assertEqual('PullTransfer', b['Type'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 self.assertEqual('Success', b['State'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 self.assertEqual(a['RemoteJob'], b['ID'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 self.assertEqual(0, b['Priority']) # Priority is chosen by the remote peer
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 self.assertEqual('gzip', b['Content']['Compression'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 self.assertEqual(1, b['Content']['CompletedHttpQueries'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 self.assertEqual('transfers-bidirectional', b['Content']['Peer'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 self.assertEqual(1, b['Content']['TotalInstances'])
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 try:
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 print('\nStarting the tests...')
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 unittest.main(argv = [ sys.argv[0] ] + args.options)
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 finally:
f2af7bdc9bf8 tests for transfers accelerator
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 print('\nDone')