annotate NewTests/helpers.py @ 593:f4f0e2d24a51

more pg-transactions tests
author Alain Mazy <am@osimis.io>
date Thu, 14 Dec 2023 10:41:09 +0100
parents 6753d96dd71f
children 3e15e950c462
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 import unittest
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 from orthanc_api_client import OrthancApiClient
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 import subprocess
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
4 import json
490
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
5 import os
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
6 import typing
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 import shutil
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
8 import glob
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
9 from threading import Thread
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
10
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
11
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
12 import pathlib
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 here = pathlib.Path(__file__).parent.resolve()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
14
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
15
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 default_base_config = {
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 "AuthenticationEnabled": False,
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 "RemoteAccessAllowed": True
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
19 }
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
20
490
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
21
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
22 class Helpers:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
23
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
24 orthanc_under_tests_hostname: str = 'localhost'
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
25 orthanc_under_tests_http_port: int = 8052
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
26 orthanc_under_tests_dicom_port: int = 4252
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
27 orthanc_under_tests_exe: str = None
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 orthanc_previous_version_exe: str = None
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
29 orthanc_under_tests_docker_image: str = None
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
30 skip_preparation: bool = False
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 break_after_preparation: bool = False
483
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents: 475
diff changeset
32 break_before_preparation: bool = False
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
33 plugins: typing.List[str] = []
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
34
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
35 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 def get_orthanc_url(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 return f"http://{cls.orthanc_under_tests_hostname}:{cls.orthanc_under_tests_http_port}"
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
38
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
39 @classmethod
490
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
40 def get_orthanc_ip(cls):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
41 return cls.orthanc_under_tests_hostname
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
42
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
43 @classmethod
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
44 def get_orthanc_dicom_port(cls):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
45 return cls.orthanc_under_tests_dicom_port
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
46
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
47 @classmethod
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
48 def is_docker(cls):
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
49 return cls.orthanc_under_tests_exe is None and cls.orthanc_under_tests_docker_image is not None
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
50
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
51 @classmethod
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
52 def is_exe(cls):
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
53 return cls.orthanc_under_tests_exe is not None and cls.orthanc_under_tests_docker_image is None
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
54
490
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
55 @classmethod
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
56 def find_executable(cls, name):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
57 p = os.path.join('/usr/local/bin', name)
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
58 if os.path.isfile(p):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
59 return p
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
60
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
61 p = os.path.join('/usr/local/sbin', name)
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
62 if os.path.isfile(p):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
63 return p
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
64
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
65 return name
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
66
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
67
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
68 class OrthancTestCase(unittest.TestCase):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
69
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 o: OrthancApiClient = None # the orthanc under tests api client
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
71 _orthanc_process = None
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
72 _orthanc_container_name = None
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
73 _orthanc_is_running = False
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
74 _orthanc_logger_thread = None
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
75 _show_orthanc_output = False
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
76
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
77 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
78 def setUpClass(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
79
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
80 cls.o = OrthancApiClient(Helpers.get_orthanc_url())
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
81 cls._prepare()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
82
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
83 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
84 def tearDownClass(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
85 if not Helpers.break_after_preparation:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
86 cls.kill_orthanc()
577
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
87 cls.terminate()
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
88
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
89 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
90 def prepare(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
91 pass # to override
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
92
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
93 @classmethod
576
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
94 def terminate(cls):
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
95 pass # to override
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
96
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
97 @classmethod
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 def _prepare(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
99 if not Helpers.skip_preparation:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
100 cls.prepare()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
101
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
102 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
103 def get_storage_path(cls, storage_name: str):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
104 return str(here / "storages" / f"{storage_name}")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
105
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 def generate_configuration(cls, config_name: str, config: object, storage_name: str, plugins = []):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
108
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
109 # add plugins and default storge directory
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
110 if plugins and len(plugins) > 0:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
111 config["Plugins"] = plugins
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
112
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
113 if Helpers.is_exe() and not "StorageDirectory" in config:
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
114 config["StorageDirectory"] = cls.get_storage_path(storage_name=storage_name)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
115
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
116 if not "Name" in config:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
117 config["Name"] = config_name
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
118
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
119 if not "HttpPort" in config:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
120 config["HttpPort"] = Helpers.orthanc_under_tests_http_port
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
121
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
122 if not "DicomPort" in config:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
123 config["DicomPort"] = Helpers.orthanc_under_tests_dicom_port
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
124
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
125 # copy the values from the base config
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
126 for k, v in default_base_config.items():
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
127 if not k in config:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
128 config[k] = v
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
129
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
130 # save to disk
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
131 path = str(here / "configurations" / f"{config_name}.json")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
132 with open(path, "w") as f:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
133 json.dump(config, f, indent=4)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
134
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
135 return path
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
136
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
137 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
138 def clear_storage(cls, storage_name: str):
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
139 storage_path = cls.get_storage_path(storage_name=storage_name)
593
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
140
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
141 # clear the directory but keep it !
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
142 for root, dirs, files in os.walk(storage_path):
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
143 for f in files:
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
144 os.unlink(os.path.join(root, f))
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
145 for d in dirs:
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
146 shutil.rmtree(os.path.join(root, d))
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
147 shutil.rmtree(storage_path, ignore_errors=True)
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
148
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
149 @classmethod
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
150 def is_storage_empty(cls, storage_name: str):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
151 storage_path = cls.get_storage_path(storage_name=storage_name)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
152 return len(glob.glob(os.path.join(storage_path, '*'))) == 0
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
153
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
154 @classmethod
577
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
155 def create_docker_network(cls, network: str):
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
156 if Helpers.is_docker():
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
157 subprocess.run(["docker", "network", "rm", network]) # ignore error
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
158 subprocess.run(["docker", "network", "create", network])
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
159
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
160 @classmethod
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
161 def launch_orthanc_to_prepare_db(cls, config_name: str = None, config: object = None, config_path: str = None, storage_name: str = None, plugins = []):
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
162 if config_name and storage_name and config:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
163 # generate the configuration file
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
164 config_path = cls.generate_configuration(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
165 config_name=config_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
166 storage_name=storage_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
167 config=config,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
168 plugins=plugins
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
169 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
170 elif not config_path or not storage_name or not config_name:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
171 raise RuntimeError("Invalid configuration")
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
172
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
173 # run orthanc
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
174 if Helpers.orthanc_previous_version_exe:
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
175 cls.launch_orthanc_exe(
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
176 exe_path=Helpers.orthanc_previous_version_exe,
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
177 config_path=config_path
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
178 )
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
179 elif Helpers.orthanc_previous_version_docker_image:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
180 cls.launch_orthanc_docker(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
181 docker_image=Helpers.orthanc_previous_version_docker_image,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
182 storage_name=storage_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
183 config_name=config_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
184 config_path=config_path
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
185 )
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
186 else:
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
187 raise RuntimeError("Invalid configuration, can not launch Orthanc")
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
188
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
189 @classmethod
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
190 def launch_orthanc_under_tests(cls, config_name: str = None, config: object = None, config_path: str = None, storage_name: str = None, plugins = [], docker_network: str = None, enable_verbose: bool = False, show_orthanc_output: bool = False):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
191 cls._show_orthanc_output = show_orthanc_output
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
192
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
193 if config_name and storage_name and config:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
194 # generate the configuration file
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
195 config_path = cls.generate_configuration(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
196 config_name=config_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
197 storage_name=storage_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
198 config=config,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
199 plugins=plugins
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
200 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
201 elif not config_path or not storage_name or not config_name:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
202 raise RuntimeError("Invalid configuration")
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
203
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
204 # run orthanc
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
205 if Helpers.orthanc_under_tests_exe:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
206 cls.launch_orthanc_exe(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
207 exe_path=Helpers.orthanc_under_tests_exe,
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
208 config_path=config_path,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
209 enable_verbose=enable_verbose
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
210 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
211 elif Helpers.orthanc_under_tests_docker_image:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
212 cls.launch_orthanc_docker(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
213 docker_image=Helpers.orthanc_under_tests_docker_image,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
214 storage_name=storage_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
215 config_name=config_name,
577
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
216 config_path=config_path,
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
217 network=docker_network,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
218 enable_verbose=enable_verbose
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
219 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
220 else:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
221 raise RuntimeError("Invalid configuration, can not launch Orthanc")
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
222
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
223 @classmethod
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
224 def launch_orthanc_exe(cls, exe_path: str, config_path: str, enable_verbose: bool = False, show_orthanc_output: bool = False):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
225 if enable_verbose:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
226 cmd = [exe_path, "--verbose", config_path]
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
227 else:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
228 cmd = [exe_path, config_path]
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
229
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
230 cls._orthanc_process = subprocess.Popen(
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
231 cmd,
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
232 stdout=subprocess.PIPE,
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
233 stderr=subprocess.PIPE
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
234 )
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
235
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
236 cls.o.wait_started(10)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
237 if not cls.o.is_alive():
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
238 output = cls.get_orthanc_process_output()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
239 print("Orthanc output\n" + output)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
240
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
241 raise RuntimeError(f"Orthanc failed to start '{exe_path}', conf = '{config_path}'. Check output above")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
242
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
243 @classmethod
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
244 def launch_orthanc_docker(cls, docker_image: str, storage_name: str, config_path: str, config_name: str, network: str = None, enable_verbose: bool = False):
484
ddfabe1fbee1 new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents: 483
diff changeset
245 storage_path = cls.get_storage_path(storage_name=storage_name)
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
246
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
247 cmd = [
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
248 "docker", "run", "--rm",
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
249 "-e", "VERBOSE_ENABLED=true" if enable_verbose else "VERBOSE_ENABLED=false",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
250 "-e", "VERBOSE_STARTUP=true" if enable_verbose else "VERBOSE_STARTUP=false",
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
251 "-v", f"{config_path}:/etc/orthanc/orthanc.json",
484
ddfabe1fbee1 new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents: 483
diff changeset
252 "-v", f"{storage_path}:/var/lib/orthanc/db/",
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
253 "--name", config_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
254 "-p", f"{Helpers.orthanc_under_tests_http_port}:{Helpers.orthanc_under_tests_http_port}",
577
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
255 "-p", f"{Helpers.orthanc_under_tests_dicom_port}:{Helpers.orthanc_under_tests_dicom_port}"
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
256 ]
577
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
257 if network:
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
258 cmd.extend(["--network", network])
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
259 cmd.append(docker_image)
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
260
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
261 cls._orthanc_container_name = config_name
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
262 print("docker cmd line: " + " ".join(cmd))
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
263
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
264 cls._orthanc_process = subprocess.Popen(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
265 cmd,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
266 stdout=subprocess.PIPE,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
267 stderr=subprocess.PIPE
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
268 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
269
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
270 cls.o.wait_started(10)
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
271 if not cls.o.is_alive():
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
272 output = cls.get_orthanc_process_output()
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
273 print("Orthanc output\n" + output)
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
274
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
275 raise RuntimeError(f"Orthanc failed to start Orthanc through Docker '{docker_image}', conf = '{config_path}'. Check output above")
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
276
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
277
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
278 @classmethod
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
279 def kill_orthanc(cls):
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
280 if Helpers.is_exe():
576
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
281 if cls._orthanc_process:
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
282 cls._orthanc_process.kill()
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
283 else:
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
284 return
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
285 else:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
286 subprocess.run(["docker", "stop", cls._orthanc_container_name])
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
287
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
288 if cls._show_orthanc_output:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
289 output = cls.get_orthanc_process_output()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
290 print("Orthanc output\n" + output)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
291
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
292 cls._orthanc_process = None
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
293
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
294 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
295 def get_orthanc_process_output(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
296 outputs = cls._orthanc_process.communicate()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
297 output = ""
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
298 for o in outputs:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
299 output += o.decode('utf-8')
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
300 return output