Skip to content

saisyah101/Pytest-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Automation Portofolio : Pytest API Testing - AirportGap

A comprehensive API test automation framework for the AirportGap using Pytest and the Requests library with Python.

Table of Contents

Overview

This project demonstrates API testing practices using the AirportGap public API. The framework follows the Page Object Model pattern adapted for API testing, ensuring maintainable and scalable test code. It includes comprehensive test coverage for positive scenarios, negative scenarios, and end-to-end workflows.

Features

  • Page Object Model for APIs: clean separation of API endpoints and test logic
  • Comprehensive Test Coverage: positive, negative, and E2E test scenarios
  • Authentication Handling: token-based authentication with session management
  • Parameterized Testing: data-driven tests using pytest parametrize
  • Reusable Fixtures: pre-configured sessions and authenticated clients
  • RESTful API Testing: GET, POST, PATCH, DELETE methods
  • Response Validation: status codes, response structure, and data validation
  • Session Management: persistent session handling with requests library
  • Project Structure

    Pytest-API/
    ├── tests/
    │   ├── pages/
    │   │   ├── airport_page.py          # Airport API endpoints wrapper
    │   │   └── auth.py                  # Authentication client
    │   ├── test_api/
    │   │   ├── test_airportgap_positive.py    # Positive test scenarios
    │   │   ├── test_airportgap_negative.py    # Negative test scenarios
    │   │   └── test_airportgap_e2e.py         # End-to-end workflows
    │   ├── __init__.py
    │   └── conftest.py                  # Pytest fixtures and configuration
    ├── .gitignore
    └── README.md
    

    Prerequisites

    Before running this project, ensure you have the following installed:

  • Python 3.8+
  • pip (Python package manager)
  • Git
  • Installation

    1. Clone the repository

    bash
    git clone https://github.com/saisyah101/Pytest-API.git cd Pytest-API

    2. Create and activate virtual environment

    bash
    # Windows python -m venv venv venv\Scripts\activate
    # macOS/Linux python3 -m venv venv source venv/bin/activate

    3. Install dependencies

    bash
    pip install pytest pip install requests pip install pytest-html

    Running Tests

    Run all tests

    bash
    pytest

    Run specific test

    bash
    # Positive tests only pytest tests/test_api/test_airportgap_positive.py
    # # Negative tests only pytest tests/test_api/test_airportgap_negative.py
    # End-to-end tests only pytest tests/test_api/test_airportgap_e2e.py

    Run tests with verbose output

    bash
    pytest -v

    Run tests in parallel (faster execution)

    bash
    pip install pytest-xdist pytest -n auto

    Run tests with HTML report

    bash
    pytest --html=report.html --self-contained-html

    Run specific test by name

    bash
    pytest -k "test_get_airports_success"

    Test Coverage

    Positive Test Scenarios

    Airport Endpoints (test_airportgap_positive.py)

  • Get all airports successfully
  • Get airports with valid pagination (pages 2, 20, 200, 203)
  • Get airports with pagination returning no data (pages 205, 300, 500)
  • Get airport by ID (NRT, SWQ, CGK, DOH, GRX)
  • Calculate distance between airports
  • Calculate distance for same airport (zero distance)
  • Favorites Endpoints (requires authentication)

  • Get all favorites
  • Get favorite by ID
  • Negative Test Scenarios

    Airport Endpoints (test_airportgap_negative.py)

  • Invalid pagination (page 0, -1)
  • Invalid distance calculation parameters
  • Unauthorized access to favorites
  • Invalid authentication credentials
  • Duplicate favorite airport
  • Delete non-existent favorite
  • End-to-End Workflows

    Favorites Management (test_airportgap_e2e.py)

  • Complete workflow: Add favorite → Verify → Delete → Verify
  • Create favorite without note → Patch with note → Delete
  • Full CRUD operations on favorites
  • API Endpoints Tested

    Base URL

    https://airportgap.com/api

    Endpoints

    Method Endpoint Description Auth Required
    GET /airports Get all airports with pagination NO
    GET /airports/{id} Get specific airport by ID NO
    POST /airports/distance Calculate distance between airports NO
    GET /favorites Get user's favorite airports YES
    GET /favorites/{id} Get specific favorite by ID YES
    POST /favorites Add airport to favorites YES
    PATCH /favorites/{id} Update favorite note YES
    DELETE /favorites/{id} Remove favorite airport YES
    POST /tokens Authenticate and get token NO

    Author

    Siti Aisyah
    LinkedIn

    About

    No description, website, or topics provided.

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published

    Languages