kink-discovery / tests /test_recommend_unique.py
Perplexed7675's picture
Sync from kink_cli (Docker Space)
6ff91d6 verified
Raw
History Blame Contribute Delete
840 Bytes
"""Defensive dedupe for recommendation payloads."""
from __future__ import annotations
from backend.recommendations import _take_unique_kink_items
def test_take_unique_kink_items_first_wins_and_respects_limit():
a = {"kink": {"id": "x", "name": "A"}, "score": 1.0}
b = {"kink": {"id": "y", "name": "B"}, "score": 0.9}
c = {"kink": {"id": "x", "name": "A-dup"}, "score": 0.8}
out = _take_unique_kink_items([a, b, c], limit=10, excluded_ids=set())
assert [i["kink"]["id"] for i in out] == ["x", "y"]
assert out[0]["score"] == 1.0
def test_take_unique_excludes_played():
a = {"kink": {"id": "p", "name": "Played"}, "score": 1.0}
b = {"kink": {"id": "q", "name": "New"}, "score": 0.5}
out = _take_unique_kink_items([a, b], limit=5, excluded_ids={"p"})
assert [i["kink"]["id"] for i in out] == ["q"]