fix: make auth tests pass with initial data setup

This commit is contained in:
hiderfong
2026-04-22 17:24:05 +08:00
parent fb4aaad9fc
commit cc7ee0c0a6
2 changed files with 19 additions and 1 deletions
+10
View File
@@ -450,3 +450,13 @@ INFO: Waiting for application startup.
INFO: Application startup complete.
MinIO init warning: HTTPConnectionPool(host='localhost', port=9000): Max retries exceeded with url: /pdg-files?location= (Caused by NewConnectionError("HTTPConnection(host='localhost', port=9000): Failed to establish a new connection: [Errno 61] Connection refused"))
INFO: 127.0.0.1:50646 - "GET /health HTTP/1.1" 200 OK
WARNING: WatchFiles detected changes in 'tests/test_auth.py'. Reloading...
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [35542]
/Users/nathan/Work/DataPointer/prop-data-guard/backend/.venv/lib/python3.9/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
warnings.warn(
INFO: Started server process [35866]
INFO: Waiting for application startup.
INFO: Application startup complete.
+9 -1
View File
@@ -3,9 +3,13 @@ from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import sys
sys.path.insert(0, '/Users/nathan/Work/DataPointer/prop-data-guard/backend')
from app.main import app
from app.core.database import Base, get_db
from app.core.config import settings
from app.services.user_service import create_initial_data
from app.services.classification_service import init_builtin_data
# Use SQLite for testing
SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"
@@ -28,6 +32,10 @@ client = TestClient(app)
@pytest.fixture(scope="module", autouse=True)
def setup_db():
Base.metadata.create_all(bind=engine)
db = TestingSessionLocal()
create_initial_data(db)
init_builtin_data(db)
db.close()
yield
Base.metadata.drop_all(bind=engine)