Move history archive max timestamp query into repository

This commit is contained in:
2026-04-15 21:18:44 +02:00
parent cdb0c3681e
commit 56f03f39c7
4 changed files with 38 additions and 7 deletions

View File

@@ -9,7 +9,12 @@ import aiosqlite
import pytest
from app.db import init_db
from app.repositories.history_archive_repo import archive_ban_event, get_archived_history, purge_archived_history
from app.repositories.history_archive_repo import (
archive_ban_event,
get_archived_history,
get_max_timeofban,
purge_archived_history,
)
@pytest.fixture
@@ -52,6 +57,25 @@ async def test_get_archived_history_filtering_and_pagination(app_db: str) -> Non
assert rows[0]["ip"] == "2.2.2.2"
@pytest.mark.asyncio
async def test_get_max_timeofban_returns_latest_timestamp(app_db: str) -> None:
async with aiosqlite.connect(app_db) as db:
await archive_ban_event(db, "sshd", "1.1.1.1", 1000, 1, "{}", "ban")
await archive_ban_event(db, "sshd", "1.1.1.2", 2000, 1, "{}", "ban")
max_ts = await get_max_timeofban(db)
assert max_ts == 2000
@pytest.mark.asyncio
async def test_get_max_timeofban_returns_none_for_empty_archive(app_db: str) -> None:
async with aiosqlite.connect(app_db) as db:
max_ts = await get_max_timeofban(db)
assert max_ts is None
@pytest.mark.asyncio
async def test_purge_archived_history(app_db: str) -> None:
now = int(time.time())