Mercurial > hg > orthanc-tests
annotate NewTests/WithIngestTranscoding/test_with_ingest_transcoding.py @ 506:2170c10f9d49
added new tests with ingest transcoding
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 27 Jan 2023 12:51:18 +0100 |
parents | |
children |
rev | line source |
---|---|
506
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
1 import unittest |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
2 import time |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
3 import os |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
4 from helpers import OrthancTestCase, Helpers |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
5 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
6 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
7 from orthanc_tools import OrthancTestDbPopulator |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
8 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
9 import pathlib |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
10 import glob |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
11 import pprint |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 here = pathlib.Path(__file__).parent.resolve() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
14 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
16 class TestWithIngestTranscoding(OrthancTestCase): |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
18 @classmethod |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
19 def prepare(cls): |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 print('-------------- preparing TestWithIngestTranscoding tests') |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
21 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
22 cls.clear_storage(storage_name="WithIngestTranscoding") |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
23 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
24 config = { |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 "IngestTranscoding": "1.2.840.10008.1.2.4.70" |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 } |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
28 config_path = cls.generate_configuration( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
29 config_name="with_ingest_transcoding", |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
30 storage_name="WithIngestTranscoding", |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
31 config=config, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
32 plugins=Helpers.plugins |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 ) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
35 print('-------------- prepared TestWithIngestTranscoding tests') |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
36 if Helpers.break_after_preparation: |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
37 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++") |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
38 input("Press Enter to continue") |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
39 else: |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
40 print('-------------- launching TestWithIngestTranscoding tests') |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
41 cls.launch_orthanc_under_tests( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
42 config_path=config_path, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
43 config_name="with_ingest_transcoding", |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
44 storage_name="WithIngestTranscoding", |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
45 plugins=Helpers.plugins |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
46 ) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
47 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
48 print('-------------- waiting for orthanc-under-tests to be available') |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
49 cls.o.wait_started() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
50 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
51 def test_modify(self): |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
52 self.o.delete_all_content() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
53 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
54 # upload a study |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
55 self.o.upload_file(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
56 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
57 # first modify it without transcoding |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
58 r = self.o.post( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
59 endpoint="studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988/modify", |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
60 json={ |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
61 "Replace": {"PatientID": "TUTU"}, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
62 "Force": True, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
63 "KeepSource": True, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
64 "Synchronous": True |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
65 } |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
66 ).json() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
67 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
68 study_id = r['ID'] |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
69 instance_id = self.o.studies.get_first_instance_id(orthanc_id=study_id) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
70 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
71 r = self.o.get( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
72 endpoint=f"instances/{instance_id}/metadata?expand" |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
73 ).json() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
74 self.assertEqual("1.2.840.10008.1.2.4.70", r['TransferSyntax']) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
75 self.o.studies.delete(orthanc_id=study_id) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
76 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
77 # first modify it with transcoding -> IngestTranscoding shall not be applied |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
78 r = self.o.post( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
79 endpoint="studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988/modify", |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
80 json={ |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
81 "Replace": {"PatientID": "TUTU"}, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
82 "Force": True, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
83 "KeepSource": True, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
84 "Synchronous": True, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
85 "Transcode": "1.2.840.10008.1.2.4.80" |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
86 } |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
87 ).json() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
88 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
89 instance_id = self.o.studies.get_first_instance_id(orthanc_id=r['ID']) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
90 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
91 r = self.o.get( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
92 endpoint=f"instances/{instance_id}/metadata?expand" |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
93 ).json() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
94 self.assertEqual("1.2.840.10008.1.2.4.80", r['TransferSyntax']) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
95 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
96 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
97 def test_anonymize(self): |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
98 self.o.delete_all_content() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
99 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
100 # upload a study |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
101 self.o.upload_file(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
102 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
103 # first anonymize it without transcoding |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
104 r = self.o.post( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
105 endpoint="studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988/anonymize", |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
106 json={ |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
107 "Synchronous": True |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
108 } |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
109 ).json() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
110 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
111 study_id = r['ID'] |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
112 instance_id = self.o.studies.get_first_instance_id(orthanc_id=study_id) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
113 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
114 r = self.o.get( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
115 endpoint=f"instances/{instance_id}/metadata?expand" |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
116 ).json() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
117 self.assertEqual("1.2.840.10008.1.2.4.70", r['TransferSyntax']) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
118 self.o.studies.delete(orthanc_id=study_id) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
119 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
120 # first anonymize it with transcoding -> IngestTranscoding shall not be applied |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
121 r = self.o.post( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
122 endpoint="studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988/anonymize", |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
123 json={ |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
124 "Synchronous": True, |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
125 "Transcode": "1.2.840.10008.1.2.4.80" |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
126 } |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
127 ).json() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
128 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
129 instance_id = self.o.studies.get_first_instance_id(orthanc_id=r['ID']) |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
130 |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
131 r = self.o.get( |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
132 endpoint=f"instances/{instance_id}/metadata?expand" |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
133 ).json() |
2170c10f9d49
added new tests with ingest transcoding
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
134 self.assertEqual("1.2.840.10008.1.2.4.80", r['TransferSyntax']) |