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:
@@ -54,6 +54,14 @@ class TestCalculatorSubtractEndpoint(unittest.TestCase):
|
||||
response = client.post("/api/v1/calculator/subtract", json={"left": 10, "right": None})
|
||||
self.assertEqual(response.status_code, 422)
|
||||
|
||||
def test_subtract_missing_left_returns_422(self) -> None:
|
||||
response = client.post("/api/v1/calculator/subtract", json={"right": 3})
|
||||
self.assertEqual(response.status_code, 422)
|
||||
|
||||
def test_subtract_missing_right_returns_422(self) -> None:
|
||||
response = client.post("/api/v1/calculator/subtract", json={"left": 10})
|
||||
self.assertEqual(response.status_code, 422)
|
||||
|
||||
|
||||
class TestCalculatorClampEndpoint(unittest.TestCase):
|
||||
|
||||
@@ -76,6 +84,18 @@ class TestCalculatorClampEndpoint(unittest.TestCase):
|
||||
response = client.post("/api/v1/calculator/clamp", json={"value": "x", "low": 0, "high": 10})
|
||||
self.assertEqual(response.status_code, 422)
|
||||
|
||||
def test_clamp_low_greater_than_high_returns_422(self) -> None:
|
||||
response = client.post("/api/v1/calculator/clamp", json={"value": 5, "low": 10, "high": 0})
|
||||
self.assertEqual(response.status_code, 422)
|
||||
|
||||
def test_clamp_missing_low_returns_422(self) -> None:
|
||||
response = client.post("/api/v1/calculator/clamp", json={"value": 5, "high": 10})
|
||||
self.assertEqual(response.status_code, 422)
|
||||
|
||||
def test_clamp_missing_high_returns_422(self) -> None:
|
||||
response = client.post("/api/v1/calculator/clamp", json={"value": 5, "low": 0})
|
||||
self.assertEqual(response.status_code, 422)
|
||||
|
||||
|
||||
class TestCalculatorClampToByteEndpoint(unittest.TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user