Files
FabledCurator/tests/test_api_sources_check.py
T
bvandeusen def967a1a8 refactor(dry-S1): hoist app/client test fixtures into conftest
Removed the app/client fixtures duplicated across 36 test files (two
variants: separate app + client(app), and a self-contained client() that
called create_app inline) and the now-unused create_app imports. Both
fixtures now live once in conftest.py. test_suggestions_bulk keeps its
import (builds the app inline in two tests); test_health drops its local
client + unused pytest_asyncio.

Net -415 lines.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 11:33:05 -04:00

66 lines
1.9 KiB
Python

import pytest
from backend.app.models import Artist, DownloadEvent, Source
pytestmark = pytest.mark.integration
@pytest.fixture
async def seed(db):
artist = Artist(name="Alice", slug="alice")
db.add(artist)
await db.flush()
source = Source(
artist_id=artist.id, platform="patreon",
url="https://patreon.com/alice", enabled=True,
config_overrides={},
)
db.add(source)
await db.commit()
return source
@pytest.mark.asyncio
async def test_check_202_creates_pending_event(client, seed, monkeypatch):
monkeypatch.setattr(
"backend.app.tasks.download.download_source.delay",
lambda *a, **k: None,
)
resp = await client.post(f"/api/sources/{seed.id}/check")
assert resp.status_code == 202
body = await resp.get_json()
assert body["status"] == "pending"
assert isinstance(body["download_event_id"], int)
@pytest.mark.asyncio
async def test_check_404_for_unknown_source(client):
resp = await client.post("/api/sources/99999/check")
assert resp.status_code == 404
@pytest.mark.asyncio
async def test_check_400_for_disabled_source(client, db, seed):
seed.enabled = False
await db.commit()
resp = await client.post(f"/api/sources/{seed.id}/check")
assert resp.status_code == 400
body = await resp.get_json()
assert body["error"] == "source_disabled"
@pytest.mark.asyncio
async def test_check_409_when_already_running(client, db, seed, monkeypatch):
monkeypatch.setattr(
"backend.app.tasks.download.download_source.delay",
lambda *a, **k: None,
)
existing = DownloadEvent(source_id=seed.id, status="running")
db.add(existing)
await db.commit()
await db.refresh(existing)
resp = await client.post(f"/api/sources/{seed.id}/check")
assert resp.status_code == 409
body = await resp.get_json()
assert body["download_event_id"] == existing.id