Test Overview
This test checks if the API client correctly fetches user data from a web service and verifies the response content.
This test checks if the API client correctly fetches user data from a web service and verifies the response content.
import requests import pytest def get_user(user_id): response = requests.get(f"https://jsonplaceholder.typicode.com/users/{user_id}") response.raise_for_status() return response.json() def test_get_user(): user = get_user(1) assert user["id"] == 1 assert user["username"] == "Bret" assert "email" in user
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | - | PASS |
| 2 | Calls get_user(1) which sends GET request to https://jsonplaceholder.typicode.com/users/1 | HTTP request sent to API server | - | PASS |
| 3 | Receives HTTP 200 OK response with JSON user data | Response JSON: {"id":1,"username":"Bret","email":"Sincere@april.biz", ...} | - | PASS |
| 4 | Asserts user["id"] == 1 | User data loaded in memory | Check if user id equals 1 | PASS |
| 5 | Asserts user["username"] == "Bret" | User data loaded in memory | Check if username is 'Bret' | PASS |
| 6 | Asserts "email" key exists in user data | User data loaded in memory | Check if 'email' field is present | PASS |
| 7 | Test ends successfully | All assertions passed | - | PASS |