68 lines
1.7 KiB
Python
68 lines
1.7 KiB
Python
import asyncio
|
|
from datetime import datetime, timezone
|
|
|
|
from app.infra.db.timescaledb.repositories.realtime import RealtimeRepository
|
|
|
|
|
|
class _FakeCursor:
|
|
def __init__(self):
|
|
self.calls: list[tuple[str, tuple]] = []
|
|
|
|
async def __aenter__(self):
|
|
return self
|
|
|
|
async def __aexit__(self, exc_type, exc, tb):
|
|
return False
|
|
|
|
async def execute(self, query, params):
|
|
self.calls.append((str(query), params))
|
|
|
|
async def fetchall(self):
|
|
return []
|
|
|
|
|
|
class _FakeConnection:
|
|
def __init__(self):
|
|
self.cursor_instance = _FakeCursor()
|
|
|
|
def cursor(self):
|
|
return self.cursor_instance
|
|
|
|
|
|
def test_get_links_by_time_range_normalizes_inputs_to_utc():
|
|
conn = _FakeConnection()
|
|
|
|
asyncio.run(
|
|
RealtimeRepository.get_links_by_time_range(
|
|
conn,
|
|
datetime.fromisoformat("2026-06-01T08:00:00+08:00"),
|
|
datetime.fromisoformat("2026-06-01T09:00:00+08:00"),
|
|
)
|
|
)
|
|
|
|
assert len(conn.cursor_instance.calls) == 1
|
|
_, params = conn.cursor_instance.calls[0]
|
|
assert params == (
|
|
datetime(2026, 6, 1, 0, 0, tzinfo=timezone.utc),
|
|
datetime(2026, 6, 1, 1, 0, tzinfo=timezone.utc),
|
|
)
|
|
|
|
|
|
def test_get_nodes_by_time_range_normalizes_inputs_to_utc():
|
|
conn = _FakeConnection()
|
|
|
|
asyncio.run(
|
|
RealtimeRepository.get_nodes_by_time_range(
|
|
conn,
|
|
datetime.fromisoformat("2026-06-01T08:00:00+08:00"),
|
|
datetime.fromisoformat("2026-06-01T09:00:00+08:00"),
|
|
)
|
|
)
|
|
|
|
assert len(conn.cursor_instance.calls) == 1
|
|
_, params = conn.cursor_instance.calls[0]
|
|
assert params == (
|
|
datetime(2026, 6, 1, 0, 0, tzinfo=timezone.utc),
|
|
datetime(2026, 6, 1, 1, 0, tzinfo=timezone.utc),
|
|
)
|