- Add SetupService for detecting application setup completion - Create ApplicationFlowMiddleware to enforce setup auth main flow - Add setup processing endpoints (/api/auth/setup, /api/auth/setup/status) - Add Pydantic models for setup requests and responses - Integrate middleware into FastAPI application - Fix logging paths to use ./logs consistently - All existing templates (setup.html, login.html) already working
146 lines
3.2 KiB
Python
146 lines
3.2 KiB
Python
"""
|
|
Pytest configuration file for AniWorld application tests.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
# Add source directory to path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def test_config():
|
|
"""Test configuration settings."""
|
|
return {
|
|
"jwt_secret_key": "test-secret-key",
|
|
"password_salt": "test-salt",
|
|
"master_password": "test_password",
|
|
"master_password_hash": "hashed_test_password",
|
|
"token_expiry_hours": 1,
|
|
"database_url": "sqlite:///:memory:",
|
|
"anime_directory": "./test_data",
|
|
"log_level": "DEBUG"
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_settings(test_config):
|
|
"""Mock settings for testing."""
|
|
from unittest.mock import Mock
|
|
settings = Mock()
|
|
for key, value in test_config.items():
|
|
setattr(settings, key, value)
|
|
return settings
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_database():
|
|
"""Mock database connection."""
|
|
return Mock()
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_logger():
|
|
"""Mock logger for testing."""
|
|
return Mock()
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_anime_data():
|
|
"""Sample anime data for testing."""
|
|
return {
|
|
"id": 1,
|
|
"title": "Test Anime",
|
|
"genre": "Action",
|
|
"year": 2023,
|
|
"episodes": [
|
|
{"id": 1, "title": "Episode 1", "season": 1, "episode": 1},
|
|
{"id": 2, "title": "Episode 2", "season": 1, "episode": 2}
|
|
]
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_episode_data():
|
|
"""Sample episode data for testing."""
|
|
return {
|
|
"id": 1,
|
|
"title": "Test Episode",
|
|
"season": 1,
|
|
"episode": 1,
|
|
"anime_id": 1,
|
|
"download_url": "https://example.com/episode1.mp4"
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def valid_jwt_token():
|
|
"""Valid JWT token for testing."""
|
|
from datetime import datetime, timedelta
|
|
|
|
import jwt
|
|
|
|
payload = {
|
|
"user": "test_user",
|
|
"exp": datetime.utcnow() + timedelta(hours=1)
|
|
}
|
|
return jwt.encode(payload, "test-secret-key", algorithm="HS256")
|
|
|
|
|
|
@pytest.fixture
|
|
def expired_jwt_token():
|
|
"""Expired JWT token for testing."""
|
|
from datetime import datetime, timedelta
|
|
|
|
import jwt
|
|
|
|
payload = {
|
|
"user": "test_user",
|
|
"exp": datetime.utcnow() - timedelta(hours=1)
|
|
}
|
|
return jwt.encode(payload, "test-secret-key", algorithm="HS256")
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_request():
|
|
"""Mock FastAPI request object."""
|
|
request = Mock()
|
|
request.headers = {}
|
|
request.client = Mock()
|
|
request.client.host = "127.0.0.1"
|
|
return request
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_file_system():
|
|
"""Mock file system operations."""
|
|
return Mock()
|
|
|
|
|
|
# Pytest configuration
|
|
def pytest_configure(config):
|
|
"""Configure pytest with custom markers."""
|
|
config.addinivalue_line(
|
|
"markers", "unit: marks tests as unit tests"
|
|
)
|
|
config.addinivalue_line(
|
|
"markers", "integration: marks tests as integration tests"
|
|
)
|
|
config.addinivalue_line(
|
|
"markers", "e2e: marks tests as end-to-end tests"
|
|
)
|
|
config.addinivalue_line(
|
|
"markers", "slow: marks tests as slow running"
|
|
)
|
|
|
|
|
|
# Test collection configuration
|
|
collect_ignore = [
|
|
"test_auth.ps1",
|
|
"test_auth_flow.ps1",
|
|
"test_database.ps1"
|
|
] |