Skip to content

Commit 42fccd4

Browse files
committed
more tests
1 parent 09f0a93 commit 42fccd4

File tree

1 file changed

+60
-10
lines changed

1 file changed

+60
-10
lines changed

tests/test_utils.py

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,92 @@
1-
from unittest.mock import Mock
1+
from unittest.mock import Mock, patch
22

33
import pytest
44

5-
from saluki.utils import parse_kafka_uri, _parse_timestamp, _deserialise_and_print_messages
5+
from saluki.utils import (
6+
parse_kafka_uri,
7+
_parse_timestamp,
8+
_deserialise_and_print_messages,
9+
__try_to_deserialise_message,
10+
)
611
from confluent_kafka import Message
712

13+
814
@pytest.fixture
915
def mock_message():
1016
return Mock(spec=Message)
1117

12-
def test_deserialising_message_with_no_message_continues(mock_message):
13-
_deserialise_and_print_messages([mock_message])
18+
19+
def test_deserialising_message_with_no_message_continues():
20+
with patch("saluki.utils.__try_to_deserialise_message") as mock_deserialise_message:
21+
_deserialise_and_print_messages([None], None)
22+
mock_deserialise_message.assert_not_called()
23+
1424

1525
def test_deserialising_message_with_error_continues(mock_message):
16-
pass
26+
mock_message.error.return_value = "Some error"
27+
with patch("saluki.utils.__try_to_deserialise_message") as mock_deserialise_message:
28+
_deserialise_and_print_messages([mock_message], None)
29+
mock_deserialise_message.assert_not_called()
30+
1731

1832
def test_deserialising_message_with_wrong_partition_continues(mock_message):
33+
noninteresting_partition = 123
34+
mock_message.error.return_value = False
35+
mock_message.partition.return_value = noninteresting_partition
36+
with patch("saluki.utils.__try_to_deserialise_message") as mock_deserialise_message:
37+
_deserialise_and_print_messages([mock_message], 234)
38+
mock_deserialise_message.assert_not_called()
39+
40+
41+
def test_deserialising_message_with_correct_partition_calls_deserialise(mock_message):
42+
partition = 123
43+
mock_message.error.return_value = False
44+
mock_message.partition.return_value = partition
45+
with patch("saluki.utils.__try_to_deserialise_message") as mock_deserialise_message:
46+
_deserialise_and_print_messages([mock_message], partition)
47+
mock_deserialise_message.assert_called_once()
48+
49+
50+
def test_deserialising_empty_message(mock_message):
51+
assert (None, "") == __try_to_deserialise_message(b"")
52+
53+
54+
def test_deserialising_message_with_invalid_schema_falls_back_to_raw_bytes_decode(
55+
mock_message,
56+
):
1957
pass
2058

2159

60+
def test_deserialising_message_which_raises_does_not_stop_loop(mock_message):
61+
pass
62+
63+
64+
def test_schema_that_isnt_in_deserialiser_list(mock_message):
65+
pass
2266

23-
# test with normal payload
2467

25-
# test with fallback serialiser when schema not found (empty payload)
68+
def test_message_that_has_valid_schema_but_empty_payload(mock_message):
69+
pass
2670

27-
# test with schema that looks ok, but not in list of deserialisers
2871

29-
# test exception while deserialising
72+
def test_message_that_has_valid_schema_but_invalid_payload(mock_message):
73+
pass
74+
75+
76+
def test_message_that_has_valid_schema_and_valid_payload(mock_message):
77+
pass
3078

3179

3280
def test_parse_timestamp_with_valid_timestamp(mock_message):
3381
mock_message.timestamp.return_value = (1, 1753434939336)
34-
assert _parse_timestamp(mock_message) == '2025-07-25 10:15:39.336000'
82+
assert _parse_timestamp(mock_message) == "2025-07-25 10:15:39.336000"
83+
3584

3685
def test_parse_timestamp_with_timestamp_not_available(mock_message):
3786
mock_message.timestamp.return_value = (2, "blah")
3887
assert _parse_timestamp(mock_message) == "Unknown"
3988

89+
4090
def test_uri_with_broker_name_and_topic_successfully_split():
4191
test_broker = "localhost"
4292
test_topic = "some_topic"

0 commit comments

Comments
 (0)