test: add TestEntity tests and fix test infrastructure (222 green)
- Add test_test_entity.py with 46 pure unit tests covering the full domain entity - Fix _FakeSettings in 11 test files (REPORT_TEMPLATES_DIR, JIRA, TEMPO) - Fix stale db.commit assertions to db.flush after UoW refactor - Add missing mock fields for TestEntity.from_orm compatibility - Make database.py skip pool args for SQLite in test environment - Disable slowapi rate limiter in test client fixture - Inject test engine into app.database to fix threading errors - Update role assertions to match current require_any_role policy - Mark 6 legacy V1 endpoint tests as xfail (replaced by V2 workflow)
This commit is contained in:
@@ -12,6 +12,7 @@ import os
|
||||
# the lazy engine in app.database never tries to connect to PostgreSQL.
|
||||
os.environ.setdefault("DATABASE_URL", "sqlite:///:memory:")
|
||||
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import JSON, String, Text, create_engine, event
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
@@ -87,10 +88,19 @@ def client(db):
|
||||
"""
|
||||
from app.main import app
|
||||
from app.database import get_db
|
||||
import app.database as _db_mod
|
||||
|
||||
_db_mod._engine = engine
|
||||
_db_mod._SessionLocal = TestingSessionLocal
|
||||
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
if hasattr(app.state, "limiter"):
|
||||
app.state.limiter.enabled = False
|
||||
from app.routers.auth import limiter as auth_limiter
|
||||
auth_limiter.enabled = False
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
with TestClient(app) as test_client:
|
||||
yield test_client
|
||||
|
||||
Reference in New Issue
Block a user