mirror of
https://github.com/ZhuLinsen/daily_stock_analysis
synced 2026-09-20 10:53:33 +08:00
* fix(api): return json from root health endpoint * test(web): stabilize vitest runtime setup * chore(security): warn on public web exposure without auth * refactor(api): centralize error response helpers * chore(db): record baseline schema version * refactor(web): extract portfolio formatting helpers * fix(db): make schema baseline initialization idempotent * docs: document health check and schema baseline changes
33 lines
936 B
Python
33 lines
936 B
Python
# -*- coding: utf-8 -*-
|
|
"""Tests for shared API error helpers."""
|
|
|
|
from fastapi import HTTPException
|
|
|
|
from api.v1.errors import api_error, error_body, error_json_response
|
|
|
|
|
|
def test_error_body_omits_empty_detail() -> None:
|
|
assert error_body("validation_error", "bad input") == {
|
|
"error": "validation_error",
|
|
"message": "bad input",
|
|
}
|
|
|
|
|
|
def test_api_error_uses_standard_detail_shape() -> None:
|
|
exc = api_error(404, "not_found", "missing", detail={"id": 1})
|
|
|
|
assert isinstance(exc, HTTPException)
|
|
assert exc.status_code == 404
|
|
assert exc.detail == {
|
|
"error": "not_found",
|
|
"message": "missing",
|
|
"detail": {"id": 1},
|
|
}
|
|
|
|
|
|
def test_error_json_response_uses_standard_content() -> None:
|
|
response = error_json_response(409, "conflict", "already exists")
|
|
|
|
assert response.status_code == 409
|
|
assert response.body == b'{"error":"conflict","message":"already exists"}'
|