Refactor history sync into history_service and update docs/tests
This commit is contained in:
@@ -31,35 +31,26 @@ class TestHistorySyncTask:
|
||||
async def test_backfill_window_is_7_5_days(self) -> None:
|
||||
assert history_sync.BACKFILL_WINDOW == 648000
|
||||
|
||||
async def test_sync_uses_strict_since_after_restart(self) -> None:
|
||||
async def test_run_sync_delegates_to_history_service(self) -> None:
|
||||
fake_app = type("FakeApp", (), {})()
|
||||
fake_app.state = type("FakeState", (), {})()
|
||||
fake_app.state.settings = type("FakeSettings", (), {})()
|
||||
fake_app.state.settings.fail2ban_socket = "/tmp/fake.sock"
|
||||
fake_app.state.settings.database_path = "/tmp/fake.db"
|
||||
|
||||
fake_app.state.db = MagicMock()
|
||||
fake_app.state.db.close = AsyncMock()
|
||||
|
||||
async def fake_get_history_page(*, db_path: str, since: int, page: int, page_size: int, **kwargs):
|
||||
assert since == 1001
|
||||
return [], 0
|
||||
|
||||
async def fake_get_fail2ban_db_path(socket_path: str) -> str:
|
||||
return "/tmp/fake.sqlite3"
|
||||
fake_db = AsyncMock()
|
||||
fake_db.close = AsyncMock()
|
||||
|
||||
with patch(
|
||||
"app.tasks.history_sync.open_db",
|
||||
new_callable=AsyncMock,
|
||||
return_value=fake_app.state.db,
|
||||
return_value=fake_db,
|
||||
), patch(
|
||||
"app.tasks.history_sync._get_last_archive_ts",
|
||||
new=AsyncMock(return_value=1000),
|
||||
), patch(
|
||||
"app.tasks.history_sync.get_fail2ban_db_path",
|
||||
new=fake_get_fail2ban_db_path,
|
||||
), patch(
|
||||
"app.tasks.history_sync.fail2ban_db_repo.get_history_page",
|
||||
new=fake_get_history_page,
|
||||
):
|
||||
"app.tasks.history_sync.history_service.sync_from_fail2ban_db",
|
||||
new_callable=AsyncMock,
|
||||
return_value=42,
|
||||
) as mock_sync:
|
||||
await history_sync._run_sync(fake_app)
|
||||
|
||||
mock_sync.assert_awaited_once_with(fake_db, "/tmp/fake.sock")
|
||||
fake_db.close.assert_awaited_once()
|
||||
|
||||
Reference in New Issue
Block a user