Files
ohm_streaming/tests
root 7dabce1c3c 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>
2026-01-29 19:19:53 +00:00
..

Tests pour Ohm Stream Downloader

Ce dossier contient la suite de tests unitaires pour le projet Ohm Stream Downloader.

Structure

tests/
├── __init__.py              # Package initialization
├── conftest.py              # Pytest configuration et fixtures
├── test_models.py           # Tests pour les modèles Pydantic
├── test_downloaders.py      # Tests pour les downloaders
├── test_download_manager.py # Tests pour DownloadManager
├── test_favorites.py        # Tests pour le système de favoris
└── test_api.py              # Tests pour les endpoints FastAPI

Lancer les tests

Tous les tests

pytest

Avec couverture de code

pytest --cov=app --cov-report=html

Uniquement les tests unitaires (rapides)

pytest -m "unit"

Uniquement les tests d'intégration

pytest -m "integration"

Exclure les tests lents

pytest -m "not slow"

Mode verbeux

pytest -v

Afficher le print debugging

pytest -s

Fixtures disponibles

Les fixtures sont définies dans conftest.py :

  • temp_dir : Répertoire temporaire pour les tests
  • temp_download_dir : Répertoire de téléchargement temporaire
  • sample_download_task : Exemple de tâche de téléchargement
  • sample_download_request : Exemple de requête de téléchargement
  • download_manager : Instance de DownloadManager configurée
  • favorites_manager : Instance de FavoritesManager configurée
  • mock_httpx_client : Mock pour httpx.AsyncClient
  • sample_anime_metadata : Exemple de métadonnées anime
  • sample_favorite_data : Exemple de favori

Marqueurs (Markers)

Les tests sont marqués automatiquement :

  • unit : Tests unitaires (isolés, rapides)
  • integration : Tests d'intégration (API endpoints)
  • asyncio : Tests asynchrones
  • slow : Tests lents (à marquer manuellement)
  • network : Tests nécessitant un accès réseau

Couverture de code

Le rapport de couverture est généré dans htmlcov/index.html après avoir lancé :

pytest --cov=app --cov-report=html

Notes

  • Les tests utilisent des mocks pour éviter les appels réseau réels
  • Les fichiers temporaires sont nettoyés automatiquement après chaque test
  • La base de données de favoris utilise des fichiers temporaires
  • Les tests asynchrones utilisent pytest-asyncio