Skip to content

lobanov-qa/pytest-booker-platform-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

53 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Pytest RESTful Booker Platform API Test Framework

Portfolio framework for automated testing of RESTful Booker Platform microservices. Implemented in Python and Pytest using modern practices to improve code readability and structure.

API tests Deploy docs

🎯 Project Purpose

This project was created for educational purposes to practically master the following skills:

  • Automated testing of REST APIs in Python
  • Working with microservice architecture
  • Organizing test code for maintainability
  • Integration with CI/CD (GitHub Actions) and reporting systems (Allure)

πŸ’Ό What's Implemented in the Project

  • Structured code organization: logical separation into API clients, data factories, and utilities
  • Response validation: using Pydantic models and JSON Schema to verify data structure
  • Test data generation: using the Faker library to create diverse input data
  • Detailed reporting: integration with Allure for clear test execution reports
  • Automated test runs: configuring CI/CD pipeline in GitHub Actions
  • Logging: custom handlers in HTTPX for recording request and response details

πŸ’‘ Test Example: Retrieving Booking by ID

Below is an example test using Allure, Pydantic, and custom fixtures:

@allure.story(AllureStory.BOOKING_RETRIEVAL)
@allure.tag(AllureTag.GET_ENTITY)
@allure.severity(Severity.BLOCKER)
def test_get_booking_success(
    self,
    booking_private_client: PrivateBookingClient,
    created_booking: BookingFixture
):
    """
    Positive test: Retrieve specific booking by booking ID.
    Validates response matches the created booking data.
    """
    booking_id = created_booking.response.bookingid
    response = booking_private_client.get_booking_api(booking_id)
    allure.dynamic.title(f"GET /booking/{booking_id} - Retrieve specific booking by ID")
    
    assert_status_code(response.status_code, HTTPStatus.OK)
    response_data = BookingSchema.model_validate_json(response.text)
    validate_json_schema(response.json(), response_data.model_json_schema())
    assert_get_booking_response(response_data, created_booking.response.booking)
Image

πŸ›  Technology Stack

Category Tools
Framework Python 3.11+, Pytest
HTTP Client HTTPX (with logging via custom handlers)
Validation Pydantic, JSON Schema
Test Data Faker
Reporting Allure-pytest, Swagger Coverage Tool
Automation GitHub Actions, Docker Compose
  • Allure 3 Reports: interactive test results with run history
  • API Coverage: Swagger specification validation metrics
  • Documentation: live documentation based on OpenAPI

Image


πŸš€ Quick Start

Prerequisites

  • Python 3.11 or higher
  • Docker & Docker Compose
  • Git

⚠️ Important: the project tests the educational RESTful Booker Platform microservices, deployed via Docker Compose.


Installation and Setup

1. Start the Target Microservices

git clone https://github.com/mwinteringham/restful-booker-platform.git
cd restful-booker-platform
docker compose up -d

2. Install the Test Framework

cd ..
git clone https://github.com/lobanov-qa/pytest-booker-platform-api.git
cd pytest-booker-platform-api

3. Create a Virtual Environment

Linux/Mac:

python3 -m venv venv
source venv/bin/activate

Windows:

python -m venv venv
venv\Scripts\activate

4. Install Dependencies

pip install -e .

5. Configure Environment

cp .env.example .env

Edit the .env file manually with your settings.

6. Run Tests

python scripts/wait_for_services.py
pytest tests/ --alluredir=allure-results -v

7. View Report

allure serve allure-results

This command will open the Allure report in your default browser.

πŸ“ Project Structure

pytest-booker-platform-api/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ clients/                    # Domain-oriented API clients
β”‚   β”‚   β”œβ”€β”€ auth/                   # Authentication service client
β”‚   β”‚   β”‚   β”œβ”€β”€ auth_client.py      # Public/private client methods with Allure steps
β”‚   β”‚   β”‚   β”œβ”€β”€ routes.py           # API endpoint definitions and URL constants
β”‚   β”‚   β”‚   └── auth_schema.py      # Pydantic models for Auth API requests/responses
β”‚   β”‚   β”œβ”€β”€ booking/                # Booking service client (structure similar to auth)
β”‚   β”‚   β”œβ”€β”€ api_client.py           # Base HTTP client with Allure step decorators
β”‚   β”‚   β”œβ”€β”€ api_coverage.py         # Swagger coverage tracking decorators
β”‚   β”‚   β”œβ”€β”€ event_hooks.py          # HTTPX event hooks for request/response logging
β”‚   β”‚   └── factories.py            # Client factory for easy instance creation
β”‚   β”œβ”€β”€ data_factories/             # Factory pattern for test data generation
β”‚   β”‚   β”œβ”€β”€ booking_factory.py      # Factory methods for booking test data
β”‚   β”‚   └── query_factories.py      # Factory methods for query parameters
β”‚   └── utils/
β”‚       β”œβ”€β”€ allure/                 # Allure configuration and decorators
β”‚       β”œβ”€β”€ assertions/             # Custom assertion libraries
β”‚       β”‚   β”œβ”€β”€ base.py             # Basic assertion utilities
β”‚       β”‚   └── schema.py           # JSON Schema validation assertions
β”‚       β”œβ”€β”€ http/curl.py            # CURL command generation utilities
β”‚       β”œβ”€β”€ fakers.py               # Extended Faker utilities for test data
β”‚       └── logger.py               # Structured logging configuration
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ auth/                       # Authentication test suites
β”‚   β”‚   └── test_authentication.py  # Auth API tests with parameterization
β”‚   β”œβ”€β”€ booking/                    # Booking service test suites
β”‚   └── test_api_health.py          # Health checks for all services
β”œβ”€β”€ fixtures/                       # Pytest fixtures
β”‚   β”œβ”€β”€ auth.py                     # Authentication-related fixtures
β”‚   └── allure.py                   # Allure reporting fixtures
β”œβ”€β”€ scripts/                        # Utility scripts
β”‚   └── wait_for_services.py        # Service health check utilities
└── .github/workflows/              # CI/CD pipelines
β”‚   β”œβ”€β”€ ci.yml                      # Main testing workflow
β”‚   └── deploy-docs.yml             # Documentation deployment workflow

πŸ“š Skills Acquired

Through this project, I have mastered:

  • Python / Pytest: writing parameterized tests, using fixtures, organizing modular structure.
  • Working with APIs: sending requests (HTTPX), handling authorization, validating responses.
  • Code organization: applying SOLID principles and domain-oriented approach for separation of concerns.
  • Automation tools: configuring GitHub Actions, generating Allure reports, integrating with Swagger.
  • Documentation: maintaining README, setting up documentation publishing via GitHub Pages.
  • Quality analysis: tracking API coverage against OpenAPI specifications.

This project has served as a "testing ground" for experimenting with best practices that I want to develop in a professional environment.

πŸ“ž Contacts

Ready for code reviews, discussion of solutions, and feedback.
Looking for an opportunity to start a career as an AQA Engineer to grow within a team and contribute to software quality.

About

πŸš€ Training project: An API test automation framework for the RESTful Booker Platform. Uses Python, Pytest, and HTTPX to test CRUD operations. Includes Pydantic models for response validation, Allure for reporting, and a GitHub Actions workflow for CI.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages