This is a Python application for explanation of Contract Testing based on Pact.
Here you can find out how to use Pact using the Python language. You can find more of an overview on Pact in the Pact Introduction.
This project uses:
- Pact, a code-first tool for testing HTTP and message integrations using contract tests
- pact-python, to create and verify consumer driven contracts
- OpenAPI, to describe the Products API
- Flask, a micro web framework for building API
Provider API Example is a sample Flask application that expose endpoints with REST standard. As an example, this project uses the simple Products API. Here is the OpenAPI spec describes the interaction of clients with the provider.
For the purity of the experiment, the consumer is implemented as a separate project and can be found at the following repo.
Sample contracts (pacts) are located here: https://github.com/sergeyklay/consumer-pact-example/tree/main/tests/pacts
What kind of things you need to install on your workstation to start:
- Python >= 3.11
- SQLite3
- Node.js >= 16
First, install Python dependencies for provider (Products API):
$ make init
$ make install
Create provider configuration:
$ cp .env.example .env
Run database migrations for provider:
$ make migrate
Add provider seed data to the database:
$ make seed
Next, install Node.js linters and tools:
$ npm install
To run API server use the command as follows:
$ make serve
To run unit tests use the command as follows:
$ make test
To verify contracts (pacts) use the command as follows:
$ ./tests/run-pytest.sh
Note that before the contracts verification, you must have deployed the broker, as well as the contracts must be published.
To run OpenAPI spec checking use the command as follows:
$ npm run lint
Provider API Example is released under the MIT License, and its code lives at GitHub. It’s rigorously tested on Python 3.11+.
If you'd like to contribute to Provider API Example you're most welcome!
Should you have any question, any remark, or if you find a bug, or if there is something you can't do with the Provider API Example, please open an issue.