59 lines
2.8 KiB
Python
59 lines
2.8 KiB
Python
"""Personensuche: Schauspieler und Regisseure, dazu ihre Filme."""
|
|
|
|
from app import main, search
|
|
|
|
|
|
def test_credits_werden_nach_rolle_getrennt():
|
|
daten = {
|
|
"cast": [
|
|
{"id": 1, "title": "Klein", "poster_path": "/a.jpg", "popularity": 2, "genre_ids": [27], "vote_count": 80},
|
|
{"id": 2, "title": "Groß", "poster_path": "/b.jpg", "popularity": 9, "release_date": "2001-05-01", "vote_count": 900},
|
|
{"id": 3, "title": "Ohne Poster", "poster_path": None, "popularity": 50, "vote_count": 500},
|
|
{"id": 2, "title": "Groß nochmal", "poster_path": "/b.jpg", "popularity": 9, "vote_count": 900},
|
|
{"id": 6, "title": "Cameo in Doku", "poster_path": "/e.jpg", "popularity": 99, "vote_count": 3},
|
|
],
|
|
"crew": [
|
|
{"id": 4, "title": "Regiearbeit", "job": "Director", "poster_path": "/c.jpg", "popularity": 1, "vote_count": 60},
|
|
{"id": 5, "title": "Nur Drehbuch", "job": "Writer", "poster_path": "/d.jpg", "popularity": 1, "vote_count": 60},
|
|
],
|
|
}
|
|
rollen = search.credits_aufbereiten(daten)
|
|
# Auch der Cameo bleibt — was raus soll, entscheidet die Filterleiste
|
|
assert [f["title"] for f in rollen["gespielt"]] == ["Cameo in Doku", "Groß", "Klein"]
|
|
assert rollen["gespielt"][1]["year"] == 2001
|
|
assert rollen["gespielt"][2]["genres"] == ["Horror"]
|
|
assert [f["title"] for f in rollen["regie"]] == ["Regiearbeit"]
|
|
|
|
|
|
def test_filmografie_kommt_aus_dem_speicher(client):
|
|
import asyncio
|
|
import time
|
|
|
|
search.PERSONEN_CACHE[99] = (time.monotonic(), {"gespielt": [{"id": 1}], "regie": []})
|
|
# Ohne Netz — käme der Abruf durch, flöge hier ein Fehler
|
|
assert asyncio.run(search.person_filme(99))["gespielt"] == [{"id": 1}]
|
|
assert client.get("/api/personen/99/filme").json()["gespielt"] == [{"id": 1}]
|
|
del search.PERSONEN_CACHE[99]
|
|
|
|
|
|
def test_credits_route(client, monkeypatch):
|
|
async def credits(movie_id):
|
|
return {"regie": [{"id": 1, "name": "R", "fach": "Regie", "profile_path": None}], "cast": []}
|
|
|
|
monkeypatch.setattr(main.search, "credits", credits)
|
|
assert client.get("/api/movies/5/credits").json()["regie"][0]["fach"] == "Regie"
|
|
|
|
|
|
def test_routen_reichen_durch(client, monkeypatch):
|
|
async def personen(query):
|
|
return [{"id": 7, "name": query, "fach": "Regie", "profile_path": None, "bekannt_fuer": []}]
|
|
|
|
async def person_filme(person_id):
|
|
return {"gespielt": [], "regie": [{"id": person_id, "title": "x"}]}
|
|
|
|
monkeypatch.setattr(main.search, "personen", personen)
|
|
monkeypatch.setattr(main.search, "person_filme", person_filme)
|
|
assert client.get("/api/personen?q=D").json() == []
|
|
assert client.get("/api/personen?q=Duvivier").json()[0]["name"] == "Duvivier"
|
|
assert client.get("/api/personen/7/filme").json()["regie"][0]["id"] == 7
|