Mercurial > hg > orthanc-tests
comparison PerfsDb/Tests/UploadFile.py @ 162:dbc42a03ee75
more perfs db tests
author | am@osimis.io |
---|---|
date | Mon, 20 Aug 2018 14:23:54 +0200 |
parents | 27b3b0df5f90 |
children |
comparison
equal
deleted
inserted
replaced
161:27b3b0df5f90 | 162:dbc42a03ee75 |
---|---|
1 import json | |
2 import tempfile | |
3 import base64 | |
4 from PIL import Image | |
5 | |
1 from Test import Test | 6 from Test import Test |
7 | |
2 | 8 |
3 class TestUploadFirstPatientFile(Test): | 9 class TestUploadFirstPatientFile(Test): |
4 | 10 |
5 def __init__(self, name:str = "UploadFirstPatientFile", filePath:str = "../Database/DummyCT.dcm"): | 11 def __init__(self, name:str = "UploadFirstPatientFile", filePath:str = "../Database/DummyCT.dcm"): |
6 super().__init__(name) | 12 super().__init__(name) |
35 self._clear() | 41 self._clear() |
36 | 42 |
37 # upload a source file that we will modify | 43 # upload a source file that we will modify |
38 self._sourceInstanceId = self._orthanc.uploadDicomFile(self._filePath) | 44 self._sourceInstanceId = self._orthanc.uploadDicomFile(self._filePath) |
39 | 45 |
46 # make sure no file is already in Orthanc before the upload | |
47 patient = self._orthanc.patients.find("UploadNextPatientFile") | |
48 if patient is not None: | |
49 self._orthanc.patients.delete(patient.id) | |
50 | |
40 # upload the first instance of this patient | 51 # upload the first instance of this patient |
41 self._dicomFileContent = self._modifyFile() | 52 self._dicomFileContent = self._modifyFile() |
42 self._orthanc.uploadDicom(self._dicomFileContent) | 53 self._orthanc.uploadDicom(self._dicomFileContent) |
43 | 54 |
44 | 55 |
72 "SeriesNumber": "1", | 83 "SeriesNumber": "1", |
73 "InstanceNumber": str(self._instanceIndex) | 84 "InstanceNumber": str(self._instanceIndex) |
74 }, | 85 }, |
75 deleteOriginal=False | 86 deleteOriginal=False |
76 ) | 87 ) |
88 | |
89 | |
90 | |
91 class TestUploadLargeFile10MB(Test): | |
92 | |
93 def __init__(self, name:str = "UploadLargeFile10MB"): | |
94 super().__init__(name) | |
95 self._instanceId = None | |
96 self._dicomFileContent = None | |
97 self._instanceIndex = 0 | |
98 | |
99 def beforeAll(self): | |
100 self._clear() | |
101 | |
102 # make sure no file is already in Orthanc before the upload | |
103 patient = self._orthanc.patients.find("UploadLargeFile") | |
104 if patient is not None: | |
105 self._orthanc.patients.delete(patient.id) | |
106 | |
107 # upload a source file that we will modify | |
108 self._sourceInstanceId = self._orthanc.post( | |
109 relativeUrl="tools/create-dicom", | |
110 data=json.dumps({ | |
111 "Tags": { | |
112 'PatientName' : 'UploadLargeFile', | |
113 'PatientID' : 'UploadLargeFile', | |
114 '8899-8899' : 'data:application/octet-stream;base64,' + base64.b64encode(b"\0" * 10000000).decode('utf-8') | |
115 } | |
116 }) | |
117 ).json()["ID"] | |
118 | |
119 # upload the first instance of this patient | |
120 self._dicomFileContent = self._modifyFile() | |
121 self._orthanc.uploadDicom(self._dicomFileContent) | |
122 | |
123 | |
124 | |
125 def beforeEach(self): | |
126 self._dicomFileContent = self._modifyFile() | |
127 | |
128 def test(self): | |
129 self._orthanc.uploadDicom(self._dicomFileContent) | |
130 | |
131 def afterAll(self): | |
132 self._clear() | |
133 | |
134 def _clear(self): | |
135 patient = self._orthanc.patients.find("UploadLargeFile") | |
136 if patient is not None: | |
137 self._orthanc.patients.delete(patient.id) | |
138 | |
139 def _modifyFile(self): | |
140 self._instanceIndex += 1 | |
141 return self._orthanc.instances.modify( | |
142 instanceId=self._sourceInstanceId, | |
143 replaceTags={ | |
144 "PatientName": "UploadLargeFile", | |
145 "PatientID": "UploadLargeFile", | |
146 "StudyDescription": "UploadLargeFile", | |
147 "SeriesDescription": "UploadLargeFile", | |
148 "SOPInstanceUID": "999998.888888.777777.666666.555555.44444", | |
149 "StudyInstanceUID": "999998.888888.777777.666666", | |
150 "SeriesInstanceUID": "999998.888888.777777.666666.555555", | |
151 "SeriesNumber": "1", | |
152 "InstanceNumber": str(self._instanceIndex) | |
153 }, | |
154 deleteOriginal=False | |
155 ) |