make section_name required in enrich_items_with_user_data

This commit is contained in:
FuzzyGrim
2026-02-08 15:51:13 +01:00
parent 1e18d557cb
commit 2ffccd09b1
3 changed files with 64 additions and 6 deletions

View File

@@ -66,7 +66,7 @@ def format_search_response(page, per_page, total_results, results):
}
def enrich_items_with_user_data(request, items, section_name=None):
def enrich_items_with_user_data(request, items, section_name):
"""Enrich a list of items with user tracking data."""
if not items:
return []

View File

@@ -154,7 +154,7 @@ class EnrichItemsWithUserDataTest(TestCase):
},
]
enriched_items = enrich_items_with_user_data(self.request, raw_items)
enriched_items = enrich_items_with_user_data(self.request, raw_items, "test")
self.assertEqual(len(enriched_items), 3)
# Scenario 1: Existing movie with user tracking data
@@ -192,3 +192,60 @@ class EnrichItemsWithUserDataTest(TestCase):
unknown_movie_enriched["item"]["description"],
"This movie doesn't exist in our database",
)
def test_hide_completed_recommendations_enabled(self):
"""Test that completed items are hidden when preference is enabled."""
self.user.hide_completed_recommendations = True
self.user.save()
raw_items = [
{
"media_id": "238", # This is our completed movie
"source": Sources.TMDB.value,
"media_type": MediaTypes.MOVIE.value,
"title": "Test Movie",
"image": "http://example.com/movie.jpg",
},
{
"media_id": "99999", # Not tracked
"source": Sources.TMDB.value,
"media_type": MediaTypes.MOVIE.value,
"title": "Unknown Movie",
"image": "http://example.com/unknown.jpg",
},
]
# When section is "recommendations", completed items should be hidden
enriched_items = enrich_items_with_user_data(
self.request, raw_items, "recommendations"
)
self.assertEqual(len(enriched_items), 1)
self.assertEqual(enriched_items[0]["item"]["media_id"], "99999")
def test_hide_completed_recommendations_disabled(self):
"""Test that completed items are shown when preference is disabled."""
self.user.hide_completed_recommendations = False
self.user.save()
raw_items = [
{
"media_id": "238", # This is our completed movie
"source": Sources.TMDB.value,
"media_type": MediaTypes.MOVIE.value,
"title": "Test Movie",
"image": "http://example.com/movie.jpg",
},
{
"media_id": "99999",
"source": Sources.TMDB.value,
"media_type": MediaTypes.MOVIE.value,
"title": "Unknown Movie",
"image": "http://example.com/unknown.jpg",
},
]
# With preference disabled, all items should be returned
enriched_items = enrich_items_with_user_data(
self.request, raw_items, "recommendations"
)
self.assertEqual(len(enriched_items), 2)

View File

@@ -179,7 +179,9 @@ def media_search(request):
# Enrich search results with user tracking data
if data.get("results"):
data["results"] = helpers.enrich_items_with_user_data(request, data["results"])
data["results"] = helpers.enrich_items_with_user_data(
request, data["results"], "search"
)
context = {
"data": data,
@@ -209,9 +211,7 @@ def media_details(request, source, media_type, media_id, title): # noqa: ARG001
if related_items:
media_metadata["related"][section_name] = (
helpers.enrich_items_with_user_data(
request,
related_items,
section_name
request, related_items, section_name
)
)
@@ -265,6 +265,7 @@ def season_details(request, source, media_id, title, season_number): # noqa: AR
helpers.enrich_items_with_user_data(
request,
related_items,
section_name,
)
)