annotate PerfsDb/Tests/UploadFile.py @ 188:7d585263808b

new test: test_queries_hierarchy
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 08 Dec 2018 18:17:10 +0100
parents dbc42a03ee75
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
162
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
1 import json
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
2 import tempfile
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
3 import base64
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
4 from PIL import Image
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
5
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
6 from Test import Test
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
7
162
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
8
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
9 class TestUploadFirstPatientFile(Test):
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
10
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
11 def __init__(self, name:str = "UploadFirstPatientFile", filePath:str = "../Database/DummyCT.dcm"):
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
12 super().__init__(name)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
13 self._instanceId = None
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
14 self._filePath = filePath
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
15 self._dicomFileContent = None
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
16
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
17 def beforeAll(self):
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
18 # get the instance Id and dicom file content
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
19 if self._instanceId is None:
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
20 self._instanceId = self._orthanc.uploadDicomFile(self._filePath)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
21 self._dicomFileContent = self._orthanc.instances.getDicom(self._instanceId)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
22
158
df1f9946571c perfs db continued: tests working with tiny DBs on all setup but the sqliteplugin
am@osimis.io
parents: 156
diff changeset
23 def beforeEach(self):
156
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
24 # make sure the file is not in Orthanc before the upload
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
25 self._orthanc.instances.delete(self._instanceId)
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
26
f1a75985caa8 first Db test framework - work in progress
am@osimis.io
parents:
diff changeset
27 def test(self):
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
28 self._orthanc.uploadDicom(self._dicomFileContent)
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
29
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
30
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
31 class TestUploadNextPatientFile(Test):
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
32
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
33 def __init__(self, name:str = "UploadNextPatientFile", filePath:str = "../Database/DummyCT.dcm"):
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
34 super().__init__(name)
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
35 self._instanceId = None
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
36 self._filePath = filePath
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
37 self._dicomFileContent = None
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
38 self._instanceIndex = 0
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
39
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
40 def beforeAll(self):
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
41 self._clear()
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
42
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
43 # upload a source file that we will modify
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
44 self._sourceInstanceId = self._orthanc.uploadDicomFile(self._filePath)
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
45
162
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
46 # make sure no file is already in Orthanc before the upload
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
47 patient = self._orthanc.patients.find("UploadNextPatientFile")
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
48 if patient is not None:
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
49 self._orthanc.patients.delete(patient.id)
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
50
161
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
51 # upload the first instance of this patient
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
52 self._dicomFileContent = self._modifyFile()
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
53 self._orthanc.uploadDicom(self._dicomFileContent)
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
54
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
55
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
56
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
57 def beforeEach(self):
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
58 self._dicomFileContent = self._modifyFile()
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
59
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
60 def test(self):
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
61 self._orthanc.uploadDicom(self._dicomFileContent)
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
62
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
63 def afterAll(self):
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
64 self._clear()
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
65
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
66 def _clear(self):
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
67 patient = self._orthanc.patients.find("UploadNextPatientFile")
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
68 if patient is not None:
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
69 self._orthanc.patients.delete(patient.id)
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
70
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
71 def _modifyFile(self):
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
72 self._instanceIndex += 1
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
73 return self._orthanc.instances.modify(
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
74 instanceId=self._sourceInstanceId,
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
75 replaceTags={
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
76 "PatientName": "UploadNextPatientFile",
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
77 "PatientID": "UploadNextPatientFile",
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
78 "StudyDescription": "UploadNextPatientFile",
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
79 "SeriesDescription": "UploadNextPatientFile",
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
80 "SOPInstanceUID": "999999.888888.777777.666666.555555.44444",
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
81 "StudyInstanceUID": "999999.888888.777777.666666",
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
82 "SeriesInstanceUID": "999999.888888.777777.666666.555555",
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
83 "SeriesNumber": "1",
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
84 "InstanceNumber": str(self._instanceIndex)
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
85 },
27b3b0df5f90 2 upload tests
am@osimis.io
parents: 158
diff changeset
86 deleteOriginal=False
162
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
87 )
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
88
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
89
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
90
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
91 class TestUploadLargeFile10MB(Test):
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
92
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
93 def __init__(self, name:str = "UploadLargeFile10MB"):
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
94 super().__init__(name)
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
95 self._instanceId = None
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
96 self._dicomFileContent = None
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
97 self._instanceIndex = 0
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
98
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
99 def beforeAll(self):
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
100 self._clear()
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
101
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
102 # make sure no file is already in Orthanc before the upload
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
103 patient = self._orthanc.patients.find("UploadLargeFile")
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
104 if patient is not None:
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
105 self._orthanc.patients.delete(patient.id)
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
106
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
107 # upload a source file that we will modify
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
108 self._sourceInstanceId = self._orthanc.post(
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
109 relativeUrl="tools/create-dicom",
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
110 data=json.dumps({
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
111 "Tags": {
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
112 'PatientName' : 'UploadLargeFile',
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
113 'PatientID' : 'UploadLargeFile',
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
114 '8899-8899' : 'data:application/octet-stream;base64,' + base64.b64encode(b"\0" * 10000000).decode('utf-8')
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
115 }
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
116 })
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
117 ).json()["ID"]
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
118
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
119 # upload the first instance of this patient
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
120 self._dicomFileContent = self._modifyFile()
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
121 self._orthanc.uploadDicom(self._dicomFileContent)
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
122
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
123
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
124
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
125 def beforeEach(self):
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
126 self._dicomFileContent = self._modifyFile()
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
127
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
128 def test(self):
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
129 self._orthanc.uploadDicom(self._dicomFileContent)
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
130
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
131 def afterAll(self):
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
132 self._clear()
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
133
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
134 def _clear(self):
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
135 patient = self._orthanc.patients.find("UploadLargeFile")
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
136 if patient is not None:
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
137 self._orthanc.patients.delete(patient.id)
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
138
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
139 def _modifyFile(self):
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
140 self._instanceIndex += 1
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
141 return self._orthanc.instances.modify(
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
142 instanceId=self._sourceInstanceId,
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
143 replaceTags={
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
144 "PatientName": "UploadLargeFile",
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
145 "PatientID": "UploadLargeFile",
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
146 "StudyDescription": "UploadLargeFile",
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
147 "SeriesDescription": "UploadLargeFile",
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
148 "SOPInstanceUID": "999998.888888.777777.666666.555555.44444",
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
149 "StudyInstanceUID": "999998.888888.777777.666666",
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
150 "SeriesInstanceUID": "999998.888888.777777.666666.555555",
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
151 "SeriesNumber": "1",
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
152 "InstanceNumber": str(self._instanceIndex)
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
153 },
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
154 deleteOriginal=False
dbc42a03ee75 more perfs db tests
am@osimis.io
parents: 161
diff changeset
155 )