mbu-dev-shared-components 3.0.0__tar.gz → 3.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/PKG-INFO +4 -1
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components.egg-info/PKG-INFO +4 -1
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components.egg-info/SOURCES.txt +1 -2
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components.egg-info/requires.txt +3 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/pyproject.toml +4 -1
- mbu_dev_shared_components-3.0.0/tests/test_database.py +0 -319
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/LICENSE +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/README.md +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/database/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/database/connection.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/database/constants.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/database/logging.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/database/utility.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/getorganized/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/getorganized/auth.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/getorganized/cases.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/getorganized/contacts.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/getorganized/documents.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/getorganized/objects.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/google/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/google/api/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/google/api/auth.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/google/workspace/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/google/workspace/alerts.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/msoffice365/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/msoffice365/excel/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/msoffice365/excel/excel_reader.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/msoffice365/sharepoint_api/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/msoffice365/sharepoint_api/files.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/os2forms/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/os2forms/documents.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/os2forms/forms.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/romexis/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/romexis/db_handler.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/romexis/helper_functions.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/sap/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/sap/create_invoice.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/app_handler.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/appointment.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/base_ui.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/clinic.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/document.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/edi_portal.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/event.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/exceptions.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/handler_base.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/journal_note.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/application/patient.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/database/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/solteqtand/database/db_handler.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/utils/__init__.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/utils/db_stored_procedure_executor.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/utils/fernet_encryptor.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/utils/file_handler.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components/utils/json_handler.py +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components.egg-info/dependency_links.txt +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/mbu_dev_shared_components.egg-info/top_level.txt +0 -0
- {mbu_dev_shared_components-3.0.0 → mbu_dev_shared_components-3.0.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mbu_dev_shared_components
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.1
|
|
4
4
|
Summary: Shared components to use in RPA projects
|
|
5
5
|
Author-email: MBU <rpa@mbu.aarhus.dk>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -22,6 +22,9 @@ Requires-Dist: docx2pdf
|
|
|
22
22
|
Requires-Dist: pandas>=2.2.3
|
|
23
23
|
Requires-Dist: rawpy
|
|
24
24
|
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pylint; extra == "dev"
|
|
26
|
+
Requires-Dist: flake8; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-json-report; extra == "dev"
|
|
25
28
|
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
29
|
Requires-Dist: pytest-dependency>=0.5.1; extra == "dev"
|
|
27
30
|
Dynamic: license-file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mbu_dev_shared_components
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.1
|
|
4
4
|
Summary: Shared components to use in RPA projects
|
|
5
5
|
Author-email: MBU <rpa@mbu.aarhus.dk>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -22,6 +22,9 @@ Requires-Dist: docx2pdf
|
|
|
22
22
|
Requires-Dist: pandas>=2.2.3
|
|
23
23
|
Requires-Dist: rawpy
|
|
24
24
|
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pylint; extra == "dev"
|
|
26
|
+
Requires-Dist: flake8; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-json-report; extra == "dev"
|
|
25
28
|
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
29
|
Requires-Dist: pytest-dependency>=0.5.1; extra == "dev"
|
|
27
30
|
Dynamic: license-file
|
|
@@ -54,5 +54,4 @@ mbu_dev_shared_components/utils/__init__.py
|
|
|
54
54
|
mbu_dev_shared_components/utils/db_stored_procedure_executor.py
|
|
55
55
|
mbu_dev_shared_components/utils/fernet_encryptor.py
|
|
56
56
|
mbu_dev_shared_components/utils/file_handler.py
|
|
57
|
-
mbu_dev_shared_components/utils/json_handler.py
|
|
58
|
-
tests/test_database.py
|
|
57
|
+
mbu_dev_shared_components/utils/json_handler.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mbu_dev_shared_components"
|
|
7
|
-
version = "3.0.
|
|
7
|
+
version = "3.0.1" # Specify the version manually here
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="MBU", email="rpa@mbu.aarhus.dk" },
|
|
10
10
|
]
|
|
@@ -33,6 +33,9 @@ dependencies = [
|
|
|
33
33
|
|
|
34
34
|
[project.optional-dependencies]
|
|
35
35
|
dev = [
|
|
36
|
+
"pylint",
|
|
37
|
+
"flake8",
|
|
38
|
+
"pytest-json-report",
|
|
36
39
|
"pytest >= 7.0",
|
|
37
40
|
"pytest-dependency >= 0.5.1"
|
|
38
41
|
]
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Module to test RPAConnection functionalities in the Solteq Tand system
|
|
3
|
-
|
|
4
|
-
Tested functionalities:
|
|
5
|
-
|
|
6
|
-
- Establish database connection:
|
|
7
|
-
Function:
|
|
8
|
-
RPAConnection.__enter__
|
|
9
|
-
Assertion:
|
|
10
|
-
Connection and cursor are not None
|
|
11
|
-
Dependencies:
|
|
12
|
-
None
|
|
13
|
-
|
|
14
|
-
- Add and retrieve constant:
|
|
15
|
-
Function:
|
|
16
|
-
RPAConnection.add_constant, RPAConnection.get_constant
|
|
17
|
-
Assertion:
|
|
18
|
-
Constant is correctly inserted and retrieved
|
|
19
|
-
Dependencies:
|
|
20
|
-
test_connection
|
|
21
|
-
|
|
22
|
-
- Add and retrieve credential:
|
|
23
|
-
Function:
|
|
24
|
-
RPAConnection.add_credential, RPAConnection.get_credential
|
|
25
|
-
Assertion:
|
|
26
|
-
Credential is correctly inserted and retrieved
|
|
27
|
-
Dependencies:
|
|
28
|
-
test_connection
|
|
29
|
-
|
|
30
|
-
- Rollback functionality:
|
|
31
|
-
Function:
|
|
32
|
-
RPAConnection.__exit__
|
|
33
|
-
Assertion:
|
|
34
|
-
Constant added without commit is not persisted
|
|
35
|
-
Dependencies:
|
|
36
|
-
test_connection, test_add_get_constant
|
|
37
|
-
|
|
38
|
-
- Log event:
|
|
39
|
-
Function:
|
|
40
|
-
RPAConnection.log_event, RPAConnection.get_latest_log
|
|
41
|
-
Assertion:
|
|
42
|
-
Log entry is correctly inserted and retrieved
|
|
43
|
-
Dependencies:
|
|
44
|
-
None
|
|
45
|
-
|
|
46
|
-
- Heartbeat logging (stop as string):
|
|
47
|
-
Function:
|
|
48
|
-
RPAConnection.log_heartbeat, RPAConnection.get_heartbeat
|
|
49
|
-
Assertion:
|
|
50
|
-
Heartbeat status is "STOPPED"
|
|
51
|
-
Dependencies:
|
|
52
|
-
None
|
|
53
|
-
|
|
54
|
-
- Heartbeat logging (stop as boolean):
|
|
55
|
-
Function:
|
|
56
|
-
RPAConnection.log_heartbeat, RPAConnection.get_heartbeat
|
|
57
|
-
Assertion:
|
|
58
|
-
Heartbeat status is "STOPPED"
|
|
59
|
-
Dependencies:
|
|
60
|
-
None
|
|
61
|
-
|
|
62
|
-
- Run heartbeat process:
|
|
63
|
-
Function:
|
|
64
|
-
External subprocess running heartbeat_worker.py
|
|
65
|
-
Assertion:
|
|
66
|
-
Heartbeat status is "RUNNING" and updates over time
|
|
67
|
-
Dependencies:
|
|
68
|
-
None
|
|
69
|
-
|
|
70
|
-
Requirements:
|
|
71
|
-
- Database environment variable `TEST` must be configured
|
|
72
|
-
- pyodbc must be installed and accessible
|
|
73
|
-
- mbu_dev_shared_components must be available in PYTHONPATH
|
|
74
|
-
- `heartbeat_worker.py` must exist in the `tests/` directory and be executable
|
|
75
|
-
- `.venv/Scripts/python` must point to the correct Python interpreter
|
|
76
|
-
Further description:
|
|
77
|
-
Each test uses the RPAConnection context manager to ensure proper handling of database transactions.
|
|
78
|
-
COMMIT is set to False to test rollback behavior and avoid persistent changes to the test database.
|
|
79
|
-
Heartbeat and logging tests validate time-sensitive operations with a threshold of 0.5 seconds.
|
|
80
|
-
The heartbeat process test (`test_run_heartbeat`) runs a parallel subprocess to simulate real-time heartbeat updates.
|
|
81
|
-
"""
|
|
82
|
-
|
|
83
|
-
from datetime import datetime, timedelta
|
|
84
|
-
import time
|
|
85
|
-
from uuid import uuid4
|
|
86
|
-
import socket
|
|
87
|
-
import subprocess
|
|
88
|
-
|
|
89
|
-
import pyodbc
|
|
90
|
-
import pytest
|
|
91
|
-
from mbu_dev_shared_components.database.connection import RPAConnection
|
|
92
|
-
|
|
93
|
-
# Global test configuration
|
|
94
|
-
DB_ENV = "TEST"
|
|
95
|
-
COMMIT = False
|
|
96
|
-
THRES_SEC = 0.5
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
@pytest.mark.dependency()
|
|
100
|
-
def test_connection():
|
|
101
|
-
"""Test that RPAConnection successfully establishes a database connection
|
|
102
|
-
|
|
103
|
-
Verifies that the `conn` and `cursor` attributes are initialized and not None
|
|
104
|
-
after creating an instance of RPAConnection. Checks that
|
|
105
|
-
"""
|
|
106
|
-
with RPAConnection(db_env=DB_ENV, commit=COMMIT) as rpa_connection:
|
|
107
|
-
# Assert connection is established
|
|
108
|
-
assert rpa_connection.conn is not None
|
|
109
|
-
assert rpa_connection.cursor is not None
|
|
110
|
-
|
|
111
|
-
# Assert connection is closed
|
|
112
|
-
with pytest.raises(pyodbc.ProgrammingError, match="Attempt to use a closed cursor."):
|
|
113
|
-
rpa_connection.get_constant("test_uuid")
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
@pytest.mark.dependency(depends=["test_connection"])
|
|
117
|
-
def test_add_get_constant():
|
|
118
|
-
"""
|
|
119
|
-
Adds a test constant, rolls back the transaction.
|
|
120
|
-
"""
|
|
121
|
-
test_constant_name = f"pytest_constant_{uuid4()}"
|
|
122
|
-
test_value = "temporary_value"
|
|
123
|
-
|
|
124
|
-
with RPAConnection(db_env=DB_ENV, commit=COMMIT) as rpa_connection:
|
|
125
|
-
# Add constant (should be rolled back)
|
|
126
|
-
rpa_connection.add_constant(test_constant_name, test_value, datetime.now())
|
|
127
|
-
|
|
128
|
-
assert rpa_connection.cursor.rowcount == 1
|
|
129
|
-
|
|
130
|
-
# Check that constant is added (will be rolled back after function)
|
|
131
|
-
test_const = rpa_connection.get_constant(test_constant_name)
|
|
132
|
-
|
|
133
|
-
assert test_const
|
|
134
|
-
assert test_const["constant_name"] == test_constant_name
|
|
135
|
-
assert test_const["value"] == test_value
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
@pytest.mark.dependency(depends=["test_connection"])
|
|
139
|
-
def test_add_get_credential():
|
|
140
|
-
"""
|
|
141
|
-
Adds a test credential, rolls back the transaction.
|
|
142
|
-
"""
|
|
143
|
-
test_credential_name = f"pytest_constant_{uuid4()}"
|
|
144
|
-
test_username = "test_user"
|
|
145
|
-
test_password = "test_password"
|
|
146
|
-
|
|
147
|
-
with RPAConnection(db_env=DB_ENV, commit=COMMIT) as rpa_connection:
|
|
148
|
-
# Add constant (should be rolled back)
|
|
149
|
-
rpa_connection.add_credential(test_credential_name, test_username, test_password, datetime.now())
|
|
150
|
-
|
|
151
|
-
# Check that constant is added (will be rolled back after function)
|
|
152
|
-
test_const = rpa_connection.get_credential(test_credential_name)
|
|
153
|
-
|
|
154
|
-
assert test_const
|
|
155
|
-
assert test_const["username"] == test_username
|
|
156
|
-
assert test_const["decrypted_password"] == test_password
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
@pytest.mark.dependency(depends=["test_connection", "test_add_get_constant"])
|
|
160
|
-
def test_rollback():
|
|
161
|
-
"""
|
|
162
|
-
Test that rollback undoes the insertion of a constant through the context manager.
|
|
163
|
-
Asserts that a constant added in a scope without commiting to the db cannot be accessed outside the scope
|
|
164
|
-
"""
|
|
165
|
-
test_constant_name = f"pytest_rollback_same_conn_{uuid4()}"
|
|
166
|
-
test_value = "temporary_value"
|
|
167
|
-
|
|
168
|
-
with RPAConnection(db_env=DB_ENV, commit=COMMIT) as rpa_connection:
|
|
169
|
-
# Add constant
|
|
170
|
-
rpa_connection.add_constant(test_constant_name, test_value, datetime.now())
|
|
171
|
-
|
|
172
|
-
with RPAConnection(db_env=DB_ENV, commit=COMMIT) as rpa_connection:
|
|
173
|
-
# Try to retrieve the constant in new connection
|
|
174
|
-
with pytest.raises(ValueError, match=f"No constant found with name: {test_constant_name}"):
|
|
175
|
-
rpa_connection.get_constant(test_constant_name)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
def test_log():
|
|
179
|
-
"""Test log functionality """
|
|
180
|
-
|
|
181
|
-
# Variables for test log row
|
|
182
|
-
log_db = "journalizing.Journalize_log"
|
|
183
|
-
level = "INFO"
|
|
184
|
-
message = "test_log"
|
|
185
|
-
context = "pytest"
|
|
186
|
-
|
|
187
|
-
with RPAConnection(db_env=DB_ENV, commit=COMMIT) as rpa_connection:
|
|
188
|
-
now = datetime.now()
|
|
189
|
-
# Attempt insertion of log_event
|
|
190
|
-
rpa_connection.log_event(
|
|
191
|
-
log_db=log_db,
|
|
192
|
-
level=level,
|
|
193
|
-
message=message,
|
|
194
|
-
context=context
|
|
195
|
-
)
|
|
196
|
-
# Assert that one row is inserted
|
|
197
|
-
assert rpa_connection.cursor.rowcount == 1
|
|
198
|
-
|
|
199
|
-
# Get latest log
|
|
200
|
-
# pylint: disable-next=W0212
|
|
201
|
-
log_row = rpa_connection.get_latest_log(
|
|
202
|
-
log_db=log_db
|
|
203
|
-
)[0]
|
|
204
|
-
|
|
205
|
-
# Assert values of inserted element
|
|
206
|
-
assert log_row[0] == level
|
|
207
|
-
assert log_row[1] == message
|
|
208
|
-
assert abs(log_row[2]-now) < timedelta(seconds=THRES_SEC) # Latest log was within 0.1 second of start of function
|
|
209
|
-
assert log_row[3] == context
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
def test_stop_heartbeat_str():
|
|
213
|
-
"""Test stopping heartbeat functionality"""
|
|
214
|
-
|
|
215
|
-
servicename = "pytest"
|
|
216
|
-
heartbeat_interval = 1.0
|
|
217
|
-
details = "pytest testing heartbeat functionality"
|
|
218
|
-
stop = "True"
|
|
219
|
-
with RPAConnection(db_env=DB_ENV, commit=COMMIT) as rpa_connection:
|
|
220
|
-
now = datetime.now()
|
|
221
|
-
rpa_connection.log_heartbeat(
|
|
222
|
-
stop=stop,
|
|
223
|
-
servicename=servicename,
|
|
224
|
-
heartbeat_interval=heartbeat_interval,
|
|
225
|
-
details=details
|
|
226
|
-
)
|
|
227
|
-
|
|
228
|
-
heartbeat = rpa_connection.get_heartbeat(service_name=servicename)[0]
|
|
229
|
-
|
|
230
|
-
assert heartbeat[0] == servicename
|
|
231
|
-
assert abs(heartbeat[1]-now) < timedelta(seconds=THRES_SEC)
|
|
232
|
-
assert heartbeat[2] == "STOPPED"
|
|
233
|
-
assert heartbeat[3] == socket.gethostname()
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
def test_stop_heartbeat_bool():
|
|
237
|
-
"""Test stopping heartbeat functionality"""
|
|
238
|
-
|
|
239
|
-
servicename = "pytest"
|
|
240
|
-
heartbeat_interval = 1.0
|
|
241
|
-
details = "pytest testing heartbeat functionality"
|
|
242
|
-
stop = True
|
|
243
|
-
with RPAConnection(db_env=DB_ENV, commit=COMMIT) as rpa_connection:
|
|
244
|
-
now = datetime.now()
|
|
245
|
-
rpa_connection.log_heartbeat(
|
|
246
|
-
stop=stop,
|
|
247
|
-
servicename=servicename,
|
|
248
|
-
heartbeat_interval=heartbeat_interval,
|
|
249
|
-
details=details
|
|
250
|
-
)
|
|
251
|
-
|
|
252
|
-
heartbeat = rpa_connection.get_heartbeat(service_name=servicename)[0]
|
|
253
|
-
|
|
254
|
-
assert heartbeat[0] == servicename
|
|
255
|
-
assert abs(heartbeat[1]-now) < timedelta(seconds=THRES_SEC)
|
|
256
|
-
assert heartbeat[2] == "STOPPED"
|
|
257
|
-
assert heartbeat[3] == socket.gethostname()
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
def test_run_heartbeat():
|
|
261
|
-
"""Test running heartbeat functionality
|
|
262
|
-
Uses subprocess to run the heartbeat process in parallel and allows to stop it after some time
|
|
263
|
-
Since we are using a stored procedure, we cannot roll back the transaction, so we have to accept the table being affected by the test
|
|
264
|
-
Effectively we insert one row to the heartbeat table for the 'pytest' service
|
|
265
|
-
"""
|
|
266
|
-
servicename = "pytest"
|
|
267
|
-
heartbeat_interval = 2.0
|
|
268
|
-
details = "pytest testing heartbeat functionality"
|
|
269
|
-
stop = False
|
|
270
|
-
now = datetime.now()
|
|
271
|
-
heartbeat_process = subprocess.Popen(
|
|
272
|
-
[
|
|
273
|
-
".venv/Scripts/python",
|
|
274
|
-
"tests/heartbeat_worker.py",
|
|
275
|
-
DB_ENV,
|
|
276
|
-
str(stop),
|
|
277
|
-
servicename,
|
|
278
|
-
str(heartbeat_interval),
|
|
279
|
-
details
|
|
280
|
-
]
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
time.sleep(heartbeat_interval)
|
|
284
|
-
|
|
285
|
-
with RPAConnection(db_env="TEST", commit=False) as rpa_connection:
|
|
286
|
-
heartbeat = rpa_connection.get_heartbeat(servicename)[0]
|
|
287
|
-
|
|
288
|
-
# Assert heartbeat is running and recent
|
|
289
|
-
assert heartbeat[0] == servicename
|
|
290
|
-
assert abs(heartbeat[1]-now) < timedelta(seconds=THRES_SEC)
|
|
291
|
-
assert heartbeat[2] == "RUNNING"
|
|
292
|
-
assert heartbeat[3] == socket.gethostname()
|
|
293
|
-
|
|
294
|
-
# Test that heartbeat is updated by heartbeat interval time
|
|
295
|
-
for i in range(5):
|
|
296
|
-
print(f"Running assertion loop {i+1}")
|
|
297
|
-
prev_heartbeat_time = heartbeat[1]
|
|
298
|
-
time.sleep(heartbeat_interval)
|
|
299
|
-
# Get new heartbeat and assert that it is newer than previous hearbeat
|
|
300
|
-
heartbeat = rpa_connection.get_heartbeat(servicename)[0]
|
|
301
|
-
assert heartbeat[1] > prev_heartbeat_time, f"Heartbeat not updated on iteration {i+1}"
|
|
302
|
-
|
|
303
|
-
print("Should have finished assertion loop ")
|
|
304
|
-
|
|
305
|
-
heartbeat_process.terminate()
|
|
306
|
-
|
|
307
|
-
print("Should have terminated heartbeat process")
|
|
308
|
-
|
|
309
|
-
with RPAConnection(db_env="TEST", commit=True) as rpa_connection:
|
|
310
|
-
rpa_connection.log_heartbeat(
|
|
311
|
-
stop=True,
|
|
312
|
-
servicename=servicename,
|
|
313
|
-
heartbeat_interval=2,
|
|
314
|
-
details="Stop send from pytest"
|
|
315
|
-
)
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if __name__ == '__main__':
|
|
319
|
-
pytest.main([__file__])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|