Skip to content

Caesarsage/microcks-testcontainers-python-demo-flask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask + Microcks Testcontainers Demo

A simple Order Service built with Flask, demonstrating how to use microcks-testcontainers for:

  • Mocking third-party APIs (Pastry API) during tests
  • Contract testing your own API against its OpenAPI specification

The Application

An Order Service that:

  1. Receives order requests via POST /api/orders
  2. Calls an external Pastry API to check if products are available
  3. Returns the created order (201) or an error if a product is unavailable (422)

Project Structure

flask-demo/
├── app/
│   ├── main.py            # Flask app factory and routes
│   ├── models.py           # Order, Pastry, ProductQuantity dataclasses
│   ├── order_service.py    # Business logic (availability checks)
│   └── pastry_client.py    # HTTP client for the Pastry API
├── tests/
│   ├── conftest.py              # Microcks container + Flask fixtures
│   ├── test_pastry_client.py    # Test the Pastry API client against mock
│   ├── test_order_api.py        # Test the Order API endpoints
│   └── test_order_contract.py   # Contract test: does our API match the spec?
└── test-resources/
    ├── order-service-openapi.yaml            # Our API spec
    └── third-parties/
        └── apipastries-openapi.yaml          # Third-party Pastry API spec

Running

# Install dependencies
pip install -r requirements-test.txt

# Run integration tests (requires Docker)
pytest tests/ -v -m integration --timeout=120

# Run the app locally (needs a real Pastry API or Microcks running)
python -m app.main

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages