Zion Boggan
repos/Secure CI/CD Pipeline/tests/test_app.py
zionboggan.com ↗
44 lines · python
History for this file →
1
import pytest
2
 
3
from app.app import app, store
4
 
5
 
6
@pytest.fixture
7
def client():
8
    app.config["TESTING"] = True
9
    with app.test_client() as client:
10
        yield client
11
    store._tasks.clear()
12
 
13
 
14
def test_health(client):
15
    resp = client.get("/health")
16
    assert resp.status_code == 200
17
    assert resp.get_json()["status"] == "ok"
18
 
19
 
20
def test_create_and_fetch(client):
21
    resp = client.post("/tasks", json={"title": "review pipeline"})
22
    assert resp.status_code == 201
23
    task = resp.get_json()["task"]
24
    assert task["title"] == "review pipeline"
25
    assert task["done"] is False
26
 
27
    fetched = client.get(f"/tasks/{task['id']}")
28
    assert fetched.status_code == 200
29
    assert fetched.get_json()["task"]["id"] == task["id"]
30
 
31
 
32
def test_create_requires_title(client):
33
    resp = client.post("/tasks", json={})
34
    assert resp.status_code == 400
35
 
36
 
37
def test_delete(client):
38
    created = client.post("/tasks", json={"title": "temp"}).get_json()["task"]
39
    assert client.delete(f"/tasks/{created['id']}").status_code == 204
40
    assert client.get(f"/tasks/{created['id']}").status_code == 404
41
 
42
 
43
def test_missing_task(client):
44
    assert client.get("/tasks/999").status_code == 404