Spaces:
Running
Running
File size: 1,303 Bytes
9fe5a30 781f7b0 9fe5a30 781f7b0 9fe5a30 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | """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
@pytest.fixture
def client():
"""Create a test client for the FastAPI app."""
with TestClient(app) as test_client:
yield test_client
@pytest.fixture
def api_key():
"""Get a valid API key for testing."""
return list(settings.api_keys_set)[0]
@pytest.fixture
def invalid_api_key():
"""Get an invalid API key for testing."""
return "invalid-key-for-testing"
@pytest.fixture
def mock_asyncio_subprocess():
"""Mock asyncio subprocess calls for yt-dlp."""
with patch('asyncio.create_subprocess_exec') as mock_exec:
yield mock_exec
@pytest.fixture
def temp_dir():
"""Create a temporary directory for testing."""
with tempfile.TemporaryDirectory() as tmp_dir:
yield tmp_dir
@pytest.fixture
def sample_youtube_url():
"""Sample YouTube URL for testing."""
return "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
@pytest.fixture
def sample_video_id():
"""Sample video ID for testing."""
return "dQw4w9WgXcQ" |