# HG changeset patch # User Alain Mazy # Date 1716304227 -7200 # Node ID 810390d3968a4de8e5383d696a6ff64cd3753fdc # Parent a25e7a641f26eb0895738fa7bbd56644b062533e new hk2 tests diff -r a25e7a641f26 -r 810390d3968a NewTests/Authorization/test_authorization.py --- a/NewTests/Authorization/test_authorization.py Thu Apr 25 15:31:03 2024 +0200 +++ b/NewTests/Authorization/test_authorization.py Tue May 21 17:10:27 2024 +0200 @@ -262,6 +262,12 @@ o.get_json(f"/plugins") o.get_json(f"/plugins/dicom-web") + if o_admin.is_plugin_version_at_least("authorization", 0, 7, 2): + # also check that this works with the admin user ! + i = o_admin.get_json(f"dicom-web/studies/{self.label_a_study_dicom_id}/instances") + i = o_admin.get_binary(f"dicom-web/studies/{self.label_a_study_dicom_id}/series/{self.label_a_series_dicom_id}/instances/{self.label_a_instance_dicom_id}") + i = o_admin.get_json(f"dicom-web/studies/{self.label_a_study_dicom_id}/series?includefield=00080021%2C00080031%2C0008103E%2C00200011") + def test_resource_token(self): diff -r a25e7a641f26 -r 810390d3968a NewTests/Housekeeper/test_housekeeper2.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NewTests/Housekeeper/test_housekeeper2.py Tue May 21 17:10:27 2024 +0200 @@ -0,0 +1,136 @@ +import unittest +import time +from helpers import OrthancTestCase, Helpers + +from orthanc_api_client import OrthancApiClient, generate_test_dicom_file + +import pathlib +here = pathlib.Path(__file__).parent.resolve() + + +class TestHousekeeper2(OrthancTestCase): + + @classmethod + def prepare(cls): + print('-------------- preparing TestHousekeeper2 tests') + + cls.clear_storage(storage_name="housekeeper2") + + cls.launch_orthanc_to_prepare_db( + config_name="housekeeper2_preparation", + storage_name="housekeeper2", + config={ + "Housekeeper": { + "Enable": False + } + }, + plugins=Helpers.plugins + ) + + # upload a study and keep track of data before housekeeper runs + cls.o.upload_folder(here / "../../Database/Knix/Loc") + + cls.instance_before, cls.series_before, cls.study_before, cls.patient_before, cls.instance_metadata_before = cls.get_infos() + + cls.kill_orthanc() + time.sleep(3) + + # generate config for orthanc-under-tests (change StorageCompression and add ExtraMainDicomTags) + config_path = cls.generate_configuration( + config_name="housekeeper2_under_test", + storage_name="housekeeper2", + config={ + "IngestTranscoding": "1.2.840.10008.1.2.4.80", + "ExtraMainDicomTags": { + "Patient" : ["PatientWeight", "PatientAge"], + "Study": ["NameOfPhysiciansReadingStudy"], + "Series": ["ScanOptions"], + "Instance": ["Rows", "Columns", "DerivationCodeSequence"] + }, + "Housekeeper": { + "Enable": True + }, + "KeepAliveTimeout": 2 + }, + plugins=Helpers.plugins + ) + + print('-------------- prepared TestHousekeeper2 tests') + if Helpers.break_after_preparation: + print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++") + input("Press Enter to continue") + else: + print('-------------- launching TestHousekeeper2 tests') + cls.launch_orthanc_under_tests( + config_path=config_path, + config_name="housekeeper2_under_test", + storage_name="housekeeper2", + plugins=Helpers.plugins, + enable_verbose=False + ) + + print('-------------- waiting for orthanc-under-tests to be available') + cls.o.wait_started() + + completed = False + while not completed: + print('-------------- waiting for housekeeper2 to finish processing') + time.sleep(1) + housekeeper_status = cls.o.get_json("plugins/housekeeper/status") + completed = (housekeeper_status["LastProcessedConfiguration"]["IngestTranscoding"] == "1.2.840.10008.1.2.4.80") \ + and (housekeeper_status["LastChangeToProcess"] == housekeeper_status["LastProcessedChange"]) + + + @classmethod + def get_infos(cls): + instance_id = cls.o.lookup( + needle="1.2.840.113619.2.176.2025.1499492.7040.1171286241.704", + filter="Instance" + )[0] + + instance_info = cls.o.get_json(endpoint=f"instances/{instance_id}") + + series_id = instance_info["ParentSeries"] + series_info = cls.o.get_json(endpoint=f"series/{series_id}") + + study_id = series_info["ParentStudy"] + study_info = cls.o.get_json(endpoint=f"studies/{study_id}") + + patient_id = study_info["ParentPatient"] + patient_info = cls.o.get_json(endpoint=f"patients/{patient_id}") + + instance_metadata = cls.o.get_json(endpoint=f"instances/{instance_id}/metadata?expand") + return instance_info, series_info, study_info, patient_info, instance_metadata + + + + def test_before_after_reconstruction(self): + if self.o.is_orthanc_version_at_least(1, 12, 4): + # make sure it has run once ! + housekeeper_status = self.o.get_json("housekeeper/status") + self.assertIsNotNone(housekeeper_status["LastTimeStarted"]) + + instance_after, series_after, study_after, patient_after, instance_metadata_after = self.get_infos() + + # extra tags were not in DB before reconstruction + self.assertNotIn("Rows", self.instance_before["MainDicomTags"]) + self.assertNotIn("DerivationCodeSequence", self.instance_before["MainDicomTags"]) + self.assertNotIn("ScanOptions", self.series_before["MainDicomTags"]) + self.assertNotIn("NameOfPhysiciansReadingStudy", self.study_before["MainDicomTags"]) + self.assertNotIn("PatientWeight", self.patient_before["MainDicomTags"]) + + # extra tags are in DB after reconstruction + self.assertIn("Rows", instance_after["MainDicomTags"]) + self.assertIn("DerivationCodeSequence", instance_after["MainDicomTags"]) + self.assertIn("ScanOptions", series_after["MainDicomTags"]) + self.assertIn("NameOfPhysiciansReadingStudy", study_after["MainDicomTags"]) + self.assertIn("PatientWeight", patient_after["MainDicomTags"]) + + # instance has been transcoded and we can still access the tags + self.assertTrue(self.instance_metadata_before["TransferSyntax"] != instance_metadata_after["TransferSyntax"]) + self.o.instances.get_tags(instance_after["ID"]) + + # the reception date and other metadata have not been updated + self.assertEqual(self.instance_metadata_before["ReceptionDate"], instance_metadata_after["ReceptionDate"]) + self.assertEqual(self.instance_metadata_before["Origin"], instance_metadata_after["Origin"]) + self.assertNotEqual(self.instance_before["FileUuid"], instance_after["FileUuid"]) # files ID have changed diff -r a25e7a641f26 -r 810390d3968a NewTests/README --- a/NewTests/README Thu Apr 25 15:31:03 2024 +0200 +++ b/NewTests/README Tue May 21 17:10:27 2024 +0200 @@ -56,6 +56,12 @@ --plugin=/home/alain/o/build/orthanc/libHousekeeper.so \ --break_after_preparation +python3 NewTests/main.py --pattern=Housekeeper.test_housekeeper2.TestHousekeeper2.test_before_after_reconstruction \ + --orthanc_under_tests_exe=/home/alain/o/build/orthanc/Orthanc \ + --orthanc_under_tests_http_port=8043 \ + --plugin=/home/alain/o/build/orthanc/libHousekeeper.so \ + --break_after_preparation + The test script will: - generate 2 configuration file in the `configurations` folder, - start your local Orthanc version to prepare the db with one of the configuration file,