comparison NewTests/MaxStorageReject/test_max_storage_reject.py @ 534:d9d059c6082d

Fix orphan files remaining in storage when working with MaximumStorageSize
author Alain Mazy <am@osimis.io>
date Mon, 22 May 2023 15:01:32 +0200
parents 10a47656e34f
children 47c43fdaf91d
comparison
equal deleted inserted replaced
533:c5291d97ed54 534:d9d059c6082d
1 import unittest 1 import unittest
2 import time 2 import time
3 import subprocess 3 import subprocess
4 import pprint 4 import pprint
5 import os
5 from helpers import OrthancTestCase, Helpers 6 from helpers import OrthancTestCase, Helpers
6 7
7 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file 8 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file
8 from orthanc_api_client import exceptions as orthanc_exceptions 9 from orthanc_api_client import exceptions as orthanc_exceptions
9 10
10 import pathlib 11 import pathlib
11 here = pathlib.Path(__file__).parent.resolve() 12 here = pathlib.Path(__file__).parent.resolve()
13
14
15 def count_files_in_storage(path):
16 all_files = []
17 for root, dirs, files in os.walk(path):
18 for file in files:
19 if len(file) == 36:
20 all_files.append(file)
21
22 return len(all_files)
12 23
13 24
14 class TestMaxStorageReject(OrthancTestCase): 25 class TestMaxStorageReject(OrthancTestCase):
15 26
16 @classmethod 27 @classmethod
56 self.o.upload_file(here / "../../Database/Knix/Loc/IM-0001-0001.dcm") 67 self.o.upload_file(here / "../../Database/Knix/Loc/IM-0001-0001.dcm")
57 with self.assertRaises(orthanc_exceptions.HttpError) as ctx: 68 with self.assertRaises(orthanc_exceptions.HttpError) as ctx:
58 self.o.upload_file(here / "../../Database/Phenix/IM-0001-0001.dcm") 69 self.o.upload_file(here / "../../Database/Phenix/IM-0001-0001.dcm")
59 self.assertEqual(507, ctx.exception.http_status_code) 70 self.assertEqual(507, ctx.exception.http_status_code)
60 self.assertEqual(2, len(self.o.studies.get_all_ids())) 71 self.assertEqual(2, len(self.o.studies.get_all_ids()))
72 self.assertEqual(2, count_files_in_storage(self.get_storage_path("max_storage_reject")))
61 73
62 def upload_with_store_scu(self, path): 74 def upload_with_store_scu(self, path):
63 subprocess.check_call([Helpers.find_executable('storescu'), 75 subprocess.check_call([Helpers.find_executable('storescu'),
64 "-xs", 76 "-xs",
65 Helpers.get_orthanc_ip(), 77 Helpers.get_orthanc_ip(),
74 self.upload_with_store_scu(here / "../../Database/Brainix/Flair/IM-0001-0001.dcm") 86 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") 87 self.upload_with_store_scu(here / "../../Database/Knix/Loc/IM-0001-0001.dcm")
76 with self.assertRaises(subprocess.CalledProcessError) as ctx: 88 with self.assertRaises(subprocess.CalledProcessError) as ctx:
77 self.upload_with_store_scu(here / "../../Database/Phenix/IM-0001-0001.dcm") 89 self.upload_with_store_scu(here / "../../Database/Phenix/IM-0001-0001.dcm")
78 self.assertEqual(2, len(self.o.studies.get_all_ids())) 90 self.assertEqual(2, len(self.o.studies.get_all_ids()))
91 self.assertEqual(2, count_files_in_storage(self.get_storage_path("max_storage_reject")))
79 92
80 def test_upload_3_patients_dicomweb(self): 93 def test_upload_3_patients_dicomweb(self):
81 94
82 self.o.delete_all_content() 95 self.o.delete_all_content()
83 96
88 with self.assertRaises(orthanc_exceptions.HttpError) as ctx: 101 with self.assertRaises(orthanc_exceptions.HttpError) as ctx:
89 self.o.upload_files_dicom_web([here / "../../Database/Phenix/IM-0001-0001.dcm"]) 102 self.o.upload_files_dicom_web([here / "../../Database/Phenix/IM-0001-0001.dcm"])
90 self.assertEqual(400, ctx.exception.http_status_code) 103 self.assertEqual(400, ctx.exception.http_status_code)
91 104
92 self.assertEqual(2, len(self.o.studies.get_all_ids())) 105 self.assertEqual(2, len(self.o.studies.get_all_ids()))
106 self.assertEqual(2, count_files_in_storage(self.get_storage_path("max_storage_reject")))
93 107
94 def test_upload_3_patients_dicomweb_in_one_query(self): 108 def test_upload_3_patients_dicomweb_in_one_query(self):
95 109
96 self.o.delete_all_content() 110 self.o.delete_all_content()
97 111
104 118
105 # pprint.pprint(r) 119 # pprint.pprint(r)
106 self.assertEqual(2, len(self.o.studies.get_all_ids())) 120 self.assertEqual(2, len(self.o.studies.get_all_ids()))
107 self.assertIn('00081198', r) 121 self.assertIn('00081198', r)
108 self.assertEqual(0xA700, r['00081198']['Value'][0]['00081197']['Value'][0]) # one failed instance with out-of-resource status 122 self.assertEqual(0xA700, r['00081198']['Value'][0]['00081197']['Value'][0]) # one failed instance with out-of-resource status
123 self.assertEqual(2, count_files_in_storage(self.get_storage_path("max_storage_reject")))