Skip to content

RaunakK22UB/Python-API-Test-Automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Python REST API Test Automation Framework

This project is a complete test automation framework for a REST API, developed using Python. It is designed to perform functional and integration testing to validate the reliability and correctness of API endpoints.

The framework automatically executes a suite of tests against a live To-Do List API, verifying all core CRUD (Create, Read, Update, Delete) operations. This project demonstrates foundational skills in API validation, Python scripting, and CI/CD quality workflows, which are all core responsibilities for a validation-focused role.

Key Features

Full CRUD Validation: Tests all four primary HTTP methods:

POST: Validates task creation and asserts data consistency.

PUT: Validates task updates.

GET: Validates data retrieval for both a single task and all tasks.

DELETE: Validates successful task deletion.

Status Code Assertion: Automatically checks for correct HTTP response codes (e.g., 200 OK, 201 Created, 404 Not Found).

Data Integrity Testing: Asserts that the data returned by the API (in JSON format) matches the data that was sent during creation or update.

CI/CD Integration: Includes a simple GitHub Actions workflow (ci.yml) that acts as a quality gate, automatically running the entire test suite on every push to the master branch.

Technologies Used

Language: Python

Testing Framework: PyTest

API Interaction: requests library

CI/CD: GitHub Actions

How to Run

  1. Clone the Repository

git clone https://github.com/RaunakK22UB/Python-API-Test-Automation.git cd Python-API-Test-Automation

  1. Create a Virtual Environment (Recommended)

On Windows

python -m venv venv .\venv\Scripts\activate

On macOS/Linux

python3 -m venv venv source venv/bin/activate

  1. Install Dependencies

This project's dependencies are listed in requirements.txt.

pip install -r requirements.txt

  1. Run the Test Suite

To execute all automated tests, simply run:

pytest

To see a more detailed "verbose" output with print statements:

pytest -v -s

Example Test Case

Here is an example of a test function that validates the create-task endpoint. It follows the "Arrange, Act, Assert" pattern.

import requests import uuid

The endpoint for the API being tested

ENDPOINT = "https://todo.pixegami.io/"

def test_can_create_task(): # 1. Arrange: Define the test data (payload) # We use uuid to ensure the task is unique every time payload = { "content": "My test task", "user_id": "test_user", "task_id": f"test_task_{uuid.uuid4().hex}" }

# 2. Act: Make the API call to create the task
create_response = requests.put(ENDPOINT + "/create-task", json=payload)

# 3. Assert: Validate that the creation was successful
assert create_response.status_code == 200

# 4. Act (Get): Retrieve the task to verify it was created correctly
get_response = requests.get(ENDPOINT + f"/get-task/{payload['task_id']}")

# 5. Assert (Verify): Validate the retrieved data
assert get_response.status_code == 200
get_task_data = get_response.json()
assert get_task_data["content"] == payload["content"]
assert get_task_data["user_id"] == payload["user_id"]

About

Testing the restAPIs by the help of pytest

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages