Document task DB access and unify background task DB handling
This commit is contained in:
@@ -70,6 +70,7 @@ def _make_app(
|
||||
app.state.db = db
|
||||
app.state.http_session = http_session
|
||||
app.state.settings = MagicMock(database_path="/tmp/fake.db")
|
||||
app.state.runtime_settings = None
|
||||
|
||||
return app
|
||||
|
||||
@@ -80,7 +81,7 @@ async def test_run_re_resolve_no_unresolved_ips_skips() -> None:
|
||||
app = _make_app(unresolved_ips=[])
|
||||
|
||||
with patch(
|
||||
"app.tasks.geo_re_resolve.open_db",
|
||||
"app.tasks.db.open_db",
|
||||
new_callable=AsyncMock,
|
||||
return_value=app.state.db,
|
||||
), patch("app.tasks.geo_re_resolve.geo_service") as mock_geo:
|
||||
@@ -104,6 +105,7 @@ async def test_run_re_resolve_clears_neg_cache() -> None:
|
||||
|
||||
with patch("app.tasks.geo_re_resolve.geo_service") as mock_geo:
|
||||
mock_geo.get_unresolved_ips = AsyncMock(return_value=ips)
|
||||
mock_geo.clear_neg_cache = AsyncMock()
|
||||
mock_geo.lookup_batch = AsyncMock(return_value=result)
|
||||
|
||||
await _run_re_resolve(app)
|
||||
@@ -122,11 +124,12 @@ async def test_run_re_resolve_calls_lookup_batch_with_db() -> None:
|
||||
app = _make_app(unresolved_ips=ips, lookup_result=result)
|
||||
|
||||
with patch(
|
||||
"app.tasks.geo_re_resolve.open_db",
|
||||
"app.tasks.db.open_db",
|
||||
new_callable=AsyncMock,
|
||||
return_value=app.state.db,
|
||||
), patch("app.tasks.geo_re_resolve.geo_service") as mock_geo:
|
||||
mock_geo.get_unresolved_ips = AsyncMock(return_value=ips)
|
||||
mock_geo.clear_neg_cache = AsyncMock()
|
||||
mock_geo.lookup_batch = AsyncMock(return_value=result)
|
||||
|
||||
await _run_re_resolve(app)
|
||||
@@ -150,11 +153,12 @@ async def test_run_re_resolve_logs_correct_counts(caplog: Any) -> None:
|
||||
app = _make_app(unresolved_ips=ips, lookup_result=result)
|
||||
|
||||
with patch(
|
||||
"app.tasks.geo_re_resolve.open_db",
|
||||
"app.tasks.db.open_db",
|
||||
new_callable=AsyncMock,
|
||||
return_value=app.state.db,
|
||||
), patch("app.tasks.geo_re_resolve.geo_service") as mock_geo:
|
||||
mock_geo.get_unresolved_ips = AsyncMock(return_value=ips)
|
||||
mock_geo.clear_neg_cache = AsyncMock()
|
||||
mock_geo.lookup_batch = AsyncMock(return_value=result)
|
||||
|
||||
await _run_re_resolve(app)
|
||||
@@ -177,11 +181,12 @@ async def test_run_re_resolve_handles_all_resolved() -> None:
|
||||
app = _make_app(unresolved_ips=ips, lookup_result=result)
|
||||
|
||||
with patch(
|
||||
"app.tasks.geo_re_resolve.open_db",
|
||||
"app.tasks.db.open_db",
|
||||
new_callable=AsyncMock,
|
||||
return_value=app.state.db,
|
||||
), patch("app.tasks.geo_re_resolve.geo_service") as mock_geo:
|
||||
mock_geo.get_unresolved_ips = AsyncMock(return_value=ips)
|
||||
mock_geo.clear_neg_cache = AsyncMock()
|
||||
mock_geo.lookup_batch = AsyncMock(return_value=result)
|
||||
|
||||
await _run_re_resolve(app)
|
||||
|
||||
Reference in New Issue
Block a user