Fix date-dependent storage tests (use now-relative timestamps)

This commit is contained in:
2026-09-03 11:57:49 +03:00
parent 0296ea501f
commit 00cd64377a
+6 -5
View File
@@ -108,14 +108,15 @@ def test_save_and_get_latest_model_metrics(tmp_path) -> None:
def test_history_upsert_same_day(tmp_path) -> None: def test_history_upsert_same_day(tmp_path) -> None:
storage = Storage(tmp_path / "cache.db") storage = Storage(tmp_path / "cache.db")
timestamp = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=1)
point = HistoryPoint( point = HistoryPoint(
timestamp=dt.datetime(2026, 8, 1, 12, 0), timestamp=timestamp,
amount_rub=Decimal("10.00"), amount_rub=Decimal("10.00"),
tokens=TokenUsage(input_tokens=5), tokens=TokenUsage(input_tokens=5),
) )
storage.save_history(point) storage.save_history(point)
point2 = HistoryPoint( point2 = HistoryPoint(
timestamp=dt.datetime(2026, 8, 1, 12, 0), timestamp=timestamp,
amount_rub=Decimal("15.00"), amount_rub=Decimal("15.00"),
tokens=TokenUsage(input_tokens=8), tokens=TokenUsage(input_tokens=8),
) )
@@ -151,7 +152,7 @@ def test_save_snapshot_combined(tmp_path) -> None:
metrics=_metrics(), metrics=_metrics(),
models=_models(), models=_models(),
history_point=HistoryPoint( history_point=HistoryPoint(
timestamp=dt.datetime(2026, 8, 1, 12, 0), timestamp=dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=1),
amount_rub=Decimal("854.83"), amount_rub=Decimal("854.83"),
tokens=TokenUsage(input_tokens=100), tokens=TokenUsage(input_tokens=100),
), ),
@@ -225,7 +226,7 @@ def test_clear_removes_all_rows(tmp_path) -> None:
storage = Storage(tmp_path / "cache.db") storage = Storage(tmp_path / "cache.db")
storage.save_history( storage.save_history(
HistoryPoint( HistoryPoint(
timestamp=dt.datetime(2026, 8, 18), timestamp=dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=1),
amount_rub=Decimal("1"), amount_rub=Decimal("1"),
tokens=TokenUsage(input_tokens=1), tokens=TokenUsage(input_tokens=1),
) )
@@ -235,4 +236,4 @@ def test_clear_removes_all_rows(tmp_path) -> None:
deleted = storage.clear() deleted = storage.clear()
assert deleted >= 1 assert deleted >= 1
assert storage.get_history() == [] assert storage.get_history() == []
assert storage.get_latest_consumption() is None assert storage.get_latest_consumption() is None