|
1 | 1 | """ |
2 | | -test_api_validation.py |
3 | | -
|
4 | | -Test with allure.step("Send GET request to /users?page=1 with retry resilience"): |
5 | | - try: |
6 | | - url = f"{base_url}/users?page=1" |
7 | | - response = make_resilient_get_request(url, headers=get_headers(), timeout=10) |
8 | | - log_request_response(response) # Enhanced logging |
9 | | - except requests.exceptions.RequestException as e: |
10 | | - allure.attach(str(e), "Request Error", allure.attachment_type.TEXT) |
11 | | - raise |
12 | | -
|
13 | | - with allure.step("Verify response status is 200"):cused on API contract validation and da with allure.step("Send GET request to /users?page=1"): |
14 | | - url = f"{base_url}/users?page=1" |
15 | | - response = requests.get(url, headers=get_headers()) |
16 | | - log_request_response(response) # Enhanced logging |
17 | | -
|
18 | | - with allure.step("Verify response status is 200"):tegrity. |
19 | | -Covers schema validation, header validation, and response format testing. |
| 2 | +test_api_validation.py - API Contract Testing |
| 3 | +
|
| 4 | +This module implements contract tests for the ReqRes API, focusing on: |
| 5 | +1. Schema Validation: Ensures API responses match defined JSON schemas |
| 6 | +2. Header Validation: Verifies correct content types and response headers |
| 7 | +3. Response Format: Validates data structure and field types |
| 8 | +4. Error Handling: Tests API error responses and status codes |
| 9 | +
|
| 10 | +Test Categories: |
| 11 | + - Contract Testing (@pytest.mark.contract) |
| 12 | + - Response Validation (@pytest.mark.response) |
| 13 | + - Schema Validation (@pytest.mark.schema) |
| 14 | + - Error Response (@pytest.mark.error) |
| 15 | +
|
| 16 | +Each test is documented with: |
| 17 | + - Purpose and description |
| 18 | + - Prerequisites and dependencies |
| 19 | + - Expected results |
| 20 | + - Allure annotations for reporting |
| 21 | +
|
| 22 | +Example Test Structure: |
| 23 | + @pytest.mark.contract |
| 24 | + def test_user_schema(): |
| 25 | + 1. Send request to API |
| 26 | + 2. Validate response against schema |
| 27 | + 3. Check specific fields |
| 28 | + 4. Verify error cases |
| 29 | +
|
| 30 | +Required Fixtures: |
| 31 | + - base_url: API base URL from config |
| 32 | + - request_id: Unique test identifier |
20 | 33 | """ |
21 | 34 |
|
22 | 35 | import pytest |
|
0 commit comments