annotate NewTests/StorageCompression/test_storage_compression.py @ 627:76c9923050b5

patch Docker env var (thx James)
author Alain Mazy <am@osimis.io>
date Wed, 21 Feb 2024 08:36:58 +0100
parents 2078cb20a560
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
489
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 import unittest
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 import time
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 from helpers import OrthancTestCase, Helpers
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
4
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
5 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
6
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 import pathlib
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
8 here = pathlib.Path(__file__).parent.resolve()
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
9
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
10
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
11 class TestStorageCompression(OrthancTestCase):
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
12
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 @classmethod
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
14 def prepare(cls):
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
15 test_name = "StorageCompression"
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 storage_name = "storage_compression"
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
17
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 print(f'-------------- preparing {test_name} tests')
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
19
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
20 cls.clear_storage(storage_name=storage_name)
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
21
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
22 config = {
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
23 "StorageCompression": True
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
24 }
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
25
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
26 config_path = cls.generate_configuration(
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
27 config_name=f"{test_name}_preparation",
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 storage_name=storage_name,
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
29 config=config,
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
30 plugins=Helpers.plugins
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 )
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
32
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
33 if Helpers.break_before_preparation:
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
34 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
35 input("Press Enter to continue")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 else:
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 cls.launch_orthanc_to_prepare_db(
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 config_name=f"{test_name}_preparation",
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
39 storage_name=storage_name,
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 config=config,
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
41 plugins=Helpers.plugins
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
42 )
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
43
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
44
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 # upload a study that will be stored with StorageCompression enabled
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
46 instances_ids = cls.o.upload_folder(here / "../../Database/Knix/Loc")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
47
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
48 # make sure we can read files that have been uploaded (this tests the StorageCache with StorageCompression=true)
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
49 dicom_file = cls.o.instances.get_file(instances_ids[0])
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
50 tags = cls.o.instances.get_tags(instances_ids[0])
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
51 if "PatientName" not in tags or tags["PatientName"] != "KNIX":
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
52 print(f"ERROR: failed to get tags from uploaded file")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
53 exit(-1)
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
54
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
55 if Helpers.break_before_preparation:
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 print(f"++++ It is now time stop your Orthanc +++++")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 input("Press Enter to continue")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 else:
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
59 cls.kill_orthanc()
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
60
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
61 # generate config for orthanc-under-tests (change StorageCompression to false)
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
62 config_path = cls.generate_configuration(
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 config_name=f"{test_name}_under_test",
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
64 storage_name=storage_name,
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
65 config={
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
66 "StorageCompression": False
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
67 },
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
68 plugins=Helpers.plugins
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
69 )
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
70
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
71 print(f'-------------- prepared {test_name} tests')
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
72 if Helpers.break_after_preparation:
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
73 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
74 input("Press Enter to continue")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
75 else:
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
76 print(f'-------------- launching {test_name} tests')
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
77 cls.launch_orthanc_under_tests(
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
78 config_path=config_path,
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
79 config_name=f"{test_name}_under_test",
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
80 storage_name=storage_name,
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
81 plugins=Helpers.plugins
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
82 )
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
83
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
84 print('-------------- waiting for orthanc-under-tests to be available')
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
85 cls.o.wait_started()
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
86
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
87 # upload a study that will be stored with StorageCompression disabled
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
88 cls.o.upload_folder(here / "../../Database/Brainix/Flair")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
89
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
90
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
91 def test_read_compressed_and_uncompressed_files(self):
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
92
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
93 # this test simply make sure we can read stored files
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
94 # it is repeated 2 times to use the cache the second time
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
95
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
96 for i in range(0, 2):
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
97 print(f"run {i}")
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 compressed_study = self.o.studies.find(query={
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
99 "PatientName": "KNIX"
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
100 })[0]
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
101 uncompressed_study = self.o.studies.find(query={
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
102 "PatientName": "BRAINIX"
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
103 })[0]
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
104
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
105 compressed_study_tags = self.o.studies.get_tags(orthanc_id = compressed_study.orthanc_id)
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 uncompressed_study_tags = self.o.studies.get_tags(orthanc_id = uncompressed_study.orthanc_id)
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
107
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
108 compressed_study_dicom_file = self.o.instances.get_file(orthanc_id = self.o.studies.get_first_instance_id(compressed_study.orthanc_id))
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
109 uncompressed_study_dicom_file = self.o.instances.get_file(orthanc_id = self.o.studies.get_first_instance_id(uncompressed_study.orthanc_id))
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
110
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
111 self.assertEqual("KNIX", compressed_study_tags["PatientName"])
2078cb20a560 new tests for StorageCompression
Alain Mazy <am@osimis.io>
parents:
diff changeset
112 self.assertEqual("BRAINIX", uncompressed_study_tags["PatientName"])