comparison NewTests/Housekeeper/test_housekeeper.py @ 473:4ee85b016a40

added NewTests framework - only the Housekeeper tests right now
author Alain Mazy <am@osimis.io>
date Sat, 30 Apr 2022 19:38:34 +0200
parents
children 6917a26881ed
comparison
equal deleted inserted replaced
472:d9ceb0fd5995 473:4ee85b016a40
1 import unittest
2 import time
3 from helpers import OrthancTestCase, Helpers
4
5 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file
6
7 import pathlib
8 here = pathlib.Path(__file__).parent.resolve()
9
10
11 class TestHousekeeper(OrthancTestCase):
12
13 @classmethod
14 def prepare(cls):
15 print('-------------- preparing TestHousekeeper tests')
16
17 cls.clear_storage(storage_name="housekeeper")
18
19 cls.launch_orthanc_to_prepare_db(
20 config_name="housekeeper_preparation",
21 storage_name="housekeeper",
22 config={
23 "StorageCompression": False,
24 "Housekeeper": {
25 "Enable": False
26 }
27 },
28 plugins=Helpers.plugins
29 )
30
31 # upload a study and keep track of data before housekeeper runs
32 cls.o.upload_folder(here / "../../Database/Knix/Loc")
33
34 cls.instance_before, cls.series_before, cls.study_before, cls.patient_before = cls.get_infos()
35
36 cls.kill_orthanc()
37
38 # generate config for orthanc-under-tests (change StorageCompression and add ExtraMainDicomTags)
39 config_path = cls.generate_configuration(
40 config_name="housekeeper_under_test",
41 storage_name="housekeeper",
42 config={
43 "StorageCompression": True,
44 "ExtraMainDicomTags": {
45 "Patient" : ["PatientWeight", "PatientAge"],
46 "Study": ["NameOfPhysiciansReadingStudy"],
47 "Series": ["ScanOptions"],
48 "Instance": ["Rows", "Columns"]
49 },
50 "Housekeeper": {
51 "Enable": True
52 }
53 },
54 plugins=Helpers.plugins
55 )
56
57 print('-------------- prepared TestHousekeeper tests')
58 if Helpers.break_after_preparation:
59 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++")
60 input("Press Enter to continue")
61 else:
62 print('-------------- launching TestHousekeeper tests')
63 cls.launch_orthanc(
64 exe_path=Helpers.orthanc_under_tests_exe,
65 config_path=config_path
66 )
67
68 print('-------------- waiting for orthanc-under-tests to be available')
69 cls.o.wait_started()
70
71 completed = False
72 while not completed:
73 print('-------------- waiting for housekeeper to finish processing')
74 time.sleep(1)
75 housekeeper_status = cls.o.get_json("/housekeeper/status")
76 completed = (housekeeper_status["LastProcessedConfiguration"]["StorageCompressionEnabled"] == True) \
77 and (housekeeper_status["LastChangeToProcess"] == housekeeper_status["LastProcessedChange"])
78
79
80 @classmethod
81 def get_infos(cls):
82 instance_id = cls.o.lookup(
83 needle="1.2.840.113619.2.176.2025.1499492.7040.1171286241.704",
84 filter="Instance"
85 )[0]
86
87 instance_info = cls.o.get_json(relative_url=f"/instances/{instance_id}")
88
89 series_id = instance_info["ParentSeries"]
90 series_info = cls.o.get_json(relative_url=f"/series/{series_id}")
91
92 study_id = series_info["ParentStudy"]
93 study_info = cls.o.get_json(relative_url=f"/studies/{study_id}")
94
95 patient_id = study_info["ParentPatient"]
96 patient_info = cls.o.get_json(relative_url=f"/patients/{patient_id}")
97
98 return instance_info, series_info, study_info, patient_info
99
100
101
102 def test_before_after_reconstruction(self):
103
104 # make sure it has run once !
105 housekeeper_status = self.o.get_json("/housekeeper/status")
106 self.assertIsNotNone(housekeeper_status["LastTimeStarted"])
107
108 instance_after, series_after, study_after, patient_after = self.get_infos()
109
110 # extra tags were not in DB before reconstruction
111 self.assertNotIn("Rows", self.instance_before["MainDicomTags"])
112 self.assertNotIn("ScanOptions", self.series_before["MainDicomTags"])
113 self.assertNotIn("NameOfPhysiciansReadingStudy", self.study_before["MainDicomTags"])
114 self.assertNotIn("PatientWeight", self.patient_before["MainDicomTags"])
115
116 # extra tags are in DB after reconstruction
117 self.assertIn("Rows", instance_after["MainDicomTags"])
118 self.assertIn("ScanOptions", series_after["MainDicomTags"])
119 self.assertIn("NameOfPhysiciansReadingStudy", study_after["MainDicomTags"])
120 self.assertIn("PatientWeight", patient_after["MainDicomTags"])
121
122 # storage has been compressed during reconstruction
123 self.assertTrue(self.instance_before["FileSize"] > instance_after["FileSize"])
124 self.assertNotEqual(self.instance_before["FileUuid"], instance_after["FileUuid"]) # files ID have changed