Skip to content

Commit 7f365db

Browse files
add tests
1 parent 00dfe09 commit 7f365db

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def __init__(self, *topics, hostname=None, port=None):
1212
self.port = port
1313
self._closed = False
1414
self._callbacks = {}
15+
self._consumer_task = None # Added for consumer task tracking
1516

1617
def add_n_topics(self, topics, bind=None):
1718
"""Mock add_n_topics method."""

tests/test_clickhouse_service.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,59 @@ def test_connect(self, mock_clickhouse_client):
3939

4040
assert service.client == mock_clickhouse_client
4141

42+
def test_write_data(self, clickhouse_service, mock_clickhouse_client):
43+
"""Test writing a single ProcessedLatency record to ClickHouse."""
44+
# Prepare test data
45+
test_data = {
46+
'window_start_time': datetime(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc),
47+
'window_end_time': datetime(2024, 1, 1, 12, 5, 0, tzinfo=timezone.utc),
48+
'window_duration_seconds': 300.0,
49+
'cell_index': 1,
50+
'network': '5G',
51+
'rsrp_mean': -80.0,
52+
'rsrp_max': -70.0,
53+
'rsrp_min': -90.0,
54+
'rsrp_std': 5.0,
55+
'sinr_mean': 15.0,
56+
'sinr_max': 20.0,
57+
'sinr_min': 10.0,
58+
'sinr_std': 3.0,
59+
'rsrq_mean': -10.0,
60+
'rsrq_max': -8.0,
61+
'rsrq_min': -12.0,
62+
'rsrq_std': 1.5,
63+
'latency_mean': 20.0,
64+
'latency_max': 30.0,
65+
'latency_min': 10.0,
66+
'latency_std': 5.0,
67+
'cqi_mean': 12.0,
68+
'cqi_max': 15.0,
69+
'cqi_min': 10.0,
70+
'cqi_std': 2.0,
71+
'primary_bandwidth': 100.0,
72+
'ul_bandwidth': 50.0,
73+
'sample_count': 100
74+
}
75+
76+
# Execute write
77+
clickhouse_service.write_data(test_data)
78+
79+
# Verify insert was called with correct parameters
80+
mock_clickhouse_client.insert.assert_called_once()
81+
call_args = mock_clickhouse_client.insert.call_args
82+
83+
# Check table name
84+
assert call_args[0][0] == 'analytics.processed_latency'
85+
86+
# Check data format (should be a list with one dict)
87+
assert isinstance(call_args[0][1], list)
88+
assert len(call_args[0][1]) == 1
89+
90+
# Check async insert settings
91+
assert call_args[1]['settings']['async_insert'] == 1
92+
assert call_args[1]['settings']['wait_for_async_insert'] == 0
93+
94+
4295
def test_query_processed_latency_success(self, clickhouse_service, mock_clickhouse_client):
4396
"""Test successful query of processed latency data."""
4497
# Mock query result

0 commit comments

Comments
 (0)