Files
offline-db/core/tests/test_dashboard.py
google-labs-jules[bot] aa51d89d5e fix(core): auto-repair & stability improvements (#84)
- Refactored `core/tests/test_old.py` into `core/tests/test_dashboard.py`.
- Removed redundant `ChatConsumerTests` from legacy file as they are covered by `core/tests/test_chat_persistence.py`.
- Current Focus Mode: A (The Medic)
- Changes Made: Cleaned up messy test code and improved organization.
- Impact on System: Improved test suite maintainability and clarity.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-01-20 22:33:54 +00:00

49 lines
1.6 KiB
Python

from django.test import TestCase, RequestFactory
from content.models import Anime, Season, Episode, VideoFile
from core.dashboard import dashboard_callback
class DashboardTests(TestCase):
def setUp(self):
self.factory = RequestFactory()
def test_dashboard_stats_bandwidth(self):
# Setup data
anime = Anime.objects.create(title="Test Anime")
season = Season.objects.create(anime=anime, number=1)
episode = Episode.objects.create(season=season, number=1)
# 1 GB file
file_size = 1024 * 1024 * 1024
VideoFile.objects.create(
episode=episode,
quality='1080p',
hls_path='/tmp/test.m3u8',
encryption_key='testkey',
file_size_bytes=file_size
)
request = self.factory.get('/')
context = {}
# Call function
updated_context = dashboard_callback(request, context)
# Verify
stats = updated_context.get('dashboard_stats', {})
self.assertIn('bandwidth_saved_gb', stats)
# 1 GB file -> 1.0 GB saved
self.assertEqual(stats['bandwidth_saved_gb'], 1.0)
# Verify Graph Data
self.assertIn('bandwidth_chart', stats)
import json
chart = json.loads(stats['bandwidth_chart'])
self.assertIn('labels', chart)
self.assertIn('datasets', chart)
datasets = chart['datasets']
self.assertEqual(len(datasets), 1)
data = datasets[0]['data']
self.assertEqual(len(data), 7)
# Check that the last element (today) is 1.0 GB
self.assertEqual(data[-1], 1.0)