Mercurial > hg > orthanc-tests
comparison NewTests/MaxStorageReject/test_max_storage_reject.py @ 490:10a47656e34f
new tests for MaximumStorageMode
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 09 Aug 2022 17:57:57 +0200 |
parents | |
children | d9d059c6082d |
comparison
equal
deleted
inserted
replaced
489:2078cb20a560 | 490:10a47656e34f |
---|---|
1 import unittest | |
2 import time | |
3 import subprocess | |
4 import pprint | |
5 from helpers import OrthancTestCase, Helpers | |
6 | |
7 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file | |
8 from orthanc_api_client import exceptions as orthanc_exceptions | |
9 | |
10 import pathlib | |
11 here = pathlib.Path(__file__).parent.resolve() | |
12 | |
13 | |
14 class TestMaxStorageReject(OrthancTestCase): | |
15 | |
16 @classmethod | |
17 def prepare(cls): | |
18 test_name = "MaxStorageReject" | |
19 storage_name = "max_storage_reject" | |
20 | |
21 cls.clear_storage(storage_name=storage_name) | |
22 | |
23 config_path = cls.generate_configuration( | |
24 config_name=f"{test_name}_under_test", | |
25 storage_name=storage_name, | |
26 config={ | |
27 "MaximumPatientCount": 2, | |
28 "MaximumStorageMode": "Reject" | |
29 }, | |
30 plugins=Helpers.plugins | |
31 ) | |
32 | |
33 print(f'-------------- prepared {test_name} tests') | |
34 if Helpers.break_after_preparation: | |
35 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++") | |
36 input("Press Enter to continue") | |
37 else: | |
38 print(f'-------------- launching {test_name} tests') | |
39 cls.launch_orthanc_under_tests( | |
40 config_path=config_path, | |
41 config_name=f"{test_name}_under_test", | |
42 storage_name=storage_name, | |
43 plugins=Helpers.plugins | |
44 ) | |
45 | |
46 print('-------------- waiting for orthanc-under-tests to be available') | |
47 cls.o.wait_started() | |
48 | |
49 | |
50 def test_upload_3_patients_rest_api(self): | |
51 | |
52 self.o.delete_all_content() | |
53 | |
54 # make sure the 3rd patient does not make it into the storage (through the Rest API) | |
55 self.o.upload_file(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") | |
56 self.o.upload_file(here / "../../Database/Knix/Loc/IM-0001-0001.dcm") | |
57 with self.assertRaises(orthanc_exceptions.HttpError) as ctx: | |
58 self.o.upload_file(here / "../../Database/Phenix/IM-0001-0001.dcm") | |
59 self.assertEqual(507, ctx.exception.http_status_code) | |
60 self.assertEqual(2, len(self.o.studies.get_all_ids())) | |
61 | |
62 def upload_with_store_scu(self, path): | |
63 subprocess.check_call([Helpers.find_executable('storescu'), | |
64 "-xs", | |
65 Helpers.get_orthanc_ip(), | |
66 str(Helpers.get_orthanc_dicom_port()), | |
67 path]) | |
68 | |
69 def test_upload_3_patients_c_store(self): | |
70 | |
71 self.o.delete_all_content() | |
72 | |
73 # make sure the 3rd patient does not make it into the storage (through StoreSCU) | |
74 self.upload_with_store_scu(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") | |
75 self.upload_with_store_scu(here / "../../Database/Knix/Loc/IM-0001-0001.dcm") | |
76 with self.assertRaises(subprocess.CalledProcessError) as ctx: | |
77 self.upload_with_store_scu(here / "../../Database/Phenix/IM-0001-0001.dcm") | |
78 self.assertEqual(2, len(self.o.studies.get_all_ids())) | |
79 | |
80 def test_upload_3_patients_dicomweb(self): | |
81 | |
82 self.o.delete_all_content() | |
83 | |
84 # make sure the 3rd patient does not make it into the storage (through DicomWeb) | |
85 self.o.upload_files_dicom_web([here / "../../Database/Brainix/Flair/IM-0001-0001.dcm"]) | |
86 self.o.upload_files_dicom_web([here / "../../Database/Knix/Loc/IM-0001-0001.dcm"]) | |
87 | |
88 with self.assertRaises(orthanc_exceptions.HttpError) as ctx: | |
89 self.o.upload_files_dicom_web([here / "../../Database/Phenix/IM-0001-0001.dcm"]) | |
90 self.assertEqual(400, ctx.exception.http_status_code) | |
91 | |
92 self.assertEqual(2, len(self.o.studies.get_all_ids())) | |
93 | |
94 def test_upload_3_patients_dicomweb_in_one_query(self): | |
95 | |
96 self.o.delete_all_content() | |
97 | |
98 # make sure the 3rd patient does not make it into the storage (through DicomWeb) | |
99 r = self.o.upload_files_dicom_web([ | |
100 here / "../../Database/Brainix/Flair/IM-0001-0001.dcm", | |
101 here / "../../Database/Knix/Loc/IM-0001-0001.dcm", | |
102 here / "../../Database/Phenix/IM-0001-0001.dcm" | |
103 ]) | |
104 | |
105 # pprint.pprint(r) | |
106 self.assertEqual(2, len(self.o.studies.get_all_ids())) | |
107 self.assertIn('00081198', r) | |
108 self.assertEqual(0xA700, r['00081198']['Value'][0]['00081197']['Value'][0]) # one failed instance with out-of-resource status |