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
An Order Service that:
- Receives order requests via
POST /api/orders - Calls an external Pastry API to check if products are available
- Returns the created order (201) or an error if a product is unavailable (422)
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
# 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