feat(attachments): importer dispatch — archive extract + non-media capture
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""FC-2d-iii: loose non-media → PostAttachment (no skip)."""
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from backend.app.models import Artist, ImportSettings, PostAttachment
|
||||
from backend.app.services.importer import Importer
|
||||
from backend.app.services.thumbnailer import Thumbnailer
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def import_layout(tmp_path):
|
||||
import_root = tmp_path / "import"
|
||||
images_root = tmp_path / "images"
|
||||
import_root.mkdir()
|
||||
images_root.mkdir()
|
||||
return import_root, images_root
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def importer(db_sync, import_layout):
|
||||
import_root, images_root = import_layout
|
||||
settings = db_sync.execute(
|
||||
select(ImportSettings).where(ImportSettings.id == 1)
|
||||
).scalar_one()
|
||||
return Importer(
|
||||
session=db_sync, images_root=images_root, import_root=import_root,
|
||||
thumbnailer=Thumbnailer(images_root=images_root), settings=settings,
|
||||
)
|
||||
|
||||
|
||||
def test_loose_non_media_becomes_attachment(importer, import_layout):
|
||||
import_root, _ = import_layout
|
||||
f = import_root / "Alice" / "manifesto.pdf"
|
||||
f.parent.mkdir(parents=True, exist_ok=True)
|
||||
f.write_bytes(b"%PDF-1.4 stuff")
|
||||
r = importer.import_one(f)
|
||||
assert r.status == "attached"
|
||||
att = importer.session.execute(select(PostAttachment)).scalar_one()
|
||||
artist = importer.session.execute(
|
||||
select(Artist).where(Artist.slug == "alice")
|
||||
).scalar_one()
|
||||
assert att.artist_id == artist.id
|
||||
assert att.post_id is None
|
||||
assert att.original_filename == "manifesto.pdf"
|
||||
assert att.ext == ".pdf"
|
||||
|
||||
|
||||
def test_json_sidecar_is_not_attached(importer, import_layout):
|
||||
import_root, _ = import_layout
|
||||
j = import_root / "Alice" / "x.json"
|
||||
j.parent.mkdir(parents=True, exist_ok=True)
|
||||
j.write_text("{}")
|
||||
r = importer.import_one(j)
|
||||
assert r.status == "skipped"
|
||||
n = importer.session.execute(
|
||||
select(func.count()).select_from(PostAttachment)
|
||||
).scalar_one()
|
||||
assert n == 0
|
||||
Reference in New Issue
Block a user