tests: added tests for daq_server, error_codes, exception_handler and tell_client
This commit is contained in:
1 parent
e5ffbb9b18
commit
c233bd333d
4 files changed
+211
No files matched your search
@@ -0,0 +1,30 @@
|
||||
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 "DAQErrorCode" 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"})
|
||||
Reference in new issue
Block a user