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