update
This commit is contained in:
@@ -62,6 +62,9 @@ def test_vorgaben_aus_der_leiste():
|
||||
assert ki.vorgaben({"jahr_min": 1980, "jahr_max": 1989}) == ["Zwischen 1980 und 1989"]
|
||||
assert ki.vorgaben({}) == []
|
||||
assert "unbedingt einhalten" in ki.prompt("x", [], [], {"include": ["Horror"]})
|
||||
assert "Nenne genau 30 Filme" in ki.system(30)
|
||||
assert "38 Originaltitel" in ki.system(30)
|
||||
assert '{"merkmale"' in ki.system(12)
|
||||
|
||||
|
||||
def test_titel_muss_zum_treffer_passen():
|
||||
@@ -77,9 +80,9 @@ def test_titel_muss_zum_treffer_passen():
|
||||
def test_route_fragt_und_loest_auf(client, film, monkeypatch):
|
||||
aufrufe = {}
|
||||
|
||||
async def fragen(beschreibung, sammlung, gesehen, filter_):
|
||||
async def fragen(beschreibung, sammlung, gesehen, filter_, anzahl):
|
||||
aufrufe.update(
|
||||
beschreibung=beschreibung, sammlung=sammlung, gesehen=gesehen, filter=filter_
|
||||
beschreibung=beschreibung, sammlung=sammlung, gesehen=gesehen, filter=filter_, anzahl=anzahl
|
||||
)
|
||||
return [{"titel": "The Witch", "jahr": 2015, "grund": "Passt."}]
|
||||
|
||||
@@ -108,6 +111,9 @@ def test_route_fragt_und_loest_auf(client, film, monkeypatch):
|
||||
assert aufrufe["filter"]["include"] == ["Horror", "Mystery"]
|
||||
assert aufrufe["filter"]["jahr_min"] == 2010
|
||||
assert aufrufe["filter"]["note_max"] is None
|
||||
assert aufrufe["anzahl"] == 12
|
||||
client.post("/api/ki-suche", json={"beschreibung": "x", "limit": 40})
|
||||
assert aufrufe["anzahl"] == 40
|
||||
|
||||
# Gesehene dürfen auch drinbleiben — dann zeigt die Karte es an
|
||||
client.post("/api/ki-suche", json={"beschreibung": "x", "ohne_gesehene": False})
|
||||
@@ -115,7 +121,7 @@ def test_route_fragt_und_loest_auf(client, film, monkeypatch):
|
||||
|
||||
|
||||
def test_nur_filter_reichen_als_frage(client, monkeypatch):
|
||||
async def fragen(beschreibung, sammlung, gesehen, filter_):
|
||||
async def fragen(beschreibung, sammlung, gesehen, filter_, anzahl):
|
||||
return []
|
||||
|
||||
async def aufloesen(vorschlaege, filter_, ausser=()):
|
||||
|
||||
20
backend/tests/test_leihbar.py
Normal file
20
backend/tests/test_leihbar.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""Ob ein Film leihbar ist, kommt aus den Anbieterdaten von TMDB."""
|
||||
|
||||
from app import db, tmdb
|
||||
|
||||
|
||||
def test_leihbar_aus_anbieterdaten():
|
||||
de = lambda eintrag: {"watch/providers": {"results": {"DE": eintrag}}}
|
||||
assert tmdb.pick_rentable(de({"rent": [{"provider_name": "Amazon Video"}]})) == 1
|
||||
assert tmdb.pick_rentable(de({"flatrate": [{"provider_name": "Netflix"}]})) == 0
|
||||
assert tmdb.pick_rentable({"watch/providers": {"results": {}}}) == 0
|
||||
# Ohne Anbieterdaten bleibt es offen — nicht fälschlich "nicht leihbar"
|
||||
assert tmdb.pick_rentable({}) is None
|
||||
|
||||
|
||||
def test_leihbarkeit_kommt_mit_dem_film(client):
|
||||
with db.connect() as conn:
|
||||
db.upsert(conn, {"id": 7, "title": "Abo-Film", "rentable": 0})
|
||||
db.upsert(conn, {"id": 8, "title": "Unbekannt"})
|
||||
assert client.get("/api/movies/7").json()["rentable"] == 0
|
||||
assert client.get("/api/movies/8").json()["rentable"] is None
|
||||
58
backend/tests/test_personen.py
Normal file
58
backend/tests/test_personen.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user