feat(provenance): ProvenanceService.for_post (post-header payload)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -65,3 +65,20 @@ class ProvenanceService:
|
|||||||
for ip, post, src, art in rows
|
for ip, post, src, art in rows
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async def for_post(self, post_id: int) -> dict | None:
|
||||||
|
stmt = (
|
||||||
|
select(Post, Source, Artist)
|
||||||
|
.join(Source, Source.id == Post.source_id)
|
||||||
|
.join(Artist, Artist.id == Source.artist_id)
|
||||||
|
.where(Post.id == post_id)
|
||||||
|
)
|
||||||
|
row = (await self.session.execute(stmt)).first()
|
||||||
|
if row is None:
|
||||||
|
return None
|
||||||
|
post, src, art = row
|
||||||
|
return {
|
||||||
|
"post": _post_dict(post),
|
||||||
|
"source": _source_dict(src),
|
||||||
|
"artist": _artist_dict(art),
|
||||||
|
}
|
||||||
|
|||||||
@@ -129,3 +129,27 @@ async def test_for_image_null_post_fields_serialize_null(db):
|
|||||||
assert e["post"]["title"] is None
|
assert e["post"]["title"] is None
|
||||||
assert e["post"]["description_html"] is None
|
assert e["post"]["description_html"] is None
|
||||||
assert e["post"]["attachment_count"] is None
|
assert e["post"]["attachment_count"] is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_for_post_missing_returns_none(db):
|
||||||
|
svc = ProvenanceService(db)
|
||||||
|
assert await svc.for_post(999999) is None
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_for_post_returns_post_source_artist(db):
|
||||||
|
artist, source, post = await _seed_post(
|
||||||
|
db, artist_name="Carol", slug="carol", platform="patreon",
|
||||||
|
ext_id="77", title="T", desc="<p>d</p>", count=3,
|
||||||
|
)
|
||||||
|
svc = ProvenanceService(db)
|
||||||
|
payload = await svc.for_post(post.id)
|
||||||
|
assert payload["post"]["id"] == post.id
|
||||||
|
assert payload["post"]["title"] == "T"
|
||||||
|
assert payload["post"]["description_html"] == "<p>d</p>"
|
||||||
|
assert payload["post"]["attachment_count"] == 3
|
||||||
|
assert payload["source"] == {"id": source.id, "platform": "patreon",
|
||||||
|
"url": source.url}
|
||||||
|
assert payload["artist"] == {"id": artist.id, "name": "Carol",
|
||||||
|
"slug": "carol"}
|
||||||
|
|||||||
Reference in New Issue
Block a user