refactor: decompose scholars service and pdf_queue into focused modules
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8c6069c121
commit
b701583716
10 changed files with 1592 additions and 1443 deletions
|
|
@ -6,7 +6,7 @@ from types import SimpleNamespace
|
|||
import pytest
|
||||
|
||||
from app.db.models import PublicationPdfJob
|
||||
from app.services.publications import pdf_queue
|
||||
from app.services.publications import pdf_queue, pdf_queue_resolution
|
||||
from app.services.publications.pdf_resolution_pipeline import PipelineOutcome
|
||||
from app.services.unpaywall.application import OaResolutionOutcome
|
||||
|
||||
|
|
@ -150,9 +150,9 @@ async def test_fetch_outcome_for_row_uses_pipeline_outcome(monkeypatch: pytest.M
|
|||
scholar_candidates=None,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(pdf_queue, "resolve_publication_pdf_outcome_for_row", _fake_pipeline)
|
||||
monkeypatch.setattr(pdf_queue_resolution, "resolve_publication_pdf_outcome_for_row", _fake_pipeline)
|
||||
|
||||
outcome, arxiv_rate_limited = await pdf_queue._fetch_outcome_for_row(
|
||||
outcome, arxiv_rate_limited = await pdf_queue_resolution._fetch_outcome_for_row(
|
||||
row=_row(),
|
||||
request_email="user@example.com",
|
||||
)
|
||||
|
|
@ -172,15 +172,15 @@ async def test_fetch_outcome_for_row_returns_failed_outcome_when_pipeline_return
|
|||
assert allow_arxiv_lookup is True
|
||||
return PipelineOutcome(outcome=None, scholar_candidates=None, arxiv_rate_limited=True)
|
||||
|
||||
monkeypatch.setattr(pdf_queue, "resolve_publication_pdf_outcome_for_row", _fake_pipeline)
|
||||
monkeypatch.setattr(pdf_queue_resolution, "resolve_publication_pdf_outcome_for_row", _fake_pipeline)
|
||||
|
||||
outcome, arxiv_rate_limited = await pdf_queue._fetch_outcome_for_row(
|
||||
outcome, arxiv_rate_limited = await pdf_queue_resolution._fetch_outcome_for_row(
|
||||
row=_row(),
|
||||
request_email="user@example.com",
|
||||
)
|
||||
|
||||
assert outcome.pdf_url is None
|
||||
assert outcome.failure_reason == pdf_queue.FAILURE_RESOLUTION_EXCEPTION
|
||||
assert outcome.failure_reason == pdf_queue_resolution.FAILURE_RESOLUTION_EXCEPTION
|
||||
assert arxiv_rate_limited is True
|
||||
|
||||
|
||||
|
|
@ -210,11 +210,11 @@ async def test_resolve_publication_row_persists_outcome_and_returns_rate_limit_f
|
|||
async def _capture_persist_outcome(*, publication_id: int, user_id: int, outcome: OaResolutionOutcome) -> None:
|
||||
captured.append((publication_id, user_id, outcome))
|
||||
|
||||
monkeypatch.setattr(pdf_queue, "_mark_attempt_started", _noop_mark_attempt_started)
|
||||
monkeypatch.setattr(pdf_queue, "_fetch_outcome_for_row", _fake_fetch)
|
||||
monkeypatch.setattr(pdf_queue, "_persist_outcome", _capture_persist_outcome)
|
||||
monkeypatch.setattr(pdf_queue_resolution, "_mark_attempt_started", _noop_mark_attempt_started)
|
||||
monkeypatch.setattr(pdf_queue_resolution, "_fetch_outcome_for_row", _fake_fetch)
|
||||
monkeypatch.setattr(pdf_queue_resolution, "_persist_outcome", _capture_persist_outcome)
|
||||
|
||||
rate_limited = await pdf_queue._resolve_publication_row(
|
||||
rate_limited = await pdf_queue_resolution._resolve_publication_row(
|
||||
user_id=42,
|
||||
request_email="user@example.com",
|
||||
row=_row(),
|
||||
|
|
@ -252,10 +252,10 @@ async def test_run_resolution_task_disables_arxiv_for_remaining_batch(
|
|||
calls.append((int(row.publication_id), bool(allow_arxiv_lookup)))
|
||||
return row.publication_id == 1
|
||||
|
||||
monkeypatch.setattr(pdf_queue, "get_session_factory", _raise_session_factory_error)
|
||||
monkeypatch.setattr(pdf_queue, "_resolve_publication_row", _fake_resolve_publication_row)
|
||||
monkeypatch.setattr(pdf_queue_resolution, "get_session_factory", _raise_session_factory_error)
|
||||
monkeypatch.setattr(pdf_queue_resolution, "_resolve_publication_row", _fake_resolve_publication_row)
|
||||
|
||||
await pdf_queue._run_resolution_task(
|
||||
await pdf_queue_resolution._run_resolution_task(
|
||||
user_id=42,
|
||||
request_email="user@example.com",
|
||||
rows=[first, second],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue