Découverte : masquer Incontournables et Pour toi en mode séries
Ces deux sections sont issues de Kitsu (catalogue animés) — elles n'ont pas de sens pour un compte en préférence « séries » et montraient des animés malgré le filtre des nouveautés. Elles ne sont même plus calculées (aucun appel Kitsu) et l'UI masque les sections vides. +1 test (Kitsu simulé) — 115 au total.
This commit is contained in:
@@ -22,8 +22,14 @@ async def get_discover(
|
|||||||
for_you_limit: Annotated[int, Query(ge=1, le=20)] = 20,
|
for_you_limit: Annotated[int, Query(ge=1, le=20)] = 20,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""Les trois sections de découverte en une requête (sections vides si source KO)."""
|
"""Les trois sections de découverte en une requête (sections vides si source KO)."""
|
||||||
must_watch = await discover.must_watch(must_watch_limit)
|
|
||||||
for_you = await discover.for_you(user.id, for_you_limit)
|
|
||||||
allowed = _allowed_media_types(user.content_preference)
|
allowed = _allowed_media_types(user.content_preference)
|
||||||
latest = [i for i in await discover.latest(latest_limit) if i.get("media_type", "anime") in allowed]
|
latest = [i for i in await discover.latest(latest_limit) if i.get("media_type", "anime") in allowed]
|
||||||
|
# Incontournables et Pour toi sont issus de Kitsu (catalogue animés) :
|
||||||
|
# en mode séries, elles n'ont pas de sens — on ne les calcule même pas.
|
||||||
|
if "anime" in allowed:
|
||||||
|
must_watch = await discover.must_watch(must_watch_limit)
|
||||||
|
for_you = await discover.for_you(user.id, for_you_limit)
|
||||||
|
else:
|
||||||
|
must_watch = []
|
||||||
|
for_you = {"based_on": [], "items": []}
|
||||||
return {"latest": latest, "must_watch": must_watch, "for_you": for_you}
|
return {"latest": latest, "must_watch": must_watch, "for_you": for_you}
|
||||||
|
|||||||
@@ -127,3 +127,28 @@ async def test_discover_latest_filtered_by_preference(client, admin_cookies, mon
|
|||||||
await client.put("/auth/preferences", json={"content_preference": "serie"}, cookies=admin_cookies)
|
await client.put("/auth/preferences", json={"content_preference": "serie"}, cookies=admin_cookies)
|
||||||
r = await client.get("/api/discover", cookies=admin_cookies)
|
r = await client.get("/api/discover", cookies=admin_cookies)
|
||||||
assert {i["media_type"] for i in r.json()["latest"]} == {"serie"}
|
assert {i["media_type"] for i in r.json()["latest"]} == {"serie"}
|
||||||
|
|
||||||
|
async def test_discover_hides_kitsu_sections_in_serie_mode(client, admin_cookies, monkeypatch):
|
||||||
|
"""Incontournables et Pour toi (Kitsu = animés) disparaissent en mode séries."""
|
||||||
|
import app.services.discover as discover_module
|
||||||
|
|
||||||
|
await _patch_sources(monkeypatch, MixedSource())
|
||||||
|
|
||||||
|
async def fake_must_watch(limit=20):
|
||||||
|
return [{"kitsu_id": 1, "title": "Animé top"}]
|
||||||
|
|
||||||
|
async def fake_for_you(user_id=0, limit=20):
|
||||||
|
return {"based_on": ["Action"], "items": [{"kitsu_id": 2}]}
|
||||||
|
|
||||||
|
monkeypatch.setattr(discover_module.discover, "must_watch", fake_must_watch)
|
||||||
|
monkeypatch.setattr(discover_module.discover, "for_you", fake_for_you)
|
||||||
|
|
||||||
|
r = await client.get("/api/discover", cookies=admin_cookies)
|
||||||
|
assert len(r.json()["must_watch"]) == 1
|
||||||
|
assert len(r.json()["for_you"]["items"]) == 1
|
||||||
|
|
||||||
|
await client.put("/auth/preferences", json={"content_preference": "serie"}, cookies=admin_cookies)
|
||||||
|
data = (await client.get("/api/discover", cookies=admin_cookies)).json()
|
||||||
|
assert data["must_watch"] == []
|
||||||
|
assert data["for_you"] == {"based_on": [], "items": []}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user