mesh-sandbox 1.0.10__py3-none-any.whl → 1.0.12__py3-none-any.whl
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.
- mesh_sandbox/__init__.py +1 -1
- mesh_sandbox/api.py +0 -1
- mesh_sandbox/common/__init__.py +1 -3
- mesh_sandbox/common/messaging.py +20 -32
- mesh_sandbox/common/mex_headers.py +0 -1
- mesh_sandbox/conftest.py +2 -6
- mesh_sandbox/dependencies.py +5 -6
- mesh_sandbox/handlers/admin.py +0 -2
- mesh_sandbox/handlers/handshake.py +0 -2
- mesh_sandbox/handlers/inbox.py +1 -10
- mesh_sandbox/handlers/lookup.py +0 -2
- mesh_sandbox/handlers/outbox.py +4 -8
- mesh_sandbox/handlers/tracking.py +0 -2
- mesh_sandbox/models/mailbox.py +0 -2
- mesh_sandbox/models/message.py +2 -5
- mesh_sandbox/models/workflow.py +0 -2
- mesh_sandbox/routers/inbox.py +5 -5
- mesh_sandbox/routers/inbox_count.py +2 -2
- mesh_sandbox/routers/lookup.py +3 -4
- mesh_sandbox/routers/outbox.py +3 -3
- mesh_sandbox/routers/tracking.py +2 -2
- mesh_sandbox/store/base.py +0 -1
- mesh_sandbox/store/canned_store.py +9 -15
- mesh_sandbox/store/file_store.py +0 -1
- mesh_sandbox/store/serialisation.py +2 -3
- mesh_sandbox/test_plugin/example_plugin.py +3 -4
- mesh_sandbox/tests/admin.py +0 -26
- mesh_sandbox/tests/docker_tests.py +0 -2
- mesh_sandbox/tests/exceptions.py +0 -1
- mesh_sandbox/tests/handshake.py +3 -11
- mesh_sandbox/tests/helpers.py +0 -3
- mesh_sandbox/tests/inbox.py +0 -13
- mesh_sandbox/tests/java_client_tests.py +1 -6
- mesh_sandbox/tests/lookup.py +2 -4
- mesh_sandbox/tests/mesh_api_helpers.py +1 -8
- mesh_sandbox/tests/mesh_client_tests.py +7 -12
- mesh_sandbox/tests/messaging_tests.py +13 -23
- mesh_sandbox/tests/outbox.py +1 -15
- mesh_sandbox/tests/serialisation.py +0 -1
- mesh_sandbox/views/error.py +3 -7
- mesh_sandbox/views/inbox.py +4 -7
- mesh_sandbox/views/lookup.py +6 -6
- mesh_sandbox/views/outbox.py +21 -26
- mesh_sandbox/views/tracking.py +0 -4
- {mesh_sandbox-1.0.10.dist-info → mesh_sandbox-1.0.12.dist-info}/METADATA +16 -41
- mesh_sandbox-1.0.12.dist-info/RECORD +76 -0
- mesh_sandbox-1.0.10.dist-info/RECORD +0 -76
- {mesh_sandbox-1.0.10.dist-info → mesh_sandbox-1.0.12.dist-info}/LICENSE +0 -0
- {mesh_sandbox-1.0.10.dist-info → mesh_sandbox-1.0.12.dist-info}/WHEEL +0 -0
|
@@ -79,20 +79,18 @@ class CannedStore(Store):
|
|
|
79
79
|
)
|
|
80
80
|
|
|
81
81
|
def _load_endpoints(self) -> dict[str, list[Mailbox]]:
|
|
82
|
-
|
|
83
82
|
canned_workflows = os.path.join(self._canned_data_dir, "workflows.jsonl")
|
|
84
83
|
endpoints: dict[str, list[Mailbox]] = defaultdict(list)
|
|
85
84
|
|
|
86
85
|
if not os.path.exists(canned_workflows):
|
|
87
86
|
return endpoints
|
|
88
87
|
|
|
89
|
-
with open(canned_workflows,
|
|
90
|
-
workflows =
|
|
88
|
+
with open(canned_workflows, encoding="utf-8") as f:
|
|
89
|
+
workflows = [
|
|
91
90
|
cast(Workflow, deserialise_model(json.loads(line), Workflow)) for line in f.readlines() if line.strip()
|
|
92
|
-
|
|
91
|
+
]
|
|
93
92
|
|
|
94
93
|
for workflow in workflows:
|
|
95
|
-
|
|
96
94
|
receivers = workflow.receivers
|
|
97
95
|
for receiver in receivers:
|
|
98
96
|
receiver = (receiver or "").strip().upper()
|
|
@@ -109,13 +107,12 @@ class CannedStore(Store):
|
|
|
109
107
|
return endpoints
|
|
110
108
|
|
|
111
109
|
def _load_mailboxes(self) -> dict[str, Mailbox]:
|
|
112
|
-
|
|
113
110
|
canned_mailboxes = os.path.join(self._canned_data_dir, "mailboxes.jsonl")
|
|
114
111
|
|
|
115
112
|
if not os.path.exists(canned_mailboxes):
|
|
116
113
|
return {}
|
|
117
114
|
|
|
118
|
-
with open(canned_mailboxes,
|
|
115
|
+
with open(canned_mailboxes, encoding="utf-8") as f:
|
|
119
116
|
return {
|
|
120
117
|
mailbox.mailbox_id: mailbox
|
|
121
118
|
for mailbox in (
|
|
@@ -126,7 +123,6 @@ class CannedStore(Store):
|
|
|
126
123
|
}
|
|
127
124
|
|
|
128
125
|
def _load_messages(self) -> dict[str, Message]:
|
|
129
|
-
|
|
130
126
|
messages: dict[str, Message] = {}
|
|
131
127
|
|
|
132
128
|
if not os.path.exists(self._mailboxes_data_dir):
|
|
@@ -147,12 +143,11 @@ class CannedStore(Store):
|
|
|
147
143
|
continue
|
|
148
144
|
|
|
149
145
|
for message_path in os.scandir(inbox_dir):
|
|
150
|
-
|
|
151
146
|
if not message_path.is_file() or not message_path.name.endswith(".json"):
|
|
152
147
|
continue
|
|
153
148
|
|
|
154
149
|
try:
|
|
155
|
-
with open(message_path.path,
|
|
150
|
+
with open(message_path.path, encoding="utf-8") as f:
|
|
156
151
|
message = deserialise_model(json.load(f), Message)
|
|
157
152
|
assert message
|
|
158
153
|
message_expiry_date = message.created_timestamp + relativedelta(
|
|
@@ -168,7 +163,6 @@ class CannedStore(Store):
|
|
|
168
163
|
return messages
|
|
169
164
|
|
|
170
165
|
def _load_chunks(self) -> dict[str, list[Optional[bytes]]]:
|
|
171
|
-
|
|
172
166
|
chunks: dict[str, list[Optional[bytes]]] = defaultdict(list)
|
|
173
167
|
|
|
174
168
|
for message in self.messages.values():
|
|
@@ -210,7 +204,7 @@ class CannedStore(Store):
|
|
|
210
204
|
"""does nothing on this readonly store..."""
|
|
211
205
|
|
|
212
206
|
async def save_message(self, message: Message):
|
|
213
|
-
raise NotImplementedError
|
|
207
|
+
raise NotImplementedError
|
|
214
208
|
|
|
215
209
|
async def get_chunk(self, message: Message, chunk_number: int) -> Optional[bytes]:
|
|
216
210
|
parts = self.chunks.get(message.message_id, [])
|
|
@@ -219,13 +213,13 @@ class CannedStore(Store):
|
|
|
219
213
|
return parts[chunk_number - 1]
|
|
220
214
|
|
|
221
215
|
async def save_chunk(self, message: Message, chunk_number: int, chunk: bytes):
|
|
222
|
-
raise NotImplementedError
|
|
216
|
+
raise NotImplementedError
|
|
223
217
|
|
|
224
218
|
async def reset(self):
|
|
225
|
-
raise NotImplementedError
|
|
219
|
+
raise NotImplementedError
|
|
226
220
|
|
|
227
221
|
async def reset_mailbox(self, mailbox_id: str):
|
|
228
|
-
raise NotImplementedError
|
|
222
|
+
raise NotImplementedError
|
|
229
223
|
|
|
230
224
|
async def get_inbox_messages(
|
|
231
225
|
self, mailbox_id: str, predicate: Optional[Callable[[Message], bool]] = None
|
mesh_sandbox/store/file_store.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from dataclasses import fields, is_dataclass
|
|
2
2
|
from datetime import date, datetime
|
|
3
|
-
from typing import Any, Optional,
|
|
3
|
+
from typing import Any, Optional, TypeVar, cast, get_args, get_origin
|
|
4
4
|
|
|
5
5
|
_NoneType = type(None)
|
|
6
6
|
|
|
@@ -62,7 +62,6 @@ def serialise_model(model) -> Optional[dict[str, Any]]:
|
|
|
62
62
|
result: dict[str, Any] = {}
|
|
63
63
|
|
|
64
64
|
for field in fields(model):
|
|
65
|
-
|
|
66
65
|
value = getattr(model, field.name)
|
|
67
66
|
if value is None:
|
|
68
67
|
# don't store None values.
|
|
@@ -116,7 +115,7 @@ def _deserialise_value(field_type, value):
|
|
|
116
115
|
TModel = TypeVar("TModel") # pylint: disable=invalid-name
|
|
117
116
|
|
|
118
117
|
|
|
119
|
-
def deserialise_model(model_dict: dict[str, Any], model_type:
|
|
118
|
+
def deserialise_model(model_dict: dict[str, Any], model_type: type[TModel]) -> Optional[TModel]:
|
|
120
119
|
if model_dict is None:
|
|
121
120
|
return None
|
|
122
121
|
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os.path
|
|
3
|
-
from typing import Any, Optional
|
|
3
|
+
from typing import Any, ClassVar, Optional
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class OnMessageAcceptedPlugin:
|
|
7
7
|
def __init__(self):
|
|
8
8
|
self.logger = logging.getLogger("mesh-sandbox")
|
|
9
|
-
with open(os.path.join(os.path.dirname(__file__), "example_plugin.txt"), encoding="utf-8"
|
|
9
|
+
with open(os.path.join(os.path.dirname(__file__), "example_plugin.txt"), encoding="utf-8") as f:
|
|
10
10
|
self.config_message = f.read().strip()
|
|
11
11
|
|
|
12
|
-
triggers = ["before_accept_message"]
|
|
12
|
+
triggers: ClassVar[list[str]] = ["before_accept_message"]
|
|
13
13
|
|
|
14
14
|
async def on_event(self, event: str, kwargs: dict[str, Any], err: Optional[Exception] = None):
|
|
15
|
-
|
|
16
15
|
if err:
|
|
17
16
|
print(f"plugin received error {event}\n{kwargs}\n{err}")
|
|
18
17
|
return
|
mesh_sandbox/tests/admin.py
CHANGED
|
@@ -22,41 +22,31 @@ from .helpers import generate_auth_token, temp_env_vars
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
def test_reset_canned_store_should_return_bad_request(app: TestClient):
|
|
25
|
-
|
|
26
25
|
with temp_env_vars(STORE_MODE="canned"):
|
|
27
|
-
|
|
28
26
|
res = app.delete("/messageexchange/admin/reset")
|
|
29
27
|
assert res.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
|
|
30
28
|
|
|
31
29
|
|
|
32
30
|
def test_reset_canned_store_with_valid_mailbox_id_should_return_bad_request(app: TestClient):
|
|
33
|
-
|
|
34
31
|
with temp_env_vars(STORE_MODE="canned"):
|
|
35
|
-
|
|
36
32
|
res = app.delete(f"/messageexchange/admin/reset/{_CANNED_MAILBOX1}")
|
|
37
33
|
assert res.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
|
|
38
34
|
|
|
39
35
|
|
|
40
36
|
def test_reset_memory_store_with_invalid_mailbox_id_should_return_bad_request(app: TestClient):
|
|
41
|
-
|
|
42
37
|
with temp_env_vars(STORE_MODE="memory"):
|
|
43
|
-
|
|
44
38
|
res = app.delete(f"/messageexchange/admin/reset/{uuid4().hex}")
|
|
45
39
|
assert res.status_code == status.HTTP_404_NOT_FOUND
|
|
46
40
|
|
|
47
41
|
|
|
48
42
|
def test_reset_file_store_with_invalid_mailbox_id_should_return_bad_request(app: TestClient):
|
|
49
|
-
|
|
50
43
|
with temp_env_vars(STORE_MODE="file"):
|
|
51
|
-
|
|
52
44
|
res = app.delete(f"/messageexchange/admin/reset/{uuid4().hex}")
|
|
53
45
|
assert res.status_code == status.HTTP_404_NOT_FOUND
|
|
54
46
|
|
|
55
47
|
|
|
56
48
|
def test_reset_memory_store_should_clear_all_mailboxes(app: TestClient):
|
|
57
|
-
|
|
58
49
|
with temp_env_vars(STORE_MODE="memory"):
|
|
59
|
-
|
|
60
50
|
msg_1to2_id = mesh_api_send_message_and_return_message_id(app, _CANNED_MAILBOX1, _CANNED_MAILBOX2)
|
|
61
51
|
assert mesh_api_get_inbox_size(app, _CANNED_MAILBOX2) == 1
|
|
62
52
|
|
|
@@ -78,9 +68,7 @@ def test_reset_memory_store_should_clear_all_mailboxes(app: TestClient):
|
|
|
78
68
|
|
|
79
69
|
|
|
80
70
|
def test_reset_memory_store_should_clear_specified_mailbox_only(app: TestClient):
|
|
81
|
-
|
|
82
71
|
with temp_env_vars(STORE_MODE="memory"):
|
|
83
|
-
|
|
84
72
|
msg_1to2_id = mesh_api_send_message_and_return_message_id(app, _CANNED_MAILBOX1, _CANNED_MAILBOX2)
|
|
85
73
|
assert mesh_api_get_inbox_size(app, _CANNED_MAILBOX2) == 1
|
|
86
74
|
|
|
@@ -142,9 +130,7 @@ def test_reset_memory_store_should_clear_specified_mailbox_only(app: TestClient)
|
|
|
142
130
|
|
|
143
131
|
|
|
144
132
|
def test_reset_file_store_should_clear_all_mailboxes_and_maybe_files(app: TestClient, tmp_path: str):
|
|
145
|
-
|
|
146
133
|
with temp_env_vars(STORE_MODE="file", MAILBOXES_DATA_DIR=tmp_path):
|
|
147
|
-
|
|
148
134
|
msg_1to2_id = mesh_api_send_message_and_return_message_id(app, _CANNED_MAILBOX1, _CANNED_MAILBOX2)
|
|
149
135
|
assert mesh_api_get_inbox_size(app, _CANNED_MAILBOX2) == 1
|
|
150
136
|
|
|
@@ -185,9 +171,7 @@ def test_reset_file_store_should_clear_all_mailboxes_and_maybe_files(app: TestCl
|
|
|
185
171
|
|
|
186
172
|
|
|
187
173
|
def test_reset_file_store_should_clear_specified_mailbox_only_and_maybe_files(app: TestClient, tmp_path: str):
|
|
188
|
-
|
|
189
174
|
with temp_env_vars(STORE_MODE="file", MAILBOXES_DATA_DIR=tmp_path):
|
|
190
|
-
|
|
191
175
|
msg_1to2_id = mesh_api_send_message_and_return_message_id(app, _CANNED_MAILBOX1, _CANNED_MAILBOX2)
|
|
192
176
|
assert mesh_api_get_inbox_size(app, _CANNED_MAILBOX2) == 1
|
|
193
177
|
|
|
@@ -224,9 +208,7 @@ def test_reset_file_store_should_clear_specified_mailbox_only_and_maybe_files(ap
|
|
|
224
208
|
def test_reset_file_store_should_not_error_if_folder_does_not_exist_yet(
|
|
225
209
|
app: TestClient, clear_disk: str, tmp_path: str
|
|
226
210
|
):
|
|
227
|
-
|
|
228
211
|
with temp_env_vars(STORE_MODE="file", MAILBOXES_DATA_DIR=tmp_path):
|
|
229
|
-
|
|
230
212
|
inbox_folder = os.path.join(tmp_path, _CANNED_MAILBOX1, "in")
|
|
231
213
|
assert not os.path.exists(inbox_folder)
|
|
232
214
|
|
|
@@ -236,11 +218,9 @@ def test_reset_file_store_should_not_error_if_folder_does_not_exist_yet(
|
|
|
236
218
|
|
|
237
219
|
|
|
238
220
|
def test_put_report_in_inbox(app: TestClient, tmp_path: str):
|
|
239
|
-
|
|
240
221
|
recipient = _CANNED_MAILBOX1
|
|
241
222
|
|
|
242
223
|
with temp_env_vars(STORE_MODE="file", MAILBOXES_DATA_DIR=tmp_path):
|
|
243
|
-
|
|
244
224
|
request = CreateReportRequest(
|
|
245
225
|
mailbox_id=recipient,
|
|
246
226
|
status=MessageStatus.ERROR,
|
|
@@ -301,11 +281,9 @@ def test_put_report_in_inbox(app: TestClient, tmp_path: str):
|
|
|
301
281
|
|
|
302
282
|
|
|
303
283
|
def test_add_message_event(app: TestClient, tmp_path: str):
|
|
304
|
-
|
|
305
284
|
recipient = _CANNED_MAILBOX1
|
|
306
285
|
|
|
307
286
|
with temp_env_vars(STORE_MODE="file", MAILBOXES_DATA_DIR=tmp_path):
|
|
308
|
-
|
|
309
287
|
create_report_request = CreateReportRequest(
|
|
310
288
|
mailbox_id=recipient,
|
|
311
289
|
status=MessageStatus.ERROR,
|
|
@@ -363,18 +341,14 @@ def test_add_message_event(app: TestClient, tmp_path: str):
|
|
|
363
341
|
|
|
364
342
|
@pytest.mark.parametrize("root_path", ["/admin/mailbox", "/messageexchange/admin/mailbox"])
|
|
365
343
|
def test_get_mailbox_invalid_mailbox_returns_404(app: TestClient, root_path: str):
|
|
366
|
-
|
|
367
344
|
with temp_env_vars(STORE_MODE="canned"):
|
|
368
|
-
|
|
369
345
|
res = app.get(f"{root_path}/NotAMailboxId")
|
|
370
346
|
assert res.status_code == status.HTTP_404_NOT_FOUND
|
|
371
347
|
|
|
372
348
|
|
|
373
349
|
@pytest.mark.parametrize("root_path", ["/admin/mailbox", "/messageexchange/admin/mailbox"])
|
|
374
350
|
def test_get_mailbox_happy_path(app: TestClient, root_path: str):
|
|
375
|
-
|
|
376
351
|
with temp_env_vars(STORE_MODE="canned"):
|
|
377
|
-
|
|
378
352
|
res = app.get(f"{root_path}/{_CANNED_MAILBOX1}")
|
|
379
353
|
assert res.status_code == status.HTTP_200_OK
|
|
380
354
|
|
|
@@ -9,7 +9,6 @@ _PASSWORD = "password"
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def test_send_receive_chunked_message():
|
|
12
|
-
|
|
13
12
|
sender_mailbox_id = _CANNED_MAILBOX1
|
|
14
13
|
recipient_mailbox_id = _CANNED_MAILBOX2
|
|
15
14
|
workflow_id = uuid4().hex
|
|
@@ -24,7 +23,6 @@ def test_send_receive_chunked_message():
|
|
|
24
23
|
max_chunk_size=100,
|
|
25
24
|
verify=False,
|
|
26
25
|
) as sender:
|
|
27
|
-
|
|
28
26
|
sent_payload = b"a" * 1000
|
|
29
27
|
|
|
30
28
|
message_id = sender.send_message(_CANNED_MAILBOX2, sent_payload, workflow_id=workflow_id, subject="change me")
|
mesh_sandbox/tests/exceptions.py
CHANGED
mesh_sandbox/tests/handshake.py
CHANGED
|
@@ -13,7 +13,7 @@ _CANNED_MAILBOX2 = "X26ABC2"
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
@pytest.mark.parametrize(
|
|
16
|
-
"mailbox_id, accepts",
|
|
16
|
+
("mailbox_id", "accepts"),
|
|
17
17
|
[
|
|
18
18
|
(_CANNED_MAILBOX1, APP_JSON),
|
|
19
19
|
(_CANNED_MAILBOX1, APP_V1_JSON),
|
|
@@ -24,7 +24,6 @@ _CANNED_MAILBOX2 = "X26ABC2"
|
|
|
24
24
|
],
|
|
25
25
|
)
|
|
26
26
|
def test_handshake_no_auth_mailbox_exists(app: TestClient, mailbox_id: str, accepts: str):
|
|
27
|
-
|
|
28
27
|
with temp_env_vars(AUTH_MODE="none"):
|
|
29
28
|
res = app.get(
|
|
30
29
|
f"/messageexchange/{mailbox_id}",
|
|
@@ -54,7 +53,6 @@ def test_handshake_no_auth_mailbox_exists(app: TestClient, mailbox_id: str, acce
|
|
|
54
53
|
],
|
|
55
54
|
)
|
|
56
55
|
def test_handshake_no_auth_mailbox_does_not_exist(app: TestClient, accepts: str):
|
|
57
|
-
|
|
58
56
|
with temp_env_vars(AUTH_MODE="none"):
|
|
59
57
|
res = app.get(
|
|
60
58
|
f"/messageexchange/{uuid4().hex}",
|
|
@@ -70,7 +68,7 @@ def test_handshake_no_auth_mailbox_does_not_exist(app: TestClient, accepts: str)
|
|
|
70
68
|
|
|
71
69
|
|
|
72
70
|
@pytest.mark.parametrize(
|
|
73
|
-
"mailbox_id, accepts",
|
|
71
|
+
("mailbox_id", "accepts"),
|
|
74
72
|
[
|
|
75
73
|
(_CANNED_MAILBOX1, APP_JSON),
|
|
76
74
|
(_CANNED_MAILBOX1, APP_V1_JSON),
|
|
@@ -81,7 +79,6 @@ def test_handshake_no_auth_mailbox_does_not_exist(app: TestClient, accepts: str)
|
|
|
81
79
|
],
|
|
82
80
|
)
|
|
83
81
|
def test_handshake_canned_auth_mailbox_exists(app: TestClient, mailbox_id: str, accepts: str):
|
|
84
|
-
|
|
85
82
|
with temp_env_vars(AUTH_MODE="canned"):
|
|
86
83
|
res = app.get(
|
|
87
84
|
f"/messageexchange/{mailbox_id}",
|
|
@@ -105,7 +102,6 @@ def test_handshake_canned_auth_mailbox_exists(app: TestClient, mailbox_id: str,
|
|
|
105
102
|
|
|
106
103
|
@pytest.mark.parametrize("mailbox_id", [_CANNED_MAILBOX1, _CANNED_MAILBOX2])
|
|
107
104
|
def test_handshake_canned_invalid_auth_mailbox_exists(app: TestClient, mailbox_id: str):
|
|
108
|
-
|
|
109
105
|
with temp_env_vars(AUTH_MODE="canned"):
|
|
110
106
|
res = app.get(
|
|
111
107
|
f"/messageexchange/{mailbox_id}",
|
|
@@ -121,7 +117,7 @@ def test_handshake_canned_invalid_auth_mailbox_exists(app: TestClient, mailbox_i
|
|
|
121
117
|
|
|
122
118
|
|
|
123
119
|
@pytest.mark.parametrize(
|
|
124
|
-
"mailbox_id, accepts",
|
|
120
|
+
("mailbox_id", "accepts"),
|
|
125
121
|
[
|
|
126
122
|
(_CANNED_MAILBOX1, APP_JSON),
|
|
127
123
|
(_CANNED_MAILBOX1, APP_V1_JSON),
|
|
@@ -132,7 +128,6 @@ def test_handshake_canned_invalid_auth_mailbox_exists(app: TestClient, mailbox_i
|
|
|
132
128
|
],
|
|
133
129
|
)
|
|
134
130
|
def test_handshake_full_auth_mailbox_exists(app: TestClient, mailbox_id: str, accepts: str):
|
|
135
|
-
|
|
136
131
|
with temp_env_vars(AUTH_MODE="full"):
|
|
137
132
|
res = app.get(
|
|
138
133
|
f"/messageexchange/{mailbox_id}",
|
|
@@ -155,7 +150,6 @@ def test_handshake_full_auth_mailbox_exists(app: TestClient, mailbox_id: str, ac
|
|
|
155
150
|
|
|
156
151
|
|
|
157
152
|
def test_handshake_full_auth_mailbox_does_not_exist(app: TestClient):
|
|
158
|
-
|
|
159
153
|
mailbox_id = uuid4().hex
|
|
160
154
|
|
|
161
155
|
with temp_env_vars(AUTH_MODE="full"):
|
|
@@ -173,7 +167,6 @@ def test_handshake_full_auth_mailbox_does_not_exist(app: TestClient):
|
|
|
173
167
|
|
|
174
168
|
|
|
175
169
|
def test_handshake_full_auth_mailbox_bad_password(app: TestClient):
|
|
176
|
-
|
|
177
170
|
mailbox_id = uuid4().hex
|
|
178
171
|
|
|
179
172
|
with temp_env_vars(AUTH_MODE="full"):
|
|
@@ -191,7 +184,6 @@ def test_handshake_full_auth_mailbox_bad_password(app: TestClient):
|
|
|
191
184
|
|
|
192
185
|
|
|
193
186
|
def test_handshake_full_auth_mailbox_bad_key(app: TestClient):
|
|
194
|
-
|
|
195
187
|
mailbox_id = uuid4().hex
|
|
196
188
|
|
|
197
189
|
with temp_env_vars(AUTH_MODE="full"):
|
mesh_sandbox/tests/helpers.py
CHANGED
|
@@ -48,7 +48,6 @@ def temp_env_vars(**kwargs):
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
def ensure_client_installed(java_path: str, base_dir: str, version: str): # pylint: disable=too-many-locals
|
|
51
|
-
|
|
52
51
|
install_dir = os.path.join(base_dir, version)
|
|
53
52
|
|
|
54
53
|
client_dir = os.path.join(install_dir, "client")
|
|
@@ -135,7 +134,6 @@ def create_certificate( # pylint: disable=too-many-arguments
|
|
|
135
134
|
serial=0,
|
|
136
135
|
valid_seconds=10 * 365 * 24 * 60 * 60,
|
|
137
136
|
):
|
|
138
|
-
|
|
139
137
|
combined_file = os.path.join(output_dir, f"{common_name}.combined.pem")
|
|
140
138
|
|
|
141
139
|
key = crypto.PKey()
|
|
@@ -184,7 +182,6 @@ def ensure_keystore(base_dir: str) -> str:
|
|
|
184
182
|
|
|
185
183
|
|
|
186
184
|
def ensure_java_client(version: str):
|
|
187
|
-
|
|
188
185
|
java_home = os.environ.get("JAVA_HOME")
|
|
189
186
|
java_path = f"{java_home}/bin/java" if java_home else "java"
|
|
190
187
|
|
mesh_sandbox/tests/inbox.py
CHANGED
|
@@ -17,7 +17,6 @@ _CANNED_MAILBOX2 = "X26ABC2"
|
|
|
17
17
|
|
|
18
18
|
@pytest.mark.parametrize("accept", [APP_V1_JSON, APP_V2_JSON])
|
|
19
19
|
def test_inbox_count(app: TestClient, accept: str):
|
|
20
|
-
|
|
21
20
|
sender = _CANNED_MAILBOX1
|
|
22
21
|
recipient = _CANNED_MAILBOX2
|
|
23
22
|
|
|
@@ -79,7 +78,6 @@ def test_paginated_inbox_outbox(app: TestClient, accept: str):
|
|
|
79
78
|
|
|
80
79
|
message_ids = []
|
|
81
80
|
for _ in range(page_size * 3):
|
|
82
|
-
|
|
83
81
|
resp = mesh_api_send_message(
|
|
84
82
|
app,
|
|
85
83
|
sender_mailbox_id=sender,
|
|
@@ -105,7 +103,6 @@ def test_paginated_inbox_outbox(app: TestClient, accept: str):
|
|
|
105
103
|
assert messages == message_ids[:page_size]
|
|
106
104
|
|
|
107
105
|
if accept == APP_V1_JSON:
|
|
108
|
-
|
|
109
106
|
res = app.get(
|
|
110
107
|
f"/messageexchange/{recipient}/inbox?max_results={page_size}&continue_from={messages[-1]}",
|
|
111
108
|
headers={Headers.Authorization: generate_auth_token(recipient), Headers.Accept: accept},
|
|
@@ -170,9 +167,7 @@ def test_paginated_inbox_outbox(app: TestClient, accept: str):
|
|
|
170
167
|
|
|
171
168
|
|
|
172
169
|
def test_receive_canned_chunked_message(app: TestClient):
|
|
173
|
-
|
|
174
170
|
with temp_env_vars(STORE_MODE="canned"):
|
|
175
|
-
|
|
176
171
|
recipient = _CANNED_MAILBOX2
|
|
177
172
|
|
|
178
173
|
res = app.get(
|
|
@@ -205,9 +200,7 @@ def test_receive_canned_chunked_message(app: TestClient):
|
|
|
205
200
|
|
|
206
201
|
|
|
207
202
|
def test_receive_canned_simple_message(app: TestClient):
|
|
208
|
-
|
|
209
203
|
with temp_env_vars(STORE_MODE="canned"):
|
|
210
|
-
|
|
211
204
|
recipient = _CANNED_MAILBOX1
|
|
212
205
|
|
|
213
206
|
res = app.get(
|
|
@@ -234,12 +227,10 @@ def test_receive_canned_simple_message(app: TestClient):
|
|
|
234
227
|
|
|
235
228
|
@pytest.mark.parametrize("accept", [APP_V1_JSON, APP_V2_JSON])
|
|
236
229
|
def test_receive_canned_undelivered_message(app: TestClient, accept: str):
|
|
237
|
-
|
|
238
230
|
recipient = _CANNED_MAILBOX1
|
|
239
231
|
sender = _CANNED_MAILBOX2
|
|
240
232
|
|
|
241
233
|
with temp_env_vars(STORE_MODE="canned"):
|
|
242
|
-
|
|
243
234
|
res = app.get(
|
|
244
235
|
f"/messageexchange/{recipient}/inbox",
|
|
245
236
|
headers={Headers.Accept: accept, Headers.Authorization: generate_auth_token(recipient)},
|
|
@@ -263,7 +254,6 @@ def test_receive_canned_undelivered_message(app: TestClient, accept: str):
|
|
|
263
254
|
|
|
264
255
|
|
|
265
256
|
def test_rich_inbox_includes_acknowledged_messages(app: TestClient):
|
|
266
|
-
|
|
267
257
|
sender = _CANNED_MAILBOX1
|
|
268
258
|
recipient = _CANNED_MAILBOX2
|
|
269
259
|
|
|
@@ -276,7 +266,6 @@ def test_rich_inbox_includes_acknowledged_messages(app: TestClient):
|
|
|
276
266
|
acknowledged_message_id = ""
|
|
277
267
|
message_ids = []
|
|
278
268
|
for index in range(5):
|
|
279
|
-
|
|
280
269
|
resp = mesh_api_send_message(
|
|
281
270
|
app,
|
|
282
271
|
sender_mailbox_id=sender,
|
|
@@ -320,7 +309,6 @@ def test_rich_inbox_includes_acknowledged_messages(app: TestClient):
|
|
|
320
309
|
|
|
321
310
|
|
|
322
311
|
def test_rich_inbox_returns_most_recent_messages(app: TestClient):
|
|
323
|
-
|
|
324
312
|
sender = _CANNED_MAILBOX1
|
|
325
313
|
recipient = _CANNED_MAILBOX2
|
|
326
314
|
total_messages = 105
|
|
@@ -333,7 +321,6 @@ def test_rich_inbox_returns_most_recent_messages(app: TestClient):
|
|
|
333
321
|
|
|
334
322
|
message_ids = {}
|
|
335
323
|
for index in range(total_messages):
|
|
336
|
-
|
|
337
324
|
resp = mesh_api_send_message(
|
|
338
325
|
app,
|
|
339
326
|
sender_mailbox_id=sender,
|
|
@@ -15,7 +15,6 @@ from .helpers import ensure_java_client
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def configure_client(base_uri: str, version: str):
|
|
18
|
-
|
|
19
18
|
base_dir = ensure_java_client(version)
|
|
20
19
|
|
|
21
20
|
java_client_config_path = f"{base_dir}/client/meshclient.cfg"
|
|
@@ -62,7 +61,6 @@ def configure_client(base_uri: str, version: str):
|
|
|
62
61
|
|
|
63
62
|
|
|
64
63
|
def run_process_and_terminate_after(args: list[str], sleep_for: int = 1):
|
|
65
|
-
|
|
66
64
|
process = subprocess.Popen(args) # pylint: disable=consider-using-with
|
|
67
65
|
# need to hard wait some time for process to start & messages to be sent/received
|
|
68
66
|
# in future we may want to read the log file to determine state
|
|
@@ -80,7 +78,6 @@ def run_process_and_terminate_after(args: list[str], sleep_for: int = 1):
|
|
|
80
78
|
|
|
81
79
|
|
|
82
80
|
def configure_mailboxes(base_dir: str, mailboxes: list[str]):
|
|
83
|
-
|
|
84
81
|
java_client_config_path = f"{base_dir}/client/meshclient.cfg"
|
|
85
82
|
parser = etree.XMLParser(remove_blank_text=True, resolve_entities=False)
|
|
86
83
|
root = cast(_ElementTree, etree.parse(java_client_config_path, parser)).getroot()
|
|
@@ -155,7 +152,6 @@ _CANNED_MAILBOX2 = "X26ABC2"
|
|
|
155
152
|
|
|
156
153
|
|
|
157
154
|
def find_sent_message_id(ctl_file: str) -> str:
|
|
158
|
-
|
|
159
155
|
parser = etree.XMLParser(remove_blank_text=True, resolve_entities=False)
|
|
160
156
|
root = cast(_ElementTree, etree.parse(ctl_file, parser)).getroot()
|
|
161
157
|
message_id = root.find("DTSId")
|
|
@@ -165,14 +161,13 @@ def find_sent_message_id(ctl_file: str) -> str:
|
|
|
165
161
|
|
|
166
162
|
@pytest.mark.parametrize("version", ["6.3.6"])
|
|
167
163
|
def test_basic_send_and_receive(base_uri: str, version: str): # pylint: disable=too-many-locals
|
|
168
|
-
|
|
169
164
|
base_dir, client_args = configure_client(base_uri, version)
|
|
170
165
|
|
|
171
166
|
sender, recipient = _CANNED_MAILBOX1, _CANNED_MAILBOX2
|
|
172
167
|
|
|
173
168
|
configure_mailboxes(base_dir, [sender, recipient])
|
|
174
169
|
|
|
175
|
-
message = f"test-{uuid4().hex}".encode(
|
|
170
|
+
message = f"test-{uuid4().hex}".encode()
|
|
176
171
|
workflow_id = uuid4().hex
|
|
177
172
|
subject = uuid4().hex
|
|
178
173
|
local_id = uuid4().hex
|
mesh_sandbox/tests/lookup.py
CHANGED
|
@@ -13,7 +13,7 @@ _CANNED_MAILBOX3 = "X26ABC3"
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
@pytest.mark.parametrize(
|
|
16
|
-
"workflow_id, ods_code, accepts, expected",
|
|
16
|
+
("workflow_id", "ods_code", "accepts", "expected"),
|
|
17
17
|
[
|
|
18
18
|
("TEST_WORKFLOW", "X26", APP_V1_JSON, {_CANNED_MAILBOX2}),
|
|
19
19
|
("TEST_WORKFLOW", "X26", APP_V2_JSON, {_CANNED_MAILBOX2}),
|
|
@@ -30,7 +30,6 @@ _CANNED_MAILBOX3 = "X26ABC3"
|
|
|
30
30
|
],
|
|
31
31
|
)
|
|
32
32
|
def test_endpoint_lookup(app: TestClient, workflow_id: str, ods_code: str, accepts: str, expected: list[str]):
|
|
33
|
-
|
|
34
33
|
res = app.get(
|
|
35
34
|
f"/messageexchange/endpointlookup/{ods_code}/{workflow_id}",
|
|
36
35
|
headers={Headers.Accept: accepts},
|
|
@@ -49,7 +48,7 @@ def test_endpoint_lookup(app: TestClient, workflow_id: str, ods_code: str, accep
|
|
|
49
48
|
|
|
50
49
|
|
|
51
50
|
@pytest.mark.parametrize(
|
|
52
|
-
"workflow_id, accepts, expected",
|
|
51
|
+
("workflow_id", "accepts", "expected"),
|
|
53
52
|
[
|
|
54
53
|
("TEST_WORKFLOW", APP_V1_JSON, {_CANNED_MAILBOX2}),
|
|
55
54
|
("TEST_WORKFLOW", APP_V2_JSON, {_CANNED_MAILBOX2}),
|
|
@@ -62,7 +61,6 @@ def test_endpoint_lookup(app: TestClient, workflow_id: str, ods_code: str, accep
|
|
|
62
61
|
],
|
|
63
62
|
)
|
|
64
63
|
def test_workflow_search(app: TestClient, workflow_id: str, accepts: str, expected: list[str]):
|
|
65
|
-
|
|
66
64
|
res = app.get(
|
|
67
65
|
f"/messageexchange/workflowsearch/{workflow_id}",
|
|
68
66
|
headers={Headers.Accept: accepts},
|
|
@@ -18,9 +18,8 @@ def mesh_api_send_message(
|
|
|
18
18
|
test_empty_message_data: bool = False,
|
|
19
19
|
file_name: Optional[str] = None,
|
|
20
20
|
):
|
|
21
|
-
|
|
22
21
|
if not test_empty_message_data:
|
|
23
|
-
message_data = message_data or f"Hello World!\n{uuid4().hex}".encode(
|
|
22
|
+
message_data = message_data or f"Hello World!\n{uuid4().hex}".encode()
|
|
24
23
|
|
|
25
24
|
headers = {
|
|
26
25
|
Headers.Mex_From: sender_mailbox_id,
|
|
@@ -48,7 +47,6 @@ def mesh_api_send_message_and_return_message_id(
|
|
|
48
47
|
test_empty_message_data: bool = False,
|
|
49
48
|
file_name: Optional[str] = None,
|
|
50
49
|
):
|
|
51
|
-
|
|
52
50
|
res = mesh_api_send_message(
|
|
53
51
|
app,
|
|
54
52
|
sender_mailbox_id,
|
|
@@ -70,7 +68,6 @@ def mesh_api_get_message(
|
|
|
70
68
|
message_id: str,
|
|
71
69
|
extra_headers: Optional[dict] = None,
|
|
72
70
|
):
|
|
73
|
-
|
|
74
71
|
headers = {Headers.Authorization: generate_auth_token(recipient_mailbox_id)}
|
|
75
72
|
if extra_headers:
|
|
76
73
|
headers.update(extra_headers)
|
|
@@ -83,7 +80,6 @@ def mesh_api_get_inbox(
|
|
|
83
80
|
recipient_mailbox_id: str,
|
|
84
81
|
extra_headers: Optional[dict] = None,
|
|
85
82
|
):
|
|
86
|
-
|
|
87
83
|
headers = {Headers.Authorization: generate_auth_token(recipient_mailbox_id)}
|
|
88
84
|
if extra_headers:
|
|
89
85
|
headers.update(extra_headers)
|
|
@@ -104,7 +100,6 @@ def mesh_api_get_inbox_size(
|
|
|
104
100
|
def mesh_api_track_message_by_local_id(
|
|
105
101
|
app: TestClient, sender_mailbox_id: str, local_id: str, extra_headers: Optional[dict] = None
|
|
106
102
|
):
|
|
107
|
-
|
|
108
103
|
headers = {Headers.Authorization: generate_auth_token(sender_mailbox_id)}
|
|
109
104
|
if extra_headers:
|
|
110
105
|
headers.update(extra_headers)
|
|
@@ -115,7 +110,6 @@ def mesh_api_track_message_by_local_id(
|
|
|
115
110
|
def mesh_api_track_message_by_message_id(
|
|
116
111
|
app: TestClient, sender_mailbox_id: str, message_id: str, extra_headers: Optional[dict] = None
|
|
117
112
|
):
|
|
118
|
-
|
|
119
113
|
headers = {Headers.Authorization: generate_auth_token(sender_mailbox_id)}
|
|
120
114
|
if extra_headers:
|
|
121
115
|
headers.update(extra_headers)
|
|
@@ -127,6 +121,5 @@ def mesh_api_track_message_by_message_id(
|
|
|
127
121
|
def mesh_api_track_message_by_message_id_status(
|
|
128
122
|
app: TestClient, sender_mailbox_id: str, message_id: str, extra_headers: Optional[dict] = None
|
|
129
123
|
):
|
|
130
|
-
|
|
131
124
|
res = mesh_api_track_message_by_message_id(app, sender_mailbox_id, message_id, extra_headers=extra_headers)
|
|
132
125
|
return res.status_code
|