feat: refactor project
This commit is contained in:
30
backend/tests/conftest.py
Normal file
30
backend/tests/conftest.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user