# HG changeset patch # User Alain Mazy # Date 1659948947 -7200 # Node ID 2078cb20a560dbb077119a63558cf4ff2e3ee0c8 # Parent e904b2282b0ebd78033e33f7b773e6c1e547915e new tests for StorageCompression diff -r e904b2282b0e -r 2078cb20a560 NewTests/README --- a/NewTests/README Fri Jul 08 15:27:27 2022 +0200 +++ b/NewTests/README Mon Aug 08 10:55:47 2022 +0200 @@ -33,6 +33,7 @@ --orthanc_under_tests_http_port=8043 \ --plugin=/home/alain/o/build/orthanc/libHousekeeper.so \ --plugin=/home/alain/o/build/orthanc/libDelayedDeletion.so \ + --plugin=/home/alain/o/build/orthanc-dicomweb/libOrthancDicomWeb.so \ --plugin=/home/alain/o/build/orthanc-gdcm/libOrthancGdcm.so @@ -63,10 +64,6 @@ - execute tests - -TODO: implement and document usage with Docker !!!! - - ExtraMainDicomTags: ------------------ @@ -86,3 +83,21 @@ - execute tests +StorageCompression: +------------------ + +Run the StorageCompression tests with your locally build version and break before and after preparation +and execution to allow you to start your debugger. + +python3 NewTests/main.py --pattern=StorageCompression.test_storage_compression.TestStorageCompression.* \ + --orthanc_under_tests_exe=/home/alain/o/build/orthanc/Orthanc \ + --orthanc_under_tests_http_port=8043 \ + --break_after_preparation \ + --break_before_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, +- drive this Orthanc to prepare the DB +- interrupt and instruct you how to start your own version, pointing to the configuration file to use +- execute tests diff -r e904b2282b0e -r 2078cb20a560 NewTests/StorageCompression/__init__.py diff -r e904b2282b0e -r 2078cb20a560 NewTests/StorageCompression/test_storage_compression.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NewTests/StorageCompression/test_storage_compression.py Mon Aug 08 10:55:47 2022 +0200 @@ -0,0 +1,112 @@ +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 TestStorageCompression(OrthancTestCase): + + @classmethod + def prepare(cls): + test_name = "StorageCompression" + storage_name = "storage_compression" + + print(f'-------------- preparing {test_name} tests') + + cls.clear_storage(storage_name=storage_name) + + config = { + "StorageCompression": True + } + + config_path = cls.generate_configuration( + config_name=f"{test_name}_preparation", + storage_name=storage_name, + config=config, + plugins=Helpers.plugins + ) + + if Helpers.break_before_preparation: + print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++") + input("Press Enter to continue") + else: + cls.launch_orthanc_to_prepare_db( + config_name=f"{test_name}_preparation", + storage_name=storage_name, + config=config, + plugins=Helpers.plugins + ) + + + # upload a study that will be stored with StorageCompression enabled + instances_ids = cls.o.upload_folder(here / "../../Database/Knix/Loc") + + # make sure we can read files that have been uploaded (this tests the StorageCache with StorageCompression=true) + dicom_file = cls.o.instances.get_file(instances_ids[0]) + tags = cls.o.instances.get_tags(instances_ids[0]) + if "PatientName" not in tags or tags["PatientName"] != "KNIX": + print(f"ERROR: failed to get tags from uploaded file") + exit(-1) + + if Helpers.break_before_preparation: + print(f"++++ It is now time stop your Orthanc +++++") + input("Press Enter to continue") + else: + cls.kill_orthanc() + + # generate config for orthanc-under-tests (change StorageCompression to false) + config_path = cls.generate_configuration( + config_name=f"{test_name}_under_test", + storage_name=storage_name, + config={ + "StorageCompression": False + }, + plugins=Helpers.plugins + ) + + print(f'-------------- prepared {test_name} 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(f'-------------- launching {test_name} tests') + cls.launch_orthanc_under_tests( + config_path=config_path, + config_name=f"{test_name}_under_test", + storage_name=storage_name, + plugins=Helpers.plugins + ) + + print('-------------- waiting for orthanc-under-tests to be available') + cls.o.wait_started() + + # upload a study that will be stored with StorageCompression disabled + cls.o.upload_folder(here / "../../Database/Brainix/Flair") + + + def test_read_compressed_and_uncompressed_files(self): + + # this test simply make sure we can read stored files + # it is repeated 2 times to use the cache the second time + + for i in range(0, 2): + print(f"run {i}") + compressed_study = self.o.studies.find(query={ + "PatientName": "KNIX" + })[0] + uncompressed_study = self.o.studies.find(query={ + "PatientName": "BRAINIX" + })[0] + + compressed_study_tags = self.o.studies.get_tags(orthanc_id = compressed_study.orthanc_id) + uncompressed_study_tags = self.o.studies.get_tags(orthanc_id = uncompressed_study.orthanc_id) + + compressed_study_dicom_file = self.o.instances.get_file(orthanc_id = self.o.studies.get_first_instance_id(compressed_study.orthanc_id)) + uncompressed_study_dicom_file = self.o.instances.get_file(orthanc_id = self.o.studies.get_first_instance_id(uncompressed_study.orthanc_id)) + + self.assertEqual("KNIX", compressed_study_tags["PatientName"]) + self.assertEqual("BRAINIX", uncompressed_study_tags["PatientName"])