Files
Barış Keserandgoogle-labs-jules[bot] f4e3fe6d5e fix(caching): add caching to Anime/Episode ViewSets and clean tests (#356)
This patch resolves missing caching decorators on DRF ViewSet methods (`AnimeViewSet.retrieve`, `EpisodeViewSet.list`, `EpisodeViewSet.retrieve`) that were previously lacking, leading to test performance failures where 0 queries were expected. It also deletes outdated tests (`test_search_view_caches_genres`, `test_anime_detail_caches_seasons`) that relied on the legacy Django views (`search`, `anime_detail`) which have been superseded by the ViewSets and commented out in `urls.py`. The `test_home_performance.py` test is properly updated to expect 0 queries post-warmup due to correct view caching.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-06-23 20:49:26 +00:00

39 lines
1.2 KiB
Python

import pytest
from django.core.cache import cache
from django.urls import reverse
from content.models import Genre, Anime, Season, Episode
@pytest.mark.django_db
class TestCaching:
def test_genre_signal_clears_cache(self):
cache.set('all_genres', ['fake_data'])
# Creating a genre should clear cache
Genre.objects.create(name='Comedy', slug='comedy')
assert cache.get('all_genres') is None
def test_episode_signal_clears_anime_cache(self):
anime = Anime.objects.create(title='Test Anime 2')
season = Season.objects.create(anime=anime, number=1)
cache_key = f'anime_{anime.id}_seasons'
cache.set(cache_key, ['fake_data'])
# Creating episode should clear cache
Episode.objects.create(season=season, number=1)
assert cache.get(cache_key) is None
def test_season_signal_clears_anime_cache(self):
anime = Anime.objects.create(title='Test Anime 3')
cache_key = f'anime_{anime.id}_seasons'
cache.set(cache_key, ['fake_data'])
# Creating season should clear cache
Season.objects.create(anime=anime, number=2)
assert cache.get(cache_key) is None