changeset 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 c5291d97ed54
children 31f70bfd86a7
files NewTests/MaxStorageReject/test_max_storage_reject.py
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NewTests/MaxStorageReject/test_max_storage_reject.py	Tue Apr 25 08:27:40 2023 +0200
+++ b/NewTests/MaxStorageReject/test_max_storage_reject.py	Mon May 22 15:01:32 2023 +0200
@@ -2,6 +2,7 @@
 import time
 import subprocess
 import pprint
+import os
 from helpers import OrthancTestCase, Helpers
 
 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file
@@ -11,6 +12,16 @@
 here = pathlib.Path(__file__).parent.resolve()
 
 
+def count_files_in_storage(path):
+    all_files = []
+    for root, dirs, files in os.walk(path):
+        for file in files:
+            if len(file) == 36:
+                all_files.append(file)
+    
+    return len(all_files)
+
+
 class TestMaxStorageReject(OrthancTestCase):
 
     @classmethod
@@ -58,6 +69,7 @@
             self.o.upload_file(here / "../../Database/Phenix/IM-0001-0001.dcm")
         self.assertEqual(507, ctx.exception.http_status_code)
         self.assertEqual(2, len(self.o.studies.get_all_ids()))
+        self.assertEqual(2, count_files_in_storage(self.get_storage_path("max_storage_reject")))
 
     def upload_with_store_scu(self, path):
         subprocess.check_call([Helpers.find_executable('storescu'),
@@ -76,6 +88,7 @@
         with self.assertRaises(subprocess.CalledProcessError) as ctx:
             self.upload_with_store_scu(here / "../../Database/Phenix/IM-0001-0001.dcm")
         self.assertEqual(2, len(self.o.studies.get_all_ids()))
+        self.assertEqual(2, count_files_in_storage(self.get_storage_path("max_storage_reject")))
 
     def test_upload_3_patients_dicomweb(self):
 
@@ -90,6 +103,7 @@
         self.assertEqual(400, ctx.exception.http_status_code)
 
         self.assertEqual(2, len(self.o.studies.get_all_ids()))
+        self.assertEqual(2, count_files_in_storage(self.get_storage_path("max_storage_reject")))
 
     def test_upload_3_patients_dicomweb_in_one_query(self):
 
@@ -105,4 +119,5 @@
         # pprint.pprint(r)
         self.assertEqual(2, len(self.o.studies.get_all_ids()))
         self.assertIn('00081198', r)
-        self.assertEqual(0xA700, r['00081198']['Value'][0]['00081197']['Value'][0])  # one failed instance with out-of-resource status
\ No newline at end of file
+        self.assertEqual(0xA700, r['00081198']['Value'][0]['00081197']['Value'][0])  # one failed instance with out-of-resource status
+        self.assertEqual(2, count_files_in_storage(self.get_storage_path("max_storage_reject")))