-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_jsonlines.py
51 lines (44 loc) · 1.29 KB
/
test_jsonlines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations
from unittest import mock
from workflows.recipe.wrapper import RecipeWrapper
from workflows.transport.offline_transport import OfflineTransport
from zocalo.service.jsonlines import JSONLines
def test_jsonlines(tmp_path):
output_file = tmp_path / "foo.json"
message = {
"recipe": {
"1": {
"parameters": {
"output_filename": str(output_file),
"include": ["ham", "spam", "bar"],
"exclude": ["bar"],
},
},
},
"recipe-pointer": 1,
}
header = {
"message-id": mock.sentinel,
"subscription": mock.sentinel,
}
t = OfflineTransport()
rw = RecipeWrapper(message=message, transport=t)
jsonlines = JSONLines()
jsonlines.transport = t
jsonlines.start()
messages = [
{"foo": "bar", "ham": 1, "spam": 2, "bar": "foo"},
{"foo": "bar", "ham": 2, "spam": 3, "bar": "foo"},
]
for msg in messages:
jsonlines.receive_msg(rw, header, msg)
# This would normally be called internally by the service
jsonlines.process_messages()
content = output_file.read_text()
assert (
content
== """\
{"ham": 1, "spam": 2}
{"ham": 2, "spam": 3}
"""
)