decomposer: generate deliverable files for Implement the task REST API service with FastAPI, including standard CRUD endpoints, HTTP status semantics, request and response models, and structured error handling.; Add a PostgreSQL persistence layer for the task service using SQLAlchemy models, session management, database initialization or migrations, and durable task storage integrated with the existing API contract.; Define and integrate Pydantic request and response schemas for task fields, status values, identifiers, timestamps, and validation errors across the existing FastAPI service and persistence contract.; Add automated pytest coverage for the task API, including CRUD behavior, request and response validation failures, HTTP status semantics, and persistence interactions using isolated test data.; Containerize the FastAPI task service and PostgreSQL persistence service with Docker Compose, including environment-based configuration, health checks, networking, startup dependencies, and persistent database storage.; Create project documentation and operational guidance covering local setup, Docker Compose configuration, environment variables, API endpoints, validation and error responses, testing commands, persistence behavior, and relevant best-practice notes.
This commit is contained in:
31
tests/test_tasks.py
Normal file
31
tests/test_tasks.py
Normal file
@@ -0,0 +1,31 @@
|
||||
def test_crud_and_persistence(client):
|
||||
response = client.post('/tasks', json={'title': 'Ship API', 'description': 'release it'})
|
||||
assert response.status_code == 201
|
||||
task = response.json()
|
||||
assert task['status'] == 'pending'
|
||||
task_id = task['id']
|
||||
|
||||
assert client.get('/tasks').status_code == 200
|
||||
assert client.get(f'/tasks/{task_id}').json()['title'] == 'Ship API'
|
||||
updated = client.patch(f'/tasks/{task_id}', json={'status': 'completed'}).json()
|
||||
assert updated['status'] == 'completed'
|
||||
assert client.delete(f'/tasks/{task_id}').status_code == 204
|
||||
assert client.get(f'/tasks/{task_id}').status_code == 404
|
||||
|
||||
|
||||
def test_validation_and_status_semantics(client):
|
||||
result = client.post('/tasks', json={'title': ' '})
|
||||
assert result.status_code == 422
|
||||
assert result.json()['error']['code'] == 'VALIDATION_ERROR'
|
||||
assert client.post('/tasks', json={'title': 'x', 'status': 'unknown'}).status_code == 422
|
||||
assert client.get('/tasks/not-a-uuid').status_code == 422
|
||||
assert client.get('/tasks?limit=0').status_code == 422
|
||||
|
||||
|
||||
def test_filter_and_missing_resource(client):
|
||||
client.post('/tasks', json={'title': 'one', 'status': 'completed'})
|
||||
client.post('/tasks', json={'title': 'two', 'status': 'pending'})
|
||||
response = client.get('/tasks?status=completed')
|
||||
assert response.status_code == 200
|
||||
assert len(response.json()) == 1
|
||||
assert client.patch('/tasks/00000000-0000-0000-0000-000000000000', json={'title': 'x'}).status_code == 404
|
||||
Reference in New Issue
Block a user