generated from john/python-template
v5.0 Introduce centralized homepage & portrait photo management
Quality Gate / gate (push) Failing after 11s
Quality Gate / gate (push) Failing after 11s
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from transcription.config import Settings
|
||||
from transcription.db.models import Person
|
||||
from transcription.services.people import PeopleService
|
||||
from transcription.services.photos import PhotosService
|
||||
|
||||
PNG_BYTES = bytes.fromhex(
|
||||
"89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c4890000000a49444154789c6360000002000100"
|
||||
"05fe02fea7b1b8000000004945"
|
||||
) + b"NDAE\xae\x42\x60\x82"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_photo_persists_media_and_primary_state(default_session_factory, tmp_path):
|
||||
settings = Settings(openrouter_api_key="test-key", upload_dir=tmp_path / "uploads")
|
||||
people = PeopleService(session_factory=default_session_factory)
|
||||
photos = PhotosService(session_factory=default_session_factory, settings=settings)
|
||||
person = await people.create_person(Person(full_name="Photo Person"))
|
||||
|
||||
first = await photos.create_photo(person_id=person.id, filename="one.png", file_bytes=PNG_BYTES)
|
||||
second = await photos.create_photo(person_id=person.id, filename="two.png", file_bytes=PNG_BYTES)
|
||||
listed = await photos.list_photos(person_id=person.id)
|
||||
|
||||
assert first.path.startswith("photos/")
|
||||
assert (settings.upload_dir / first.path).exists()
|
||||
assert first.is_primary is True
|
||||
assert second.is_primary is False
|
||||
assert listed[0].is_primary is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_primary_and_delete_promotes_next_photo(default_session_factory, tmp_path):
|
||||
settings = Settings(openrouter_api_key="test-key", upload_dir=tmp_path / "uploads")
|
||||
people = PeopleService(session_factory=default_session_factory)
|
||||
photos = PhotosService(session_factory=default_session_factory, settings=settings)
|
||||
person = await people.create_person(Person(full_name="Primary Person"))
|
||||
|
||||
first = await photos.create_photo(person_id=person.id, filename="one.png", file_bytes=PNG_BYTES)
|
||||
second = await photos.create_photo(person_id=person.id, filename="two.png", file_bytes=PNG_BYTES)
|
||||
|
||||
await photos.set_primary(photo_id=second.id)
|
||||
switched = await photos.list_photos(person_id=person.id)
|
||||
assert switched[0].id == second.id
|
||||
assert switched[0].is_primary is True
|
||||
|
||||
await photos.delete_photo(photo_id=second.id)
|
||||
remaining = await photos.list_photos(person_id=person.id)
|
||||
assert len(remaining) == 1
|
||||
assert remaining[0].id == first.id
|
||||
assert remaining[0].is_primary is True
|
||||
Reference in New Issue
Block a user