Skip to content

Commit 8135c04

Browse files
committed
Bumped kafka-python to 2.3.0 and test dependencies. Added unit tests for JSON deserialization logic.
1 parent 8ec7b89 commit 8135c04

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

requirements-dev.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pytest==8.4.1
2-
pytest-cov==6.2.1
3-
coverage==7.10.6
4-
testcontainers[kafka]==4.12.0
1+
pytest==8.4.2
2+
pytest-cov==6.3.0
3+
coverage==7.10.7
4+
testcontainers[kafka]==4.13.3

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
kafka-python==2.2.15
1+
kafka-python==2.2.18
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import json
2+
3+
4+
def test_json_deserializer_valid():
5+
from serialization.json_format import json_deserializer
6+
7+
data = {"a": 1, "b": "text"}
8+
raw = json.dumps(data).encode("utf-8")
9+
10+
result = json_deserializer(raw)
11+
12+
assert result == data
13+
14+
15+
def test_json_or_text_deserializer_json_ok():
16+
from serialization.json_format import json_or_text_deserializer
17+
18+
payload = {"x": 123}
19+
raw = json.dumps(payload).encode("utf-8")
20+
21+
out = json_or_text_deserializer(raw)
22+
23+
assert out == payload
24+
assert isinstance(out, dict)
25+
26+
27+
def test_json_or_text_deserializer_invalid_json_falls_back_to_text():
28+
from serialization.json_format import json_or_text_deserializer
29+
30+
raw = b"this is not json"
31+
32+
out = json_or_text_deserializer(raw)
33+
34+
assert out == "this is not json"
35+
assert isinstance(out, str)
36+
37+
38+
def test_json_or_text_deserializer_invalid_utf8_replaced():
39+
from serialization.json_format import json_or_text_deserializer
40+
41+
raw = b"\xff\xfe\xfd" # invalid UTF-8
42+
43+
out = json_or_text_deserializer(raw)
44+
45+
# Should decode with replacement characters via plain_text_deserializer
46+
assert isinstance(out, str)
47+
assert "\ufffd" in out or "�" in out

0 commit comments

Comments
 (0)