|
| 1 | +"""Repository-Tests für slug-Lookup und Slug-oder-UUID-Resolution.""" |
| 2 | +from __future__ import annotations |
| 3 | + |
| 4 | +from uuid import uuid4 |
| 5 | + |
| 6 | +import pytest |
| 7 | +from sqlalchemy.ext.asyncio import AsyncSession |
| 8 | + |
| 9 | +from app.models.printer import Printer |
| 10 | +from app.repositories import printers as printers_repo |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.asyncio |
| 14 | +async def test_get_by_slug_returns_printer(db_session: AsyncSession): |
| 15 | + p = Printer(name="Brother PT-P750W", slug="brother-p750w", |
| 16 | + model="PT-P750W", backend="ptouch") |
| 17 | + await printers_repo.create(db_session, p) |
| 18 | + |
| 19 | + found = await printers_repo.get_by_slug(db_session, "brother-p750w") |
| 20 | + assert found is not None |
| 21 | + assert found.id == p.id |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.asyncio |
| 25 | +async def test_get_by_slug_returns_none_when_missing(db_session: AsyncSession): |
| 26 | + found = await printers_repo.get_by_slug(db_session, "does-not-exist") |
| 27 | + assert found is None |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.asyncio |
| 31 | +async def test_resolve_by_slug_or_uuid_with_uuid(db_session: AsyncSession): |
| 32 | + p = Printer(name="X", slug="x", model="X", backend="mock") |
| 33 | + await printers_repo.create(db_session, p) |
| 34 | + |
| 35 | + found = await printers_repo.resolve_by_slug_or_uuid(db_session, str(p.id)) |
| 36 | + assert found is not None |
| 37 | + assert found.id == p.id |
| 38 | + |
| 39 | + |
| 40 | +@pytest.mark.asyncio |
| 41 | +async def test_resolve_by_slug_or_uuid_with_slug(db_session: AsyncSession): |
| 42 | + p = Printer(name="Y", slug="my-printer", model="Y", backend="mock") |
| 43 | + await printers_repo.create(db_session, p) |
| 44 | + |
| 45 | + found = await printers_repo.resolve_by_slug_or_uuid(db_session, "my-printer") |
| 46 | + assert found is not None |
| 47 | + assert found.id == p.id |
| 48 | + |
| 49 | + |
| 50 | +@pytest.mark.asyncio |
| 51 | +async def test_resolve_by_slug_or_uuid_with_garbage(db_session: AsyncSession): |
| 52 | + found = await printers_repo.resolve_by_slug_or_uuid(db_session, "nonexistent") |
| 53 | + assert found is None |
0 commit comments