refactor: Apply code quality improvements from PR review
This commit implements the optional improvements identified during code review: **Backend (animesama.py):** - Replace all print() statements with logger calls for consistency - Use logger.debug() for detailed debugging information - Use logger.info() for general operational messages - Use logger.warning() for non-critical issues - Use logger.error() for error conditions - Add comprehensive docstring to get_seasons() method: - Document two-phase parallel loading strategy - Explain performance characteristics (200x faster) - Document timeout behavior and error handling - Include usage examples and return value format - Import logging module and initialize logger **Frontend (anime.js & api.js):** - Create providerSupportsSeasons() helper function in api.js: - Uses provider configuration as single source of truth - Eliminates hardcoded 'animesama' and 'anime-sama' checks - Supports explicit supports_seasons flag in provider config - Fallback to domain detection for unknown URLs - Update renderAnimeCard() to use async helper function - Update loadSeasonsForAnime() to use provider configuration - Update displaySearchResults() to handle async card rendering - Export helper function globally for use across modules **Tests (test_anime_sama_seasons.py):** - Fix import paths for new animesama.py location - Update from app.downloaders.animesama to app.downloaders.anime_sites.animesama - All tests passing with new structure **Benefits:** - Consistent logging throughout the codebase - Better maintainability with configuration-driven behavior - Improved documentation for complex async logic - Easier to add new season-supporting providers in future - No hardcoded provider checks in frontend code All tests passing: 5/5 ✅ Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -12,7 +12,7 @@ class TestAnimeSamaSeasons:
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_seasons_no_seasons_available(self):
|
||||
"""Test get_seasons when no seasons exist"""
|
||||
from app.downloaders.animesama import AnimeSamaDownloader
|
||||
from app.downloaders.anime_sites.animesama import AnimeSamaDownloader
|
||||
|
||||
downloader = AnimeSamaDownloader()
|
||||
|
||||
@@ -54,7 +54,7 @@ class TestAnimeSamaSeasons:
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_seasons_with_multiple_seasons(self):
|
||||
"""Test get_seasons when multiple seasons exist"""
|
||||
from app.downloaders.animesama import AnimeSamaDownloader
|
||||
from app.downloaders.anime_sites.animesama import AnimeSamaDownloader
|
||||
|
||||
downloader = AnimeSamaDownloader()
|
||||
|
||||
@@ -103,7 +103,7 @@ class TestAnimeSamaSeasons:
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_seasons_url_parsing(self):
|
||||
"""Test that get_seasons correctly parses URLs"""
|
||||
from app.downloaders.animesama import AnimeSamaDownloader
|
||||
from app.downloaders.anime_sites.animesama import AnimeSamaDownloader
|
||||
|
||||
downloader = AnimeSamaDownloader()
|
||||
|
||||
@@ -131,7 +131,7 @@ class TestAnimeSamaSeasons:
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_seasons_sorting(self):
|
||||
"""Test that seasons are returned in correct order"""
|
||||
from app.downloaders.animesama import AnimeSamaDownloader
|
||||
from app.downloaders.anime_sites.animesama import AnimeSamaDownloader
|
||||
|
||||
downloader = AnimeSamaDownloader()
|
||||
|
||||
@@ -153,7 +153,7 @@ class TestAnimeSamaSeasons:
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_seasons_with_season_links_in_html(self):
|
||||
"""Test get_seasons when season links are present in HTML"""
|
||||
from app.downloaders.animesama import AnimeSamaDownloader
|
||||
from app.downloaders.anime_sites.animesama import AnimeSamaDownloader
|
||||
|
||||
downloader = AnimeSamaDownloader()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user