Mercurial > hg > orthanc-tests
annotate PerfsDb/Tests/UploadFile.py @ 657:9582c37652f4
Added tag Orthanc-1.12.4 for changeset 7bfc8992ab8f
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Jun 2024 17:53:36 +0200 |
parents | dbc42a03ee75 |
children |
rev | line source |
---|---|
162 | 1 import json |
2 import tempfile | |
3 import base64 | |
4 from PIL import Image | |
5 | |
156 | 6 from Test import Test |
7 | |
162 | 8 |
161 | 9 class TestUploadFirstPatientFile(Test): |
156 | 10 |
161 | 11 def __init__(self, name:str = "UploadFirstPatientFile", filePath:str = "../Database/DummyCT.dcm"): |
156 | 12 super().__init__(name) |
13 self._instanceId = None | |
14 self._filePath = filePath | |
15 self._dicomFileContent = None | |
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 | 18 # get the instance Id and dicom file content |
19 if self._instanceId is None: | |
20 self._instanceId = self._orthanc.uploadDicomFile(self._filePath) | |
21 self._dicomFileContent = self._orthanc.instances.getDicom(self._instanceId) | |
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 | 24 # make sure the file is not in Orthanc before the upload |
25 self._orthanc.instances.delete(self._instanceId) | |
26 | |
27 def test(self): | |
161 | 28 self._orthanc.uploadDicom(self._dicomFileContent) |
29 | |
30 | |
31 class TestUploadNextPatientFile(Test): | |
32 | |
33 def __init__(self, name:str = "UploadNextPatientFile", filePath:str = "../Database/DummyCT.dcm"): | |
34 super().__init__(name) | |
35 self._instanceId = None | |
36 self._filePath = filePath | |
37 self._dicomFileContent = None | |
38 self._instanceIndex = 0 | |
39 | |
40 def beforeAll(self): | |
41 self._clear() | |
42 | |
43 # upload a source file that we will modify | |
44 self._sourceInstanceId = self._orthanc.uploadDicomFile(self._filePath) | |
45 | |
162 | 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 | |
161 | 51 # upload the first instance of this patient |
52 self._dicomFileContent = self._modifyFile() | |
53 self._orthanc.uploadDicom(self._dicomFileContent) | |
54 | |
55 | |
56 | |
57 def beforeEach(self): | |
58 self._dicomFileContent = self._modifyFile() | |
59 | |
60 def test(self): | |
61 self._orthanc.uploadDicom(self._dicomFileContent) | |
62 | |
63 def afterAll(self): | |
64 self._clear() | |
65 | |
66 def _clear(self): | |
67 patient = self._orthanc.patients.find("UploadNextPatientFile") | |
68 if patient is not None: | |
69 self._orthanc.patients.delete(patient.id) | |
70 | |
71 def _modifyFile(self): | |
72 self._instanceIndex += 1 | |
73 return self._orthanc.instances.modify( | |
74 instanceId=self._sourceInstanceId, | |
75 replaceTags={ | |
76 "PatientName": "UploadNextPatientFile", | |
77 "PatientID": "UploadNextPatientFile", | |
78 "StudyDescription": "UploadNextPatientFile", | |
79 "SeriesDescription": "UploadNextPatientFile", | |
80 "SOPInstanceUID": "999999.888888.777777.666666.555555.44444", | |
81 "StudyInstanceUID": "999999.888888.777777.666666", | |
82 "SeriesInstanceUID": "999999.888888.777777.666666.555555", | |
83 "SeriesNumber": "1", | |
84 "InstanceNumber": str(self._instanceIndex) | |
85 }, | |
86 deleteOriginal=False | |
162 | 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 ) |