32 lines
1.5 KiB
Python
32 lines
1.5 KiB
Python
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
|