CI / lint (push) Canceled after 0s
CI / typecheck (push) Canceled after 0s
CI / unit-tests (push) Canceled after 0s
CI / integration-tests (push) Canceled after 0s
CI / container-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s
Production-grade media metadata backend per docs/aurora-core-spec.md: Aurora-owned UUIDv7 identity system, normalized movie/TV/people/credits schema, provider abstraction with a TMDb adapter, an idempotent async ingestion pipeline (normalize -> match -> upsert -> provenance), a Postgres FTS/trigram search layer, a stateless FastAPI v1 API with Redis caching/rate-limiting, arq workers, dev/prod Docker Compose topologies, unit + integration + load tests, CI, and architecture/ database/API/ERD documentation. Co-Authored-By: Claude Sonnet 5 <[email protected]>
92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
"""Integration tests for the Movie API (section 17/18). Requires
|
|
PostgreSQL and Redis — see tests/conftest.py."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from httpx import AsyncClient
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from tests.integration.factories import make_movie, make_provider, movie_aurora_id
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_movie_returns_normalized_record(client: AsyncClient, db_session: AsyncSession):
|
|
provider = await make_provider(db_session)
|
|
movie = await make_movie(db_session, provider=provider)
|
|
await db_session.commit()
|
|
|
|
response = await client.get(f"/api/v1/movies/{movie_aurora_id(movie)}")
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
|
|
assert body["id"] == movie_aurora_id(movie)
|
|
assert body["type"] == "movie"
|
|
assert body["title"] == "The Matrix"
|
|
assert body["runtime"] == 136
|
|
assert {g["name"] for g in body["genres"]} == {"Science Fiction"}
|
|
assert len(body["cast"]) == 1
|
|
assert body["cast"][0]["character"] == "Neo"
|
|
assert body["images"]["posters"][0]["is_primary"] is True
|
|
assert body["external_ids"]["tmdb"] == "603"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_movie_404_for_unknown_id(client: AsyncClient):
|
|
from app.core.ids import aurora_id, new_uuid7
|
|
|
|
unknown_id = aurora_id("movie", new_uuid7())
|
|
response = await client.get(f"/api/v1/movies/{unknown_id}")
|
|
assert response.status_code == 404
|
|
assert response.json()["error"]["code"] == "movie_not_found"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_movie_rejects_malformed_id(client: AsyncClient):
|
|
response = await client.get("/api/v1/movies/not-a-real-id")
|
|
assert response.status_code == 404
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_movie_rejects_wrong_entity_type_id(
|
|
client: AsyncClient, db_session: AsyncSession
|
|
):
|
|
# A well-formed person ID must not resolve as a movie.
|
|
from app.core.ids import aurora_id, new_uuid7
|
|
|
|
person_shaped_id = aurora_id("person", new_uuid7())
|
|
response = await client.get(f"/api/v1/movies/{person_shaped_id}")
|
|
assert response.status_code == 404
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_movie_credits(client: AsyncClient, db_session: AsyncSession):
|
|
movie = await make_movie(db_session)
|
|
await db_session.commit()
|
|
|
|
response = await client.get(f"/api/v1/movies/{movie_aurora_id(movie)}/credits")
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
assert len(body["cast"]) == 1
|
|
assert body["cast"][0]["person"]["name"] == "Keanu Reeves"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_movie_images(client: AsyncClient, db_session: AsyncSession):
|
|
movie = await make_movie(db_session)
|
|
await db_session.commit()
|
|
|
|
response = await client.get(f"/api/v1/movies/{movie_aurora_id(movie)}/images")
|
|
assert response.status_code == 200
|
|
assert len(response.json()["images"]["posters"]) == 1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_movie_videos_empty(client: AsyncClient, db_session: AsyncSession):
|
|
movie = await make_movie(db_session)
|
|
await db_session.commit()
|
|
|
|
response = await client.get(f"/api/v1/movies/{movie_aurora_id(movie)}/videos")
|
|
assert response.status_code == 200
|
|
assert response.json()["videos"] == []
|