refactor: consolidate get_db into single module
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
+3
-6
@@ -63,9 +63,8 @@ def db_session():
|
||||
def client(db_session) -> TestClient:
|
||||
"""Create a test client with a fresh database."""
|
||||
|
||||
# Import all the different get_db functions used across the app
|
||||
from app.api.common import get_db as api_get_db
|
||||
from app.views.base import get_db as views_get_db
|
||||
# Import the canonical get_db function
|
||||
from app.database import get_db
|
||||
|
||||
# Override the get_db dependency to use our test database
|
||||
def override_get_db():
|
||||
@@ -74,10 +73,8 @@ def client(db_session) -> TestClient:
|
||||
finally:
|
||||
pass
|
||||
|
||||
# Override all variants of get_db
|
||||
# Override the single canonical get_db dependency
|
||||
fastapi_app.dependency_overrides[get_db] = override_get_db
|
||||
fastapi_app.dependency_overrides[api_get_db] = override_get_db
|
||||
fastapi_app.dependency_overrides[views_get_db] = override_get_db
|
||||
|
||||
# Use base_url to satisfy TrustedHostMiddleware
|
||||
with TestClient(fastapi_app, base_url="http://localhost") as test_client:
|
||||
|
||||
Reference in New Issue
Block a user