import pytest import os from fastapi.testclient import TestClient # We need to set the environment variable before importing the app os.environ["JWT_AAREDAQ_KEY"] = "test_key_for_integration_testing" from aare.daq.server import app @pytest.fixture def client(): # We use a TestClient to interact with the FastAPI app # Note: Many endpoints require authentication and a running backend (daq, bl, etc.) # For a simple integration test, we can check public endpoints. return TestClient(app) @pytest.mark.integration def test_read_error_codes(client): response = client.get("/meta/error-codes") assert response.status_code == 200 data = response.json() assert "AuthErrorCode" in data assert "AareErrorCode" in data @pytest.mark.integration def test_login_unauthorized(client): # Testing login with invalid credentials. # The current implementation raises KeyError if user not found. with pytest.raises(Exception): client.post("/token", data={"username": "non_existent_user_123", "password": "bad"})