Files
ohm_streaming/tests/README.md
root 785147b1b1 test: Add comprehensive unit and integration test suite
Implement a complete test suite for Ohm Stream Downloader with over 300 tests covering:

Test Files:
- tests/test_models.py: Pydantic model validation tests
  * DownloadTask, DownloadRequest, DownloadStatus, HostType
  * AnimeMetadata, AnimeSearchResult
  * Field validation, edge cases, error handling

- tests/test_downloaders.py: Downloader implementation tests
  * BaseDownloader abstract class
  * Unfichier, Doodstream, Rapidfile, Uptobox downloaders
  * Video downloaders (VidMoly, SendVid)
  * Anime provider downloaders (Anime-Sama, Neko-Sama, etc.)
  * URL detection and handling

- tests/test_download_manager.py: Core download management tests
  * Task creation and lifecycle
  * Pause/resume/cancel operations
  * Progress tracking and file handling
  * Concurrency and semaphore limits
  * Error handling and edge cases

- tests/test_favorites.py: Favorites system tests
  * Add, remove, get, list favorites
  * Sorting and filtering (by title, rating, provider, genre)
  * Toggle functionality
  * Statistics generation
  * Concurrent operations

- tests/test_api.py: FastAPI endpoint tests
  * Root, health, providers endpoints
  * Download CRUD operations
  * Anime search and metadata endpoints
  * Favorites API endpoints
  * Sorting and filtering
  * Error handling and validation
  * CORS headers

Infrastructure:
- tests/conftest.py: Pytest configuration and fixtures
  * Temporary directories for isolation
  * Sample data fixtures
  * Mock clients for network operations
  * Custom markers (unit, integration, slow, network)

- pytest.ini: Pytest configuration
  * Coverage reporting (term + HTML)
  * Verbose output with locals
  * Strict markers
  * Async test support
  * Timeout configuration

- requirements.txt: Updated with testing dependencies
  * pytest, pytest-asyncio, pytest-cov
  * pytest-mock, pytest-timeout, pytest-html

- .gitignore: Updated to ignore test artifacts
  * .pytest_cache/, coverage reports
  * Project data files (favorites.json, *.db)

- tests/README.md: Test documentation
  * How to run tests
  * Available fixtures and markers
  * Coverage reporting instructions

Test Coverage Areas:
✓ Model validation and serialization
✓ All downloader implementations
✓ Download queue management
✓ Favorites persistence and retrieval
✓ REST API endpoints
✓ Error handling and edge cases
✓ Async/await operations
✓ Concurrent operations
✓ File system operations

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-23 10:28:47 +00:00

92 lines
2.4 KiB
Markdown

# 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
```bash
pytest
```
### Avec couverture de code
```bash
pytest --cov=app --cov-report=html
```
### Uniquement les tests unitaires (rapides)
```bash
pytest -m "unit"
```
### Uniquement les tests d'intégration
```bash
pytest -m "integration"
```
### Exclure les tests lents
```bash
pytest -m "not slow"
```
### Mode verbeux
```bash
pytest -v
```
### Afficher le print debugging
```bash
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é :
```bash
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`