DEV Community

Fiyinfoluwa Ojo
Fiyinfoluwa Ojo

Posted on

Capstone Day 2: Testing the To-Do App API with Pytest

Why Test the Capstone?

Every feature I add could break an existing one.
Automated tests catch that instantly.
no manual Postman testing needed.

10 Tests Covering Everything

Auth Tests

  • Signup success
  • Duplicate email returns 400
  • Login success returns accessToken
  • Wrong password returns 401

Task Tests

  • Create task returns 201
  • Get tasks returns data array
  • Update task marks as completed
  • Delete task returns 204
  • Get tasks without token returns 401
  • Create task without title returns 422

Key Test Pattern

def get_token():
    email = f"taskuser{int(time.time())}@example.com"
    client.post("/auth/signup", json={
        "email": email, "password": "password123"
    })
    response = client.post("/auth/login", json={
        "email": email, "password": "password123"
    })
    return response.json()["accessToken"]

Enter fullscreen mode Exit fullscreen mode

Every task test creates its own user and token,
tests are completely isolated from each other.

Results

Results

10 passed, 0 failed. ✅

Lessons Learned

Testing a capstone project is different from
testing isolated endpoints : you need to test
the full flow: signup -> login -> create -> update -> delete.
That's what real integration testing looks like.

Day 27 done. 3 more to go. 🔥

GDGoCBowen30dayChallenge

Top comments (0)