s
This commit is contained in:
parent
5499904cef
commit
1c01b29be7
31 changed files with 1725 additions and 53 deletions
|
|
@ -1,11 +1,14 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from app.db.models import PublicationPdfJob
|
||||
from app.services.domains.publications import pdf_queue
|
||||
from app.services.domains.publications.pdf_resolution_pipeline import PipelineOutcome
|
||||
from app.services.domains.unpaywall.application import OaResolutionOutcome
|
||||
|
||||
|
||||
def _job(
|
||||
|
|
@ -22,6 +25,25 @@ def _job(
|
|||
)
|
||||
|
||||
|
||||
def _row(*, pub_url: str | None = "https://scholar.google.com/citations?view_op=view_citation&citation_for_view=abc:xyz") -> SimpleNamespace:
|
||||
return SimpleNamespace(
|
||||
publication_id=1,
|
||||
scholar_profile_id=1,
|
||||
scholar_label="Ada Lovelace",
|
||||
title="A paper",
|
||||
year=2024,
|
||||
citation_count=0,
|
||||
venue_text=None,
|
||||
pub_url=pub_url,
|
||||
doi=None,
|
||||
pdf_url=None,
|
||||
is_read=False,
|
||||
is_favorite=False,
|
||||
first_seen_at=datetime(2026, 2, 22, 12, 0, tzinfo=timezone.utc),
|
||||
is_new_in_latest_run=True,
|
||||
)
|
||||
|
||||
|
||||
def test_pdf_queue_auto_enqueue_blocks_recent_attempt(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
now = datetime(2026, 2, 21, 12, 0, tzinfo=timezone.utc)
|
||||
monkeypatch.setattr(pdf_queue, "_utcnow", lambda: now)
|
||||
|
|
@ -107,3 +129,44 @@ def test_pdf_queue_manual_requeue_still_blocks_when_inflight() -> None:
|
|||
)
|
||||
assert pdf_queue._can_enqueue_job(running, force_retry=True) is False
|
||||
assert pdf_queue._can_enqueue_job(queued, force_retry=True) is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fetch_outcome_for_row_uses_pipeline_outcome(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
async def _fake_pipeline(*, row, request_email=None):
|
||||
assert request_email == "user@example.com"
|
||||
return PipelineOutcome(
|
||||
outcome=OaResolutionOutcome(
|
||||
publication_id=row.publication_id,
|
||||
doi=None,
|
||||
pdf_url="https://arxiv.org/pdf/1703.06103",
|
||||
failure_reason=None,
|
||||
source=pdf_queue.PDF_SOURCE_SCHOLAR_PUBLICATION_PAGE,
|
||||
used_crossref=False,
|
||||
),
|
||||
scholar_candidates=None,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(pdf_queue, "resolve_publication_pdf_outcome_for_row", _fake_pipeline)
|
||||
|
||||
outcome = await pdf_queue._fetch_outcome_for_row(row=_row(), request_email="user@example.com")
|
||||
|
||||
assert outcome.pdf_url == "https://arxiv.org/pdf/1703.06103"
|
||||
assert outcome.source == pdf_queue.PDF_SOURCE_SCHOLAR_PUBLICATION_PAGE
|
||||
assert outcome.used_crossref is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fetch_outcome_for_row_returns_failed_outcome_when_pipeline_returns_none(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
async def _fake_pipeline(*, row, request_email=None):
|
||||
assert request_email == "user@example.com"
|
||||
return PipelineOutcome(outcome=None, scholar_candidates=None)
|
||||
|
||||
monkeypatch.setattr(pdf_queue, "resolve_publication_pdf_outcome_for_row", _fake_pipeline)
|
||||
|
||||
outcome = await pdf_queue._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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue