diff --git a/tests/conftest.py b/tests/conftest.py index 87722481..27a6f750 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,10 +10,10 @@ from dotenv import load_dotenv # Load environment variables load_dotenv() -# Force no-auth mode for testing by removing OAuth credentials +# Force no-auth mode for testing by setting OAuth credentials to empty strings # This ensures anonymous JWT tokens are created automatically -os.environ.pop('GOOGLE_OAUTH_CLIENT_ID', None) -os.environ.pop('GOOGLE_OAUTH_CLIENT_SECRET', None) +os.environ['GOOGLE_OAUTH_CLIENT_ID'] = '' +os.environ['GOOGLE_OAUTH_CLIENT_SECRET'] = '' from src.config.settings import clients from src.session_manager import SessionManager diff --git a/tests/integration/test_api_endpoints.py b/tests/integration/test_api_endpoints.py index 60810563..20f57d55 100644 --- a/tests/integration/test_api_endpoints.py +++ b/tests/integration/test_api_endpoints.py @@ -50,6 +50,7 @@ async def test_upload_and_search_endpoint(tmp_path: Path, disable_langflow_inges "src.api.router", "src.api.connector_router", "src.config.settings", + "src.auth_middleware", "src.main", ]: sys.modules.pop(mod, None) @@ -68,7 +69,11 @@ async def test_upload_and_search_endpoint(tmp_path: Path, disable_langflow_inges app = await create_app() # Manually run startup tasks since httpx ASGI transport here doesn't manage lifespan await startup_tasks(app.state.services) - + + # Ensure index exists for tests (startup_tasks only creates it if DISABLE_INGEST_WITH_LANGFLOW=True) + from src.main import _ensure_opensearch_index + await _ensure_opensearch_index() + # Verify index is truly empty after startup try: count_response = await clients.opensearch.count(index=INDEX_NAME) @@ -159,6 +164,7 @@ async def test_router_upload_ingest_traditional(tmp_path: Path, disable_langflow "src.api.router", "src.api.connector_router", "src.config.settings", + "src.auth_middleware", "src.main", ]: sys.modules.pop(mod, None) @@ -176,7 +182,11 @@ async def test_router_upload_ingest_traditional(tmp_path: Path, disable_langflow app = await create_app() await startup_tasks(app.state.services) - + + # Ensure index exists for tests (startup_tasks only creates it if DISABLE_INGEST_WITH_LANGFLOW=True) + from src.main import _ensure_opensearch_index + await _ensure_opensearch_index() + # Verify index is truly empty after startup try: count_response = await clients.opensearch.count(index=INDEX_NAME) diff --git a/tests/integration/test_startup_ingest.py b/tests/integration/test_startup_ingest.py index 436c4d28..b2243b33 100644 --- a/tests/integration/test_startup_ingest.py +++ b/tests/integration/test_startup_ingest.py @@ -51,6 +51,7 @@ async def test_startup_ingest_creates_task(disable_langflow_ingest: bool): "src.api.router", "src.api.connector_router", "src.config.settings", + "src.auth_middleware", "src.main", ]: sys.modules.pop(mod, None) @@ -69,6 +70,10 @@ async def test_startup_ingest_creates_task(disable_langflow_ingest: bool): # Trigger startup tasks explicitly await startup_tasks(app.state.services) + # Ensure index exists for tests (startup_tasks only creates it if DISABLE_INGEST_WITH_LANGFLOW=True) + from src.main import _ensure_opensearch_index + await _ensure_opensearch_index() + transport = httpx.ASGITransport(app=app) try: async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client: