58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
"""Pytest configuration and fixtures."""
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from app.main import app
|
|
from app.core.config import Settings, get_settings
|
|
import bcrypt
|
|
|
|
|
|
# Test settings
|
|
TEST_PASSWORD = "test_password_123"
|
|
TEST_PASSWORD_HASH = bcrypt.hashpw(TEST_PASSWORD.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
|
|
|
|
|
|
def get_test_settings():
|
|
"""Override settings for testing."""
|
|
return Settings(
|
|
auth_username="testuser",
|
|
auth_password_hash=TEST_PASSWORD_HASH,
|
|
jwt_secret="test-secret-key-for-testing-only",
|
|
jwt_expires_minutes=60,
|
|
max_file_mb=10,
|
|
log_level="DEBUG",
|
|
service_name="mve-incrementables-parser",
|
|
service_version="1.0.0"
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def test_settings():
|
|
"""Provide test settings."""
|
|
return get_test_settings()
|
|
|
|
|
|
@pytest.fixture
|
|
def client(test_settings):
|
|
"""Create a test client with overridden settings."""
|
|
app.dependency_overrides[get_settings] = lambda: test_settings
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
app.dependency_overrides.clear()
|
|
|
|
|
|
@pytest.fixture
|
|
def auth_token(client):
|
|
"""Get authentication token for testing."""
|
|
response = client.post(
|
|
"/auth/login",
|
|
json={"username": "testuser", "password": TEST_PASSWORD}
|
|
)
|
|
assert response.status_code == 200
|
|
return response.json()["access_token"]
|
|
|
|
|
|
@pytest.fixture
|
|
def auth_headers(auth_token):
|
|
"""Get authorization headers for testing."""
|
|
return {"Authorization": f"Bearer {auth_token}"}
|