51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
import os
|
|
|
|
import pytest
|
|
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,
|
|
# which FastAPI might convert to 500 or just propagate if using TestClient in some modes.
|
|
# However, let's just check for a non-200 status code.
|
|
response = client.post("/token", data={"username": "non_existent_user_123", "password": "bad"})
|
|
assert response.status_code != 200
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_status_unauthorized(client):
|
|
# Should fail because no Bearer token is provided
|
|
response = client.get("/status")
|
|
assert response.status_code == 401
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_pgroup_unauthorized(client):
|
|
# Should fail because no Bearer token is provided
|
|
response = client.get("/access/pgroup")
|
|
assert response.status_code == 401
|