Test Overview
This test checks if a Postman mock server is created successfully and responds with the expected mock data when a request is sent.
This test checks if a Postman mock server is created successfully and responds with the expected mock data when a request is sent.
import requests # Step 1: Create a mock server via Postman API mock_server_creation_url = "https://api.getpostman.com/mocks" headers = {"X-Api-Key": "{{POSTMAN_API_KEY}}", "Content-Type": "application/json"} mock_server_payload = { "mock": { "name": "Test Mock Server", "collection": { "uid": "{{COLLECTION_UID}}" } } } response_create = requests.post(mock_server_creation_url, json=mock_server_payload, headers=headers) assert response_create.status_code == 200, f"Failed to create mock server: {response_create.text}" mock_url = response_create.json()["mock"]["mockUrl"] # Step 2: Send a GET request to the mock server response_mock = requests.get(mock_url + "/test-endpoint") # Step 3: Verify the response status and body assert response_mock.status_code == 200, f"Unexpected status code: {response_mock.status_code}" expected_body = {"message": "Hello from mock server!"} assert response_mock.json() == expected_body, f"Response body mismatch: {response_mock.json()}"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send POST request to Postman API to create a mock server | Postman API receives request to create mock server with given collection and name | Check response status code is 200 (OK) | PASS |
| 2 | Extract mock server URL from creation response | Mock server URL is available for sending requests | - | PASS |
| 3 | Send GET request to mock server endpoint '/test-endpoint' | Mock server receives request and returns predefined mock response | Verify response status code is 200 | PASS |
| 4 | Verify response JSON body matches expected mock data | Response body contains {"message": "Hello from mock server!"} | Assert response JSON equals expected body | PASS |