annotate NewTests/DelayedDeletion/test_delayed_deletion.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 6144ef431512
children ed0a51317c0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
483
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 import unittest
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 import time
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 import os
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
4 from helpers import OrthancTestCase, Helpers
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
5
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
6 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 from orthanc_tools import OrthancTestDbPopulator
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
8
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
9 import pathlib
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
10 import glob
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
11 here = pathlib.Path(__file__).parent.resolve()
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
12
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
13
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
14 class TestDelayedDeletion(OrthancTestCase):
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
15
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 @classmethod
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 def prepare(cls):
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 print('-------------- preparing TestDelayedDeletion tests')
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
19
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
20 cls.clear_storage(storage_name="DelayedDeletion")
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
21
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
22 config = {
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
23 "DelayedDeletion": {
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
24 "Enable": True,
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
25 "ThrottleDelayMs": 200
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
26 }
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
27 }
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
28
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
29 config_path = cls.generate_configuration(
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
30 config_name="delayed_deletion",
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 storage_name="DelayedDeletion",
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
32 config=config,
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
33 plugins=Helpers.plugins
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
34 )
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
35
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 if Helpers.break_before_preparation:
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++")
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 input("Press Enter to continue")
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
39 else:
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 print('-------------- launching DelayedDeletion preparation')
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
41
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
42 cls.launch_orthanc_to_prepare_db(
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
43 config_name="delayed_deletion",
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
44 config_path=config_path,
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 storage_name="DelayedDeletion",
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
46 config=config,
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
47 plugins=Helpers.plugins
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
48 )
486
6144ef431512 new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
49
6144ef431512 new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
50 print('-------------- waiting for orthanc-to-prepare-db to be available')
6144ef431512 new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
51 cls.o.wait_started()
483
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
52
486
6144ef431512 new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
53 print('-------------- populating')
6144ef431512 new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
54 cls.o.upload_folder(here / "../../Database/Knix/Loc")
6144ef431512 new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
55 print('-------------- populated')
483
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 cls.files_count_after_preparation = len(glob.glob(os.path.join(cls.get_storage_path("DelayedDeletion"), "**"), recursive=True))
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
57
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 all_studies_ids = cls.o.studies.get_all_ids()
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
59 # delete all studies and exit Orthanc one seconds later
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
60 cls.o.studies.delete(orthanc_ids = all_studies_ids)
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
61 time.sleep(1)
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
62
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 if Helpers.break_before_preparation:
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
64 print(f"++++ It is now time stop your Orthanc +++++")
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
65 input("Press Enter to continue")
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
66 else:
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
67 cls.kill_orthanc()
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
68
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
69 cls.files_count_after_stop = len(glob.glob(os.path.join(cls.get_storage_path("DelayedDeletion"), "**"), recursive=True))
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
70
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
71 # speed up deletion for the second part of the tests
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
72 config["DelayedDeletion"]["ThrottleDelayMs"] = 0
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
73
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
74 config_path = cls.generate_configuration(
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
75 config_name="delayed_deletion",
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
76 storage_name="DelayedDeletion",
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
77 config=config,
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
78 plugins=Helpers.plugins
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
79 )
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
80
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
81 print('-------------- prepared DelayedDeletion tests')
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
82 if Helpers.break_after_preparation:
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
83 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++")
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
84 input("Press Enter to continue")
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
85 else:
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
86 print('-------------- launching DelayedDeletion tests')
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
87 cls.launch_orthanc_under_tests(
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
88 config_path=config_path,
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
89 config_name="delayed_deletion",
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
90 storage_name="DelayedDeletion",
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
91 plugins=Helpers.plugins
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
92 )
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
93
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
94 print('-------------- waiting for orthanc-under-tests to be available')
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
95 cls.o.wait_started()
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
96
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
97
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
98
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
99 def test_resumes_pending_deletion(self):
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
100
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
101 completed = False
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
102 while not completed:
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
103 print('-------------- waiting for DelayedDeletion to finish processing')
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
104 time.sleep(1)
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
105 plugin_status = self.o.get_json("/plugins/delayed-deletion/status")
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 completed = plugin_status["FilesPendingDeletion"] == 0
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents:
diff changeset
107
484
ddfabe1fbee1 new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents: 483
diff changeset
108 self.assertTrue(completed)
ddfabe1fbee1 new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents: 483
diff changeset
109 files_count_after_delayed_deletion_is_complete = len(glob.glob(os.path.join(self.get_storage_path("DelayedDeletion"), "**"), recursive=True))
ddfabe1fbee1 new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents: 483
diff changeset
110 self.assertGreater(10, files_count_after_delayed_deletion_is_complete) # only the sqlite files shall remain (and . and ..)
ddfabe1fbee1 new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents: 483
diff changeset
111