annotate NewTests/Housekeeper/test_housekeeper.py @ 474:6917a26881ed

NewTests working with Docker
author Alain Mazy <am@osimis.io>
date Mon, 02 May 2022 17:05:42 +0200
parents 4ee85b016a40
children 45c3fe035fed
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')
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
63 cls.launch_orthanc_under_tests(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
64 config_path=config_path,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
65 config_name="housekepper_under_tests",
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
66 storage_name="housekeeper",
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
67 plugins=Helpers.plugins
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
68 )
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
69
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 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
71 cls.o.wait_started()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
72
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
73 completed = False
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
74 while not completed:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
75 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
76 time.sleep(1)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
77 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
78 completed = (housekeeper_status["LastProcessedConfiguration"]["StorageCompressionEnabled"] == True) \
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
79 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
80
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
81
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
82 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
83 def get_infos(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
84 instance_id = cls.o.lookup(
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
85 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
86 filter="Instance"
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
87 )[0]
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 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
90
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
91 series_id = instance_info["ParentSeries"]
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
92 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
93
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
94 study_id = series_info["ParentStudy"]
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
95 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
96
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
97 patient_id = study_info["ParentPatient"]
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 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
99
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
100 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
101
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
102
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 def test_before_after_reconstruction(self):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
105
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 # make sure it has run once !
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 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
108 self.assertIsNotNone(housekeeper_status["LastTimeStarted"])
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 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
111
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
112 # 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
113 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
114 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
115 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
116 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
117
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
118 # 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
119 self.assertIn("Rows", instance_after["MainDicomTags"])
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
120 self.assertIn("ScanOptions", series_after["MainDicomTags"])
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
121 self.assertIn("NameOfPhysiciansReadingStudy", study_after["MainDicomTags"])
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
122 self.assertIn("PatientWeight", patient_after["MainDicomTags"])
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
123
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
124 # storage has been compressed during reconstruction
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
125 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
126 self.assertNotEqual(self.instance_before["FileUuid"], instance_after["FileUuid"]) # files ID have changed