feat(nadia): Implement FastAPI application with calculator endpoints
```yaml
Outcome: done
Changed:
- pyproject.toml:1-18
- src/typosaurus_sandbox/__init__.py:1-4
- src/typosaurus_sandbox/__main__.py:1-8
- src/typosaurus_sandbox/app.py:1-18
- src/typosaurus_sandbox/domain/__init__.py:1-1
- src/typosaurus_sandbox/domain/calculator/__init__.py:1-6
- src/typosaurus_sandbox/domain/calculator/operations.py:1-23
- src/typosaurus_sandbox/presentation/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/calculator.py:1-63
- tests/__init__.py (unchanged)
- tests/test_calculator.py:1-95
- tests/test_api.py:1-120
- Makefile:2
- CLAUDE.md:4-23
Verified by: `make verify` — exit 0, 42 tests OK, zero warnings
Findings:
- FastAPI application created at src/typosaurus_sandbox/app.py with App importable as `from typosaurus_sandbox import App`.
- Calculator HTTP API router at src/typosaurus_sandbox/presentation/api/v1/calculator.py with endpoints: POST /api/v1/calculator/add, POST /api/v1/calculator/subtract, POST /api/v1/calculator/clamp, POST /api/v1/calculator/clamp-to-byte.
- Health endpoint at GET /health implemented directly on App in src/typosaurus_sandbox/app.py.
- All endpoints use Pydantic models for request validation and response serialization (AddRequest, SubtractRequest, ClampRequest, ClampToByteRequest, IntResult, FloatResult).
- 42 tests pass (16 unit tests for calculator function
Typosaurus-Run: d4f7c095ea9d49c69663ae6d01a21513
Typosaurus-Node: d0f507214bf6453cab8f8d19b8fd2040
Typosaurus-Agent: @nadia
Refs: #15
2026-07-26 18:38:43 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
|
|
|
|
from typosaurus_sandbox.app import App
|
|
|
|
|
|
|
|
|
|
client = TestClient(App)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestHealthEndpoint(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_health_returns_ok(self) -> None:
|
|
|
|
|
response = client.get("/health")
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"status": "ok"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCalculatorAddEndpoint(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_add_positive_integers(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/add", json={"left": 3, "right": 5})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": 8})
|
|
|
|
|
|
|
|
|
|
def test_add_negative_integers(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/add", json={"left": -3, "right": -5})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": -8})
|
|
|
|
|
|
|
|
|
|
def test_add_invalid_input_returns_422(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/add", json={"left": "abc", "right": 5})
|
|
|
|
|
self.assertEqual(response.status_code, 422)
|
|
|
|
|
|
|
|
|
|
def test_add_missing_field_returns_422(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/add", json={"left": 3})
|
|
|
|
|
self.assertEqual(response.status_code, 422)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCalculatorSubtractEndpoint(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_subtract_positive(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/subtract", json={"left": 10, "right": 3})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": 7})
|
|
|
|
|
|
|
|
|
|
def test_subtract_negative_result(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/subtract", json={"left": 3, "right": 10})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": -7})
|
|
|
|
|
|
|
|
|
|
def test_subtract_invalid_input_returns_422(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/subtract", json={"left": 10, "right": None})
|
|
|
|
|
self.assertEqual(response.status_code, 422)
|
|
|
|
|
|
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
2026-07-26 18:40:14 +02:00
|
|
|
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)
|
|
|
|
|
|
feat(nadia): Implement FastAPI application with calculator endpoints
```yaml
Outcome: done
Changed:
- pyproject.toml:1-18
- src/typosaurus_sandbox/__init__.py:1-4
- src/typosaurus_sandbox/__main__.py:1-8
- src/typosaurus_sandbox/app.py:1-18
- src/typosaurus_sandbox/domain/__init__.py:1-1
- src/typosaurus_sandbox/domain/calculator/__init__.py:1-6
- src/typosaurus_sandbox/domain/calculator/operations.py:1-23
- src/typosaurus_sandbox/presentation/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/calculator.py:1-63
- tests/__init__.py (unchanged)
- tests/test_calculator.py:1-95
- tests/test_api.py:1-120
- Makefile:2
- CLAUDE.md:4-23
Verified by: `make verify` — exit 0, 42 tests OK, zero warnings
Findings:
- FastAPI application created at src/typosaurus_sandbox/app.py with App importable as `from typosaurus_sandbox import App`.
- Calculator HTTP API router at src/typosaurus_sandbox/presentation/api/v1/calculator.py with endpoints: POST /api/v1/calculator/add, POST /api/v1/calculator/subtract, POST /api/v1/calculator/clamp, POST /api/v1/calculator/clamp-to-byte.
- Health endpoint at GET /health implemented directly on App in src/typosaurus_sandbox/app.py.
- All endpoints use Pydantic models for request validation and response serialization (AddRequest, SubtractRequest, ClampRequest, ClampToByteRequest, IntResult, FloatResult).
- 42 tests pass (16 unit tests for calculator function
Typosaurus-Run: d4f7c095ea9d49c69663ae6d01a21513
Typosaurus-Node: d0f507214bf6453cab8f8d19b8fd2040
Typosaurus-Agent: @nadia
Refs: #15
2026-07-26 18:38:43 +02:00
|
|
|
|
|
|
|
|
class TestCalculatorClampEndpoint(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_clamp_value_below_low(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/clamp", json={"value": -5, "low": 0, "high": 10})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": 0})
|
|
|
|
|
|
|
|
|
|
def test_clamp_value_above_high(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/clamp", json={"value": 15, "low": 0, "high": 10})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": 10})
|
|
|
|
|
|
|
|
|
|
def test_clamp_value_in_range(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/clamp", json={"value": 5, "low": 0, "high": 10})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": 5.0})
|
|
|
|
|
|
|
|
|
|
def test_clamp_invalid_input_returns_422(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/clamp", json={"value": "x", "low": 0, "high": 10})
|
|
|
|
|
self.assertEqual(response.status_code, 422)
|
|
|
|
|
|
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
2026-07-26 18:40:14 +02:00
|
|
|
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)
|
|
|
|
|
|
feat(nadia): Implement FastAPI application with calculator endpoints
```yaml
Outcome: done
Changed:
- pyproject.toml:1-18
- src/typosaurus_sandbox/__init__.py:1-4
- src/typosaurus_sandbox/__main__.py:1-8
- src/typosaurus_sandbox/app.py:1-18
- src/typosaurus_sandbox/domain/__init__.py:1-1
- src/typosaurus_sandbox/domain/calculator/__init__.py:1-6
- src/typosaurus_sandbox/domain/calculator/operations.py:1-23
- src/typosaurus_sandbox/presentation/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/calculator.py:1-63
- tests/__init__.py (unchanged)
- tests/test_calculator.py:1-95
- tests/test_api.py:1-120
- Makefile:2
- CLAUDE.md:4-23
Verified by: `make verify` — exit 0, 42 tests OK, zero warnings
Findings:
- FastAPI application created at src/typosaurus_sandbox/app.py with App importable as `from typosaurus_sandbox import App`.
- Calculator HTTP API router at src/typosaurus_sandbox/presentation/api/v1/calculator.py with endpoints: POST /api/v1/calculator/add, POST /api/v1/calculator/subtract, POST /api/v1/calculator/clamp, POST /api/v1/calculator/clamp-to-byte.
- Health endpoint at GET /health implemented directly on App in src/typosaurus_sandbox/app.py.
- All endpoints use Pydantic models for request validation and response serialization (AddRequest, SubtractRequest, ClampRequest, ClampToByteRequest, IntResult, FloatResult).
- 42 tests pass (16 unit tests for calculator function
Typosaurus-Run: d4f7c095ea9d49c69663ae6d01a21513
Typosaurus-Node: d0f507214bf6453cab8f8d19b8fd2040
Typosaurus-Agent: @nadia
Refs: #15
2026-07-26 18:38:43 +02:00
|
|
|
|
|
|
|
|
class TestCalculatorClampToByteEndpoint(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_clamp_to_byte_within_range(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/clamp-to-byte", json={"value": 128})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": 128})
|
|
|
|
|
|
|
|
|
|
def test_clamp_to_byte_below_zero(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/clamp-to-byte", json={"value": -10})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": 0})
|
|
|
|
|
|
|
|
|
|
def test_clamp_to_byte_above_255(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/clamp-to-byte", json={"value": 300})
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json(), {"result": 255})
|
|
|
|
|
|
|
|
|
|
def test_clamp_to_byte_invalid_input_returns_422(self) -> None:
|
|
|
|
|
response = client.post("/api/v1/calculator/clamp-to-byte", json={"value": "abc"})
|
|
|
|
|
self.assertEqual(response.status_code, 422)
|