init update (#1)
Co-authored-by: Sergey Vanyushkin <pi3c@yandex.ru> Co-committed-by: Sergey Vanyushkin <pi3c@yandex.ru>
This commit is contained in:
0
tests/api/__init__.py
Normal file
0
tests/api/__init__.py
Normal file
22
tests/api/conftest.py
Normal file
22
tests/api/conftest.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# API test fixtures
|
||||
# Provides: httpx.AsyncClient, authentication helpers, test API data
|
||||
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def client():
|
||||
"""Create async HTTP client for API testing."""
|
||||
from app.main import app_factory
|
||||
|
||||
app = app_factory()
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as ac:
|
||||
yield ac
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth_headers():
|
||||
"""Return mock authentication headers."""
|
||||
return {"Authorization": "Bearer test_token"}
|
||||
8
tests/conftest.py
Normal file
8
tests/conftest.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def event_loop_policy():
|
||||
import asyncio
|
||||
|
||||
return asyncio.DefaultEventLoopPolicy()
|
||||
0
tests/e2e/__init__.py
Normal file
0
tests/e2e/__init__.py
Normal file
27
tests/e2e/conftest.py
Normal file
27
tests/e2e/conftest.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# E2E test fixtures
|
||||
# Provides: full application state, end-to-end workflows, cleanup
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def e2e_app():
|
||||
"""Create full application instance for E2E testing."""
|
||||
from app.main import app_factory
|
||||
|
||||
app = app_factory()
|
||||
yield app
|
||||
# Cleanup after E2E test
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def e2e_user_data():
|
||||
"""Generate realistic user data for E2E scenarios."""
|
||||
from mimesis import Person
|
||||
|
||||
person = Person()
|
||||
return {
|
||||
"username": person.username(),
|
||||
"email": person.email(),
|
||||
"password": "SecurePass123!",
|
||||
}
|
||||
0
tests/integration/__init__.py
Normal file
0
tests/integration/__init__.py
Normal file
18
tests/integration/conftest.py
Normal file
18
tests/integration/conftest.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Integration test fixtures
|
||||
# Provides: test database, external service connections
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_db_connection():
|
||||
"""Create test database connection."""
|
||||
# TODO: Implement when DB is added to project
|
||||
yield "test_db"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cleanup_db():
|
||||
"""Cleanup database after test."""
|
||||
yield
|
||||
# TODO: Implement cleanup logic
|
||||
0
tests/unit/__init__.py
Normal file
0
tests/unit/__init__.py
Normal file
18
tests/unit/conftest.py
Normal file
18
tests/unit/conftest.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Unit test fixtures
|
||||
# Provides: mocks, stubs, isolated test data
|
||||
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_service():
|
||||
"""Create a mock service for unit testing."""
|
||||
return Mock()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_async_service():
|
||||
"""Create an async mock service for unit testing."""
|
||||
return AsyncMock()
|
||||
33
tests/unit/test_unit_app_run.py
Normal file
33
tests/unit/test_unit_app_run.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
|
||||
from app.main import app_factory, lifespan, main
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_lifespan():
|
||||
app = FastAPI()
|
||||
assert isinstance(lifespan, asynccontextmanager(lifespan).__class__)
|
||||
|
||||
async with lifespan(app):
|
||||
pass
|
||||
|
||||
|
||||
def test_app_factory():
|
||||
app = app_factory()
|
||||
assert isinstance(app, FastAPI)
|
||||
assert app.router.lifespan_context == lifespan
|
||||
|
||||
|
||||
@patch("app.main.uvicorn.run")
|
||||
def test_main(mock_uvicorn_run):
|
||||
main()
|
||||
mock_uvicorn_run.assert_called_once_with(
|
||||
app_factory,
|
||||
factory=True,
|
||||
host="0.0.0.0",
|
||||
port=8000,
|
||||
)
|
||||
Reference in New Issue
Block a user