annotate NewTests/Housekeeper/test_housekeeper2.py @ 700:8561d9c88d1a

fix
author Alain Mazy <am@orthanc.team>
date Thu, 26 Sep 2024 12:27:52 +0200
parents 810390d3968a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
648
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
1 import unittest
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
2 import time
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
3 from helpers import OrthancTestCase, Helpers
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
4
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
5 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
6
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
7 import pathlib
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
8 here = pathlib.Path(__file__).parent.resolve()
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
9
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
10
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
11 class TestHousekeeper2(OrthancTestCase):
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
12
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
13 @classmethod
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
14 def prepare(cls):
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
15 print('-------------- preparing TestHousekeeper2 tests')
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
16
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
17 cls.clear_storage(storage_name="housekeeper2")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
18
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
19 cls.launch_orthanc_to_prepare_db(
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
20 config_name="housekeeper2_preparation",
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
21 storage_name="housekeeper2",
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
22 config={
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
23 "Housekeeper": {
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
24 "Enable": False
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
25 }
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
26 },
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
27 plugins=Helpers.plugins
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
28 )
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
29
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
30 # upload a study and keep track of data before housekeeper runs
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
31 cls.o.upload_folder(here / "../../Database/Knix/Loc")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
32
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
33 cls.instance_before, cls.series_before, cls.study_before, cls.patient_before, cls.instance_metadata_before = cls.get_infos()
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
34
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
35 cls.kill_orthanc()
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
36 time.sleep(3)
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
37
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
38 # generate config for orthanc-under-tests (change StorageCompression and add ExtraMainDicomTags)
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
39 config_path = cls.generate_configuration(
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
40 config_name="housekeeper2_under_test",
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
41 storage_name="housekeeper2",
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
42 config={
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
43 "IngestTranscoding": "1.2.840.10008.1.2.4.80",
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
44 "ExtraMainDicomTags": {
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
45 "Patient" : ["PatientWeight", "PatientAge"],
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
46 "Study": ["NameOfPhysiciansReadingStudy"],
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
47 "Series": ["ScanOptions"],
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
48 "Instance": ["Rows", "Columns", "DerivationCodeSequence"]
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
49 },
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
50 "Housekeeper": {
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
51 "Enable": True
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
52 },
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
53 "KeepAliveTimeout": 2
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
54 },
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
55 plugins=Helpers.plugins
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
56 )
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
57
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
58 print('-------------- prepared TestHousekeeper2 tests')
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
59 if Helpers.break_after_preparation:
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
60 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
61 input("Press Enter to continue")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
62 else:
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
63 print('-------------- launching TestHousekeeper2 tests')
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
64 cls.launch_orthanc_under_tests(
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
65 config_path=config_path,
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
66 config_name="housekeeper2_under_test",
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
67 storage_name="housekeeper2",
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
68 plugins=Helpers.plugins,
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
69 enable_verbose=False
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
70 )
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
71
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
72 print('-------------- waiting for orthanc-under-tests to be available')
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
73 cls.o.wait_started()
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
74
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
75 completed = False
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
76 while not completed:
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
77 print('-------------- waiting for housekeeper2 to finish processing')
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
78 time.sleep(1)
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
79 housekeeper_status = cls.o.get_json("plugins/housekeeper/status")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
80 completed = (housekeeper_status["LastProcessedConfiguration"]["IngestTranscoding"] == "1.2.840.10008.1.2.4.80") \
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
81 and (housekeeper_status["LastChangeToProcess"] == housekeeper_status["LastProcessedChange"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
82
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
83
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
84 @classmethod
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
85 def get_infos(cls):
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
86 instance_id = cls.o.lookup(
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
87 needle="1.2.840.113619.2.176.2025.1499492.7040.1171286241.704",
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
88 filter="Instance"
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
89 )[0]
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
90
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
91 instance_info = cls.o.get_json(endpoint=f"instances/{instance_id}")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
92
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
93 series_id = instance_info["ParentSeries"]
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
94 series_info = cls.o.get_json(endpoint=f"series/{series_id}")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
95
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
96 study_id = series_info["ParentStudy"]
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
97 study_info = cls.o.get_json(endpoint=f"studies/{study_id}")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
98
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
99 patient_id = study_info["ParentPatient"]
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
100 patient_info = cls.o.get_json(endpoint=f"patients/{patient_id}")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
101
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
102 instance_metadata = cls.o.get_json(endpoint=f"instances/{instance_id}/metadata?expand")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
103 return instance_info, series_info, study_info, patient_info, instance_metadata
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
104
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
105
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
106
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
107 def test_before_after_reconstruction(self):
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
108 if self.o.is_orthanc_version_at_least(1, 12, 4):
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
109 # make sure it has run once !
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
110 housekeeper_status = self.o.get_json("housekeeper/status")
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
111 self.assertIsNotNone(housekeeper_status["LastTimeStarted"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
112
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
113 instance_after, series_after, study_after, patient_after, instance_metadata_after = self.get_infos()
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
114
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
115 # extra tags were not in DB before reconstruction
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
116 self.assertNotIn("Rows", self.instance_before["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
117 self.assertNotIn("DerivationCodeSequence", self.instance_before["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
118 self.assertNotIn("ScanOptions", self.series_before["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
119 self.assertNotIn("NameOfPhysiciansReadingStudy", self.study_before["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
120 self.assertNotIn("PatientWeight", self.patient_before["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
121
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
122 # extra tags are in DB after reconstruction
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
123 self.assertIn("Rows", instance_after["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
124 self.assertIn("DerivationCodeSequence", instance_after["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
125 self.assertIn("ScanOptions", series_after["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
126 self.assertIn("NameOfPhysiciansReadingStudy", study_after["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
127 self.assertIn("PatientWeight", patient_after["MainDicomTags"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
128
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
129 # instance has been transcoded and we can still access the tags
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
130 self.assertTrue(self.instance_metadata_before["TransferSyntax"] != instance_metadata_after["TransferSyntax"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
131 self.o.instances.get_tags(instance_after["ID"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
132
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
133 # the reception date and other metadata have not been updated
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
134 self.assertEqual(self.instance_metadata_before["ReceptionDate"], instance_metadata_after["ReceptionDate"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
135 self.assertEqual(self.instance_metadata_before["Origin"], instance_metadata_after["Origin"])
810390d3968a new hk2 tests
Alain Mazy <am@orthanc.team>
parents:
diff changeset
136 self.assertNotEqual(self.instance_before["FileUuid"], instance_after["FileUuid"]) # files ID have changed