Spaces:
Running
Running
| """Pytest configuration and fixtures.""" | |
| import pytest | |
| from fastapi.testclient import TestClient | |
| from unittest.mock import patch | |
| import tempfile | |
| import os | |
| # Ensure API_KEYS is set for testing | |
| os.environ.setdefault("API_KEYS", "test-key-1,test-key-2") | |
| from app.main import app | |
| from app.core.config import settings | |
| def client(): | |
| """Create a test client for the FastAPI app.""" | |
| with TestClient(app) as test_client: | |
| yield test_client | |
| def api_key(): | |
| """Get a valid API key for testing.""" | |
| return list(settings.api_keys_set)[0] | |
| def invalid_api_key(): | |
| """Get an invalid API key for testing.""" | |
| return "invalid-key-for-testing" | |
| def mock_asyncio_subprocess(): | |
| """Mock asyncio subprocess calls for yt-dlp.""" | |
| with patch('asyncio.create_subprocess_exec') as mock_exec: | |
| yield mock_exec | |
| def temp_dir(): | |
| """Create a temporary directory for testing.""" | |
| with tempfile.TemporaryDirectory() as tmp_dir: | |
| yield tmp_dir | |
| def sample_youtube_url(): | |
| """Sample YouTube URL for testing.""" | |
| return "https://www.youtube.com/watch?v=dQw4w9WgXcQ" | |
| def sample_video_id(): | |
| """Sample video ID for testing.""" | |
| return "dQw4w9WgXcQ" |