39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
|
|
"""Tests for structured error codes."""
|
||
|
|
|
||
|
|
from fusionagi.api.error_codes import (
|
||
|
|
ErrorCode,
|
||
|
|
error_json_response,
|
||
|
|
error_response,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_error_codes_unique():
|
||
|
|
"""All error codes should have unique values."""
|
||
|
|
values = [e.value for e in ErrorCode]
|
||
|
|
assert len(values) == len(set(values))
|
||
|
|
|
||
|
|
|
||
|
|
def test_error_response_basic():
|
||
|
|
"""error_response should return structured dict."""
|
||
|
|
resp = error_response(ErrorCode.AUTH_MISSING)
|
||
|
|
assert resp["error"]["code"] == "FAGI-1001"
|
||
|
|
assert "Authentication" in resp["error"]["message"]
|
||
|
|
|
||
|
|
|
||
|
|
def test_error_response_custom_detail():
|
||
|
|
"""Custom detail should override default message."""
|
||
|
|
resp = error_response(ErrorCode.INTERNAL_ERROR, detail="Custom error")
|
||
|
|
assert resp["error"]["message"] == "Custom error"
|
||
|
|
|
||
|
|
|
||
|
|
def test_error_response_extra():
|
||
|
|
"""Extra data should appear in details."""
|
||
|
|
resp = error_response(ErrorCode.INPUT_INVALID, extra={"field": "prompt"})
|
||
|
|
assert resp["error"]["details"]["field"] == "prompt"
|
||
|
|
|
||
|
|
|
||
|
|
def test_error_json_response():
|
||
|
|
"""error_json_response should return a JSONResponse."""
|
||
|
|
r = error_json_response(ErrorCode.SESSION_NOT_FOUND, status_code=404)
|
||
|
|
assert r.status_code == 404
|