Skip to content

About

Automated REST API test suite using Python Requests and PyTest — covers auth, CRUD operations, JSON schema validation, and negative testing with Postman collection included

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

API Test Suite (PyTest + Requests)

CI

Automated REST API test suite built with Python, PyTest, and Requests, targeting reqres.in. Covers the authentication token flow, full CRUD operations, JSON schema validation, and negative/edge-case testing. Includes a companion Postman collection for manual and exploratory testing of the same endpoints, and runs automatically on every push via a GitHub Actions CI/CD pipeline.

Features

  • Auth token flow — register and login tests, including missing-field and invalid-credential negative cases
  • CRUD operations — GET (single + paginated list), POST (create), PUT (update), DELETE, with status code and response body assertions
  • JSON schema validation — response structure and data types validated against defined schemas, not just individual field values
  • Data-driven testing — login and user-creation scenarios loaded from JSON files and run via pytest.mark.parametrize, so new test cases can be added without touching code
  • Negative testing — 404s on non-existent resources, invalid ID formats, malformed requests
  • HTML reporting — a self-contained pytest-html report generated after every run
  • CI/CD — GitHub Actions pipeline runs the full suite on every push/PR and uploads the HTML report as a build artifact
  • Postman collection — the same endpoints available for manual exploration, organized into Auth, CRUD, and Negative Cases folders

Tech Stack

Tool Purpose
Python 3.11 Language
PyTest Test runner, fixtures, parametrization
Requests HTTP client
jsonschema Response schema validation
pytest-html HTML test reports
GitHub Actions CI/CD pipeline
Postman Manual/exploratory API testing

Project Structure

api-test-suite-project/
├── tests/
│   ├── test_auth.py            # register/login, token validation
│   ├── test_users_crud.py      # GET/POST/PUT/DELETE + schema checks
│   └── test_negative.py        # 404s, invalid IDs, edge cases
├── utils/
│   ├── api_client.py           # requests wrapper (base URL, headers, API key)
│   └── schema_validator.py     # JSON schema assertion helper
├── schemas/                    # JSON schema definitions
│   ├── user_schema.json
│   └── user_list_schema.json
├── test_data/                  # JSON-driven test scenarios
│   ├── login_data.json
│   └── create_user_data.json
├── postman/
│   └── API_Test_Suite.postman_collection.json
├── conftest.py                 # shared fixtures (api_client, auth_token)
├── pytest.ini                  # markers + HTML report config
├── requirements.txt
└── .github/workflows/ci.yml    # CI pipeline

Setup

# Clone the repo
git clone https://github.com/Arunkumar-1809/api-test-suite-python.git
cd api-test-suite-python

# Create and activate a virtual environment
python -m venv venv
venv\Scripts\activate      # Windows
source venv/bin/activate   # macOS/Linux

# Install dependencies
pip install -r requirements.txt

API Key

reqres.in requires a free API key. Sign up at reqres.in/signup, then set it as an environment variable:

setx REQRES_API_KEY "your-key-here"     # Windows (restart terminal after)
export REQRES_API_KEY="your-key-here"   # macOS/Linux

Running Tests

pytest                     # run the full suite
pytest -m smoke             # smoke tests only
pytest -m auth                # auth flow tests only
pytest -m crud                  # CRUD tests only
pytest -m negative                # negative/edge case tests only
pytest -k "TC_LOGIN_01"             # run one specific test

An HTML report is generated at reports/report.html after every run.

CI/CD

Every push to main triggers a GitHub Actions workflow that:

  1. Checks out the code
  2. Sets up Python 3.11
  3. Installs dependencies
  4. Runs the full test suite (using a REQRES_API_KEY repository secret)
  5. Uploads the HTML report as a downloadable build artifact

Postman Collection

Import postman/API_Test_Suite.postman_collection.json into Postman for manual/exploratory testing of the same endpoints — useful for quick checks without spinning up the automated suite.

Author

Arunkumar — QA Automation Engineer GitHub · LinkedIn

About

Automated REST API test suite using Python Requests and PyTest — covers auth, CRUD operations, JSON schema validation, and negative testing with Postman collection included

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages