Mercurial > hg > orthanc-tests
annotate Plugins/Worklists/Run.py @ 520:a06d0a45c62f
Python 3 compatibility of GenerateConfigurationForTests.py
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 Apr 2023 10:48:04 +0200 |
parents | 933fe1bbce4f |
children | 6546ca088276 |
rev | line source |
---|---|
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
2 # -*- coding: utf-8 -*- |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
3 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 # Orthanc - A Lightweight, RESTful DICOM Store |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
afbac3eb28a5
integration tests of worklists
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 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # This program is free software: you can redistribute it and/or |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # modify it under the terms of the GNU General Public License as |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # published by the Free Software Foundation, either version 3 of the |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # License, or (at your option) any later version. |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # This program is distributed in the hope that it will be useful, but |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # WITHOUT ANY WARRANTY; without even the implied warranty of |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # General Public License for more details. |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 # |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 # You should have received a copy of the GNU General Public License |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 import argparse |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import os |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import pprint |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 import re |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 import subprocess |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 import sys |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 import tempfile |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 import unittest |
109
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
33 from shutil import copyfile |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests')) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 from Toolbox import * |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 ## Parse the command-line arguments |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 parser = argparse.ArgumentParser(description = 'Run the integration tests for the DICOM worklist plugin.') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 parser.add_argument('--server', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 default = 'localhost', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 help = 'Address of the Orthanc server to test') |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
48 parser.add_argument('--rest', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
49 type = int, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
50 default = 8042, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
51 help = 'Port to the REST API') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
52 parser.add_argument('--username', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
53 default = 'alice', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
54 help = 'Username to the REST API') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
55 parser.add_argument('--password', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
56 default = 'orthanctest', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
57 help = 'Password to the REST API') |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 parser.add_argument('--dicom', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 type = int, |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 default = 4242, |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 help = 'DICOM port of the Orthanc instance to test') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 parser.add_argument('options', metavar = 'N', nargs = '*', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 help='Arguments to Python unittest') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 args = parser.parse_args() |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
69 ORTHANC = DefineOrthanc(server = args.server, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
70 username = args.username, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
71 password = args.password, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
72 restPort = args.rest) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
73 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
74 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
75 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 ## Toolbox |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 DATABASE = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file__), '..', '..', 'Database', 'Worklists'))) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 WORKING = os.path.join(DATABASE, 'Working') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 |
108 | 83 print('Database directory: %s' % DATABASE) |
84 print('Working directory: %s' % WORKING) | |
85 | |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 try: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 os.mkdir(WORKING) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 except Exception as e: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 # The working folder has already been created |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 pass |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 def ClearDatabase(): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 for f in os.listdir(WORKING): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 if f != 'lockfile': |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 os.remove(os.path.join(WORKING, f)) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 |
109
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
97 def AddToDatabase(worklist): |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
98 extension = os.path.splitext(worklist)[1].lower() |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
99 source = os.path.join(DATABASE, worklist) |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
100 target = os.path.join(WORKING, os.path.basename(worklist) + '.wl') |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
101 |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
102 if extension == '.dump': |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
103 subprocess.check_call([ 'dump2dcm', '--write-xfer-little', source, target ]) |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
104 else: |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
105 copyfile(source, target) |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
106 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 def RunQuery(source, ignoreTags): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 with tempfile.NamedTemporaryFile() as f: |
93
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
110 subprocess.check_call([ 'dump2dcm', '--write-xfer-little', |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 os.path.join(DATABASE, source), f.name ]) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 a = subprocess.check_output([ 'findscu', '-v', '--call', 'ORTHANC', '-aet', 'ORTHANCTEST', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 args.server, str(args.dicom), f.name ], |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 stderr = subprocess.STDOUT).splitlines() |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 if len(filter(lambda x: x.startswith('E:'), a)) > 0: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 raise Exception('Error while running findscu') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 |
108 | 120 b = map(lambda x: x[3:], filter(lambda x: (x.startswith('I: ---') or |
121 x.startswith('W: ---') or | |
122 x.startswith('I: (') or | |
123 x.startswith('W: (')), a)) | |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 b = map(lambda x: re.sub(r'\s*#.*', '', x), b) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 answers = [] |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 current = [] |
108 | 128 isQuery = True |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 for l in b: |
108 | 131 l = l.replace('\0', '') |
132 | |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 if l[0] == '-': |
108 | 134 if isQuery: |
135 isQuery = False | |
136 else: | |
137 # This is a separator between DICOM datasets | |
138 if len(current) > 0: | |
139 answers.append(current) | |
140 current = [] | |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 else: |
108 | 143 if not isQuery: |
144 tag = l[1:10].lower() | |
145 if not tag in ignoreTags: | |
146 current.append(l) | |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 if len(current) > 0: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 answers.append(current) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 return answers |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 def CompareAnswers(expected, actual): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 if len(expected) != len(actual): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 return False |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 if len(expected) == 0: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 return True |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 for i in range(len(expected)): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 for j in range(len(actual)): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 if expected[i] == actual[j]: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 return True |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 return False |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
168 def ParseTopLevelTags(answer): |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
169 tags = {} |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
170 for line in answer: |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
171 m = re.match(r'^\(([0-9a-f]{4},[0-9a-f]{4})\)\s*..\s*\[([^]]*)\]', line) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
172 tags[m.group(1)] = m.group(2).strip() |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
173 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
174 return tags |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
175 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
176 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 ## The tests |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 class Orthanc(unittest.TestCase): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 def setUp(self): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 if (sys.version_info >= (3, 0)): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 # Remove annoying warnings about unclosed socket in Python 3 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 import warnings |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 warnings.simplefilter("ignore", ResourceWarning) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 ClearDatabase() |
174 | 189 DoPost(ORTHANC, '/tools/execute-script', 'function IncomingWorklistRequestFilter(query, origin) return query end', 'application/lua') |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 def test_single(self): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 for db in range(1, 11): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 ClearDatabase() |
91 | 195 AddToDatabase('Dcmtk/Database/wklist%d.dump' % db) |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 for query in range(0, 13): |
91 | 198 answers = RunQuery('Dcmtk/Queries/wlistqry%d.dump' % query, [ |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 '0008,0005', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 '0040,0004', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 '0040,0005', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 '0040,0020', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 ]) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 |
91 | 205 with open(os.path.join('%s/Dcmtk/Expected/single-%d-%d.json' % (DATABASE, db, query)), 'r') as f: |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 expected = json.loads(f.read()) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 self.assertTrue(CompareAnswers(expected, answers)) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 def test_all(self): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 ClearDatabase() |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 for db in range(1, 11): |
91 | 214 AddToDatabase('Dcmtk/Database/wklist%d.dump' % db) |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 for query in range(0, 13): |
91 | 217 answers = RunQuery('Dcmtk/Queries/wlistqry%d.dump' % query, [ |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 '0008,0005', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 '0040,0004', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 '0040,0005', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 '0040,0020', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 ]) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 |
91 | 224 with open(os.path.join('%s/Dcmtk/Expected/all-%d.json' % (DATABASE, query)), 'r') as f: |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 expected = json.loads(f.read()) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 self.assertTrue(CompareAnswers(expected, answers)) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 |
93
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
229 def test_vet(self): |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
230 AddToDatabase('Sequences/STATION_AET/orig.7705.dump') |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
231 AddToDatabase('Sequences/STATION_AET/orig.7814.dump') |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
232 AddToDatabase('Sequences/STATION_AET/orig.7814.without.seq.dump') |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
233 |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
234 self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.length.dump', []))) |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
235 self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.seq.dump', []))) |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
236 self.assertEqual(2, len(RunQuery('Sequences/Queries/orig.7814.dump', []))) |
97 | 237 |
238 | |
98 | 239 @unittest.skip("This test requires to enable option 'FilterIssuerAet' in the sample worklist plugin") |
240 def test_filter_issuer_aet(self): | |
97 | 241 AddToDatabase('Sequences/STATION_AET/orig.7814.dump') |
98 | 242 AddToDatabase('Sequences/STATION_AET/orig.7814.other.station.dump') |
97 | 243 |
98 | 244 self.assertEqual(1, len(RunQuery('Sequences/Queries/7814.without.station.aet.dump', []))) |
93
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
245 |
174 | 246 def test_filter_issuer_aet_from_lua(self): |
247 AddToDatabase('Sequences/STATION_AET/orig.7814.dump') # targeted at STATION_AET | |
248 AddToDatabase('Sequences/STATION_AET/orig.7814.other.station.dump') # targeted at ORTHANC_TEST | |
249 | |
250 self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.station.aet.dump', []))) # query is not targeting any station -> match all | |
251 InstallLuaScript(ORTHANC, "\ | |
252 function IncomingWorklistRequestFilter(query, origin)\ | |
253 query['0040,0100'][1]['0040,0001'] = origin['RemoteAet']\ | |
254 return query\ | |
255 end"); | |
256 | |
257 self.assertEqual(1, len(RunQuery('Sequences/Queries/7814.without.station.aet.dump', []))) # now, query is targeting ORTHANCTEST -> match one | |
258 | |
259 | |
260 def test_remove_aet_from_query(self): | |
261 AddToDatabase('Sequences/NO_STATION_AET/orig.7814.other.station.dump') # targeted at ORTHANCTEST | |
262 | |
263 self.assertEqual(0, len(RunQuery('Sequences/Queries/orig.7814.dump', []))) # query is targeting STATION_AET -> will not match | |
264 InstallLuaScript(ORTHANC, "\ | |
265 function IncomingWorklistRequestFilter(query, origin)\ | |
266 query['0040,0100'][1]['0040,0001'] = nil\ | |
267 return query\ | |
268 end"); | |
269 self.assertEqual(1, len(RunQuery('Sequences/Queries/orig.7814.dump', []))) # query is targeting STATION_AET but, since we have removed this field, we should get 2 queries | |
93
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
270 |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
271 def test_encodings(self): |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
272 # Check out ../../Database/Worklists/Encodings/database.dump |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
273 TEST = u'Test-éüäöòДΘĝדصķћ๛ネİ' |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
274 ENCODINGS = { |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
275 'Arabic' : [ 'ISO_IR 127' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
276 'Ascii' : [ 'ISO_IR 6' ], # More accurately, ISO 646 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
277 'Cyrillic' : [ 'ISO_IR 144' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
278 'Greek' : [ 'ISO_IR 126' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
279 'Hebrew' : [ 'ISO_IR 138' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
280 'Japanese' : [ 'ISO_IR 13', 'shift-jis' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
281 'Latin1' : [ 'ISO_IR 100' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
282 'Latin2' : [ 'ISO_IR 101' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
283 'Latin3' : [ 'ISO_IR 109' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
284 'Latin4' : [ 'ISO_IR 110' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
285 'Latin5' : [ 'ISO_IR 148' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
286 'Thai' : [ 'ISO_IR 166', 'tis-620' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
287 'Utf8' : [ 'ISO_IR 192' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
288 } |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
289 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
290 AddToDatabase('Encodings/database.dump') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
291 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
292 for name, encoding in ENCODINGS.iteritems(): |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
293 self.assertEqual(name, DoPut(ORTHANC, '/tools/default-encoding', name)) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
294 result = RunQuery('Encodings/query.dump', []) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
295 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
296 self.assertEqual(1, len(result)) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
297 self.assertEqual(2, len(result[0])) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
298 tags = ParseTopLevelTags(result[0]) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
299 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
300 if len(encoding) == 1: |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
301 encoded = TEST.encode(name, 'ignore') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
302 else: |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
303 encoded = TEST.encode(encoding[1], 'ignore') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
304 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
305 self.assertEqual(encoding[0], tags['0008,0005']) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
306 self.assertEqual(encoded, tags['0010,0010']) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
307 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
308 |
109
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
309 def test_bitbucket_issue_49(self): |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
310 def Check(encoding, expectedEncoding, expectedContent): |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
311 DoPut(ORTHANC, '/tools/default-encoding', encoding) |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
312 result = RunQuery('Encodings/issue49-latin1.query', []) |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
313 self.assertEqual(1, len(result)) |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
314 self.assertEqual(2, len(result[0])) |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
315 tags = ParseTopLevelTags(result[0]) |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
316 self.assertEqual(expectedEncoding, tags['0008,0005']) |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
317 self.assertEqual(expectedContent, tags['0010,0010']) |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
318 |
109
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
319 AddToDatabase('Encodings/issue49-latin1.wl') |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
320 Check('Ascii', 'ISO_IR 6', r'VANILL^LAURA^^^Mme') |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
321 Check('Utf8', 'ISO_IR 192', r'VANILLÉ^LAURA^^^Mme') |
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
322 Check('Latin1', 'ISO_IR 100', u'VANILLÉ^LAURA^^^Mme'.encode('latin-1', 'ignore')) |
422
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
323 |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
324 |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
325 def test_format(self): |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
326 DoPut(ORTHANC, '/tools/default-encoding', 'Latin1') |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
327 AddToDatabase('Dcmtk/Database/wklist1.dump') |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
328 |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
329 # Only behavior of Orthanc <= 1.9.4 |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
330 a = DoPost(ORTHANC, '/modalities/self/find-worklist', { |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
331 'PatientID' : '' |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
332 }) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
333 self.assertEqual(1, len(a)) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
334 self.assertEqual(2, len(a[0])) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
335 self.assertEqual('AV35674', a[0]['PatientID']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
336 self.assertEqual('ISO_IR 100', a[0]['SpecificCharacterSet']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
337 |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
338 a = DoPost(ORTHANC, '/modalities/self/find-worklist', { |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
339 'Query' : { |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
340 'PatientID' : '' |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
341 } |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
342 }) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
343 self.assertEqual(1, len(a)) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
344 self.assertEqual(2, len(a[0])) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
345 self.assertEqual('AV35674', a[0]['PatientID']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
346 self.assertEqual('ISO_IR 100', a[0]['SpecificCharacterSet']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
347 |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
348 a = DoPost(ORTHANC, '/modalities/self/find-worklist', { |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
349 'Query' : { |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
350 'PatientID' : '' |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
351 }, |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
352 'Short' : True |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
353 }) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
354 self.assertEqual(1, len(a)) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
355 self.assertEqual(2, len(a[0])) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
356 self.assertEqual('AV35674', a[0]['0010,0020']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
357 self.assertEqual('ISO_IR 100', a[0]['0008,0005']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
358 |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
359 a = DoPost(ORTHANC, '/modalities/self/find-worklist', { |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
360 'Query' : { |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
361 'PatientID' : '' |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
362 }, |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
363 'Full' : True |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
364 }) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
365 self.assertEqual(1, len(a)) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
366 self.assertEqual(2, len(a[0])) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
367 self.assertEqual('AV35674', a[0]['0010,0020']['Value']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
368 self.assertEqual('PatientID', a[0]['0010,0020']['Name']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
369 self.assertEqual('ISO_IR 100', a[0]['0008,0005']['Value']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
370 self.assertEqual('SpecificCharacterSet', a[0]['0008,0005']['Name']) |
91170313187c
worklists: test_format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
371 |
109
5b6812f8cc38
worklists: test_bitbucket_issue_49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
108
diff
changeset
|
372 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 try: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 print('\nStarting the tests...') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
375 unittest.main(argv = [ sys.argv[0] ] + args.options) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 finally: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 print('\nDone') |