-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
65 lines (46 loc) · 1.61 KB
/
Copy pathtest_app.py
File metadata and controls
65 lines (46 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pytest
from app import app, reset_items
@pytest.fixture
def client():
app.config["TESTING"] = True
with app.test_client() as client:
reset_items()
yield client
def test_health(client):
resp = client.get("/health")
assert resp.status_code == 200
data = resp.get_json()
assert data["status"] == "ok"
assert "timestamp" in data
assert data["version"] == "0.1.0"
def test_list_items_empty(client):
resp = client.get("/items")
assert resp.status_code == 200
assert resp.get_json()["items"] == []
def test_create_item(client):
resp = client.post("/items", json={"name": "Write tests"})
assert resp.status_code == 201
data = resp.get_json()
assert data["name"] == "Write tests"
assert data["done"] is False
assert data["id"] == 1
def test_create_item_missing_name(client):
resp = client.post("/items", json={})
assert resp.status_code == 400
def test_update_item(client):
client.post("/items", json={"name": "Task 1"})
resp = client.patch("/items/1", json={"done": True})
assert resp.status_code == 200
assert resp.get_json()["done"] is True
def test_update_item_not_found(client):
resp = client.patch("/items/999", json={"done": True})
assert resp.status_code == 404
def test_delete_item(client):
client.post("/items", json={"name": "To delete"})
resp = client.delete("/items/1")
assert resp.status_code == 204
resp = client.get("/items")
assert resp.get_json()["items"] == []
def test_delete_item_not_found(client):
resp = client.delete("/items/999")
assert resp.status_code == 404