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