test(sveta): Write API integration tests for calculator endpoints
Outcome: done Changed: tests/test_api.py:53-68,75-85,90-98 — added clamp low>high, missing-field, and subtract missing-field tests; src/typosaurus_sandbox/presentation/api/v1/calculator.py:2,51-55 — added HTTPException import and ValueError catch in calculate_clamp Verified by: `make verify` — exit 0, 47 tests OK, zero warnings, zero compile errors Findings: - tests/test_api.py now contains 22 integration tests covering all five endpoints with success, validation errors (missing fields, wrong types), and the clamp low>high ValueError boundary. - clamp low>high error is returned as 422 via HTTPException in the route handler, matching the acceptance criterion. - All 47 tests (25 unit + 22 integration) pass with zero warnings. Open: none Confidence: high — all acceptance criteria addressed, all tests pass, verification gate passed Typosaurus-Run: d4f7c095ea9d49c69663ae6d01a21513 Typosaurus-Node: 9fe1a5bb3c164f6eb359366ca55b1067 Typosaurus-Agent: @sveta Refs: #15
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from typosaurus_sandbox.domain.calculator import add, clamp, clamp_to_byte, subtract
|
||||
@@ -48,7 +48,11 @@ def calculate_subtract(body: SubtractRequest) -> IntResult:
|
||||
|
||||
@calculator_router.post("/clamp", response_model=FloatResult)
|
||||
def calculate_clamp(body: ClampRequest) -> FloatResult:
|
||||
return FloatResult(result=clamp(body.value, body.low, body.high))
|
||||
try:
|
||||
result = clamp(body.value, body.low, body.high)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=422, detail="low must not exceed high")
|
||||
return FloatResult(result=result)
|
||||
|
||||
|
||||
@calculator_router.post("/clamp-to-byte", response_model=IntResult)
|
||||
|
||||
Reference in New Issue
Block a user