How sas5999/enterprise_api_framework-2 works
1. Repository purpose and boundary
- This is a Python pytest-based API test automation framework, not an application backend.
- The repo’s main boundary is between the test harness and an external target API (for example reqres.in by default). The framework orchestrates requests, assertions, logging, and reporting around that external system.
2. Top-level architecture is layered
- The code is organized into four practical layers:
- Foundation: config/, utils/, schemas/, data/
- API layer: api/
- Action layer: actions/
- Test layer: tests/
- The dependency direction is one-way downward: tests call actions, actions call the API client, and lower layers use foundation utilities.
3. Test layer: suite organization and execution
- tests/ contains the actual pytest suites, grouped by concern:
- tests/smoke/ for fast commit/PR gates
- tests/users/ for user CRUD-style coverage
- tests/auth/ for login/register coverage
- Tests are marker-driven (smoke, positive, negative, schema, performance, regression, wip) so CI can select subsets without changing code.
4. Action layer: business-level operations
- actions/auth_actions.py and actions/user_actions.py are the main abstraction for tests.
- These classes represent resource-level business flows such as “get user”, “create user”, or “authenticate”, instead of raw HTTP calls.
- This layer is the main boundary that keeps tests readable and shields them from endpoint and request details.
5. API layer: transport and endpoint definition
- api/client.py is the HTTP transport layer: it likely handles request execution, retries, pooling, masking, metrics, and fluent response wrapping as described in the README.
- api/endpoints.py centralizes path construction, so endpoint strings are defined once and reused by all actions.
- This separation means URL structure changes are isolated from tests.
6. Foundation layer: configuration, contracts, and utilities
- config/settings.py provides environment-driven settings such as base URL, timeouts, retries, and SLA thresholds.
- schemas/user_schemas.py holds JSON schema contracts used to detect API response drift.
- utils/logger.py and utils/helpers.py provide cross-cutting support such as logging, retry/assertion helpers, and likely test instrumentation.
7. Test data generation
- data/factories/user_factory.py generates payloads for positive and negative cases.
- This factory-based approach supports realistic and boundary-oriented test data without hardcoding payloads in the tests.
- It is a key input source into the action layer when creating or validating users.
8. Request/response flow through the system
- A typical flow is: pytest test → action method → API client → external API → response wrapper/assertions → schema validation/logging/reporting.
- Tests generally do not speak directly to the client; they invoke actions and then use assertion helpers or schema validators on the returned response object.
9. Shared test fixtures and session behavior
- conftest.py is the central pytest integration point for fixtures, metrics collection, and reporting enrichment.
- This is where action instances and shared session state are likely injected into tests.
- Session-level behavior such as aggregated request metrics and reporting hooks is coordinated here rather than in individual tests.
10. Environment and configuration model
- Configuration is externalized via .env.example and loaded through config/settings.py.
- The framework supports multiple environments (dev, staging, uat, prod) with environment-specific base URLs and runtime knobs like timeout, retries, and SLA budgets.
- This makes the same test suite portable across deployment targets.
11. CI/CD and developer workflow
- .github/workflows/ci.yml defines a staged pipeline: quality checks → smoke tests → full suite → reporting.
- .pre-commit-config.yaml enforces local hygiene before code reaches CI.
- The architecture is designed so smoke tests act as an early gate, while broader marker groups run later.
12. External integrations and observability
- The framework is built to integrate with Allure for report generation and likely stores request metrics for session summaries.
- Logging is designed to redact sensitive fields, which matters because credentials or bearer tokens may be injected into requests via config.
- These observability features are cross-cutting concerns that sit beside the test flow rather than inside individual tests.
13. What to draw in an architecture diagram
- Show the external API under test as the system boundary.
- Inside the repo, show four stacked layers with arrows:
- tests/ → actions/ → api/ → external API
- config/, utils/, schemas/, data/ feeding into actions, API client, and tests as shared foundation
- Add side channels for logging/metrics/reporting and CI/pre-commit as orchestration and observability paths.
Main entry points: client.py API Client · ci.yml CI Workflow · auth_actions.py Auth Actions · user_actions.py User Actions
Components 16
Foundation
Shared config, data, schemas, and utilities
- Settings · Environment-driven runtime settings and thresholds
config/settings.py - Logger · Cross-cutting request and test logging with redaction
utils/logger.py - Helpers · Shared helper functions for retries, assertions, and instrumentation
utils/helpers.py - User Schema · JSON schema contract for user API responses
schemas/user_schemas.py - User Factory · Payload generation for positive and negative user cases
data/factories/user_factory.py
API Layer
HTTP transport and endpoint definitions
- Endpoints · Centralized endpoint path construction
api/endpoints.py - API Client · HTTP execution, response wrapping, retries, and metrics
api/client.py
Action Layer
Resource-level business flows used by tests
- Auth Actions · Authentication and registration operations
actions/auth_actions.py - User Actions · User retrieval and CRUD-style business operations
actions/user_actions.py
Test Layer
Pytest suites organized by concern
- Smoke Suite · Fast commit/PR gate tests
tests/smoke/test_smoke.py - Auth Suite · Login and register coverage
tests/auth/test_auth.py - Users Suite · User-focused API coverage
tests/users/test_users.py
Orchestration
Pytest integration and CI workflow
- Pytest Fixtures · Shared fixtures, session state, and reporting hooks
conftest.py - CI Workflow · Quality checks, smoke tests, full suite, and reporting
.github/workflows/ci.yml - Pre-commit · Local hygiene checks before CI
.pre-commit-config.yaml
Other components
- External API · The third-party API under test, such as reqres.in
Connections 23
- Smoke Suite → Auth Actions: calls · Smoke tests exercise business flows through actions
- Auth Suite → Auth Actions: calls · Auth tests invoke resource-level operations
- Users Suite → User Actions: calls · User tests invoke resource-level operations
- Auth Actions → API Client: uses · Action methods delegate transport to the API client
- User Actions → API Client: uses · Action methods delegate transport to the API client
- API Client → Endpoints: resolves · Client uses centralized endpoint paths
- API Client → External API: requests · HTTP calls exit the repo boundary to the target API
- Settings → API Client: configures · Settings provide base URL, timeouts, retries, and thresholds
- Settings → Auth Actions: configures · Actions can read environment-driven auth settings
- Settings → User Actions: configures · Actions can read environment-driven runtime settings
- Logger → API Client: observes · Client logs requests and responses with redaction
- Helpers → Auth Actions: supports · Shared helpers support assertions and retries
- Helpers → User Actions: supports · Shared helpers support assertions and retries
- User Schema → Users Suite: validates · Schema contracts are used to detect response drift
- User Factory → User Actions: feeds · Factory-generated payloads drive create and negative cases
- Pytest Fixtures → Smoke Suite: injects · Fixtures provide shared session state and reporting hooks
- Pytest Fixtures → Auth Suite: injects · Fixtures provide shared session state and reporting hooks
- Pytest Fixtures → Users Suite: injects · Fixtures provide shared session state and reporting hooks
- CI Workflow → Pre-commit: mirrors · CI complements local pre-commit hygiene
- CI Workflow → Smoke Suite: runs · Smoke tests run early in the pipeline
- CI Workflow → Auth Suite: runs · Full suite includes auth coverage
- CI Workflow → Users Suite: runs · Full suite includes user coverage
- CI Workflow → Pytest Fixtures: executes through · Pytest orchestration flows through shared fixtures