Set up test directory structure and pytest configuration
- Created unit, integration, and e2e test directories - Added conftest.py with common fixtures and mocks - Added pytest.ini with test configuration and markers
This commit is contained in:
parent
88db74c9a0
commit
f550ec05e3
18
pytest.ini
Normal file
18
pytest.ini
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[tool:pytest]
|
||||||
|
testpaths = src/tests
|
||||||
|
python_files = test_*.py
|
||||||
|
python_classes = Test*
|
||||||
|
python_functions = test_*
|
||||||
|
addopts =
|
||||||
|
-v
|
||||||
|
--tb=short
|
||||||
|
--strict-markers
|
||||||
|
--disable-warnings
|
||||||
|
markers =
|
||||||
|
unit: Unit tests
|
||||||
|
integration: Integration tests
|
||||||
|
e2e: End-to-end tests
|
||||||
|
slow: Slow running tests
|
||||||
|
filterwarnings =
|
||||||
|
ignore::DeprecationWarning
|
||||||
|
ignore::PendingDeprecationWarning
|
||||||
143
src/tests/conftest.py
Normal file
143
src/tests/conftest.py
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
"""
|
||||||
|
Pytest configuration file for AniWorld application tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
|
# 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."""
|
||||||
|
import jwt
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
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."""
|
||||||
|
import jwt
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
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"
|
||||||
|
]
|
||||||
Loading…
x
Reference in New Issue
Block a user