31 lines
650 B
Python
31 lines
650 B
Python
"""Shared test fixtures."""
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.database import get_db
|
|
from app.main import app
|
|
|
|
|
|
@pytest.fixture()
|
|
def db_session():
|
|
"""Provide a mocked database session."""
|
|
session = MagicMock(spec=Session)
|
|
return session
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(db_session):
|
|
"""Provide a FastAPI test client with mocked DB."""
|
|
|
|
def _override_get_db():
|
|
yield db_session
|
|
|
|
app.dependency_overrides[get_db] = _override_get_db
|
|
with TestClient(app) as c:
|
|
yield c
|
|
app.dependency_overrides.clear()
|