← ClaudeAtlas

api-testing-patternslisted

API test automation patterns — httpx/requests client wrappers, response validation with Pydantic, test data factories, retry/polling utilities, schema testing, and contract testing.
Izangi2714/claude-code-python-stack · ★ 0 · Testing & QA · score 65
Install: claude install-skill Izangi2714/claude-code-python-stack
# API Testing Patterns Production patterns for API test automation with httpx, requests, Pydantic, and pytest. ## When to Activate - Writing HTTP API tests (REST, GraphQL) - Building reusable HTTP client wrappers - Validating API responses against schemas - Generating test data with factories - Implementing retry/polling for async operations - Setting up contract testing ## HTTP Client: httpx (Recommended) ### Why httpx over requests | Feature | httpx | requests | |---------|-------|----------| | Async support | Native | No | | HTTP/2 | Yes | No | | Timeout config | Granular | Basic | | Connection pooling | Built-in | Built-in | | Type hints | Full | Partial | | API compatibility | requests-like | N/A | ### Client Wrapper ```python import httpx import allure import logging from framework.config.settings import Settings logger = logging.getLogger(__name__) class HTTPClient: def __init__(self, settings: Settings, token: str | None = None): headers = {"Content-Type": "application/json", "Accept": "application/json"} if token: headers["Authorization"] = f"Bearer {token}" self._client = httpx.Client( base_url=settings.BASE_URL, headers=headers, timeout=httpx.Timeout( connect=5.0, read=settings.REQUEST_TIMEOUT, write=5.0, pool=5.0, ), ) @allure.step("{method} {url}") def request(self, method: str, url: s