A simple demo to demonstrate how to work with the Pact Framework in python.
In this example we'll have a Provider Memes-Service
and a Consumer
Memes-Website
.
The Memes-Website
will create a pact with the provider and publish it to
a pact broker. And the Memes-Service
will download that pact and verify it.
You need to get a version of the pact broker running, you can find the instructions here: https://github.com/DiUS/pact_broker-docker
git clone git@github.com:mbeltre/pact-demo.git
cd pact-demo
pip install -r requirements.txt
- Run the Memes-Service
python ./src/memes_service/app.py
- Open another terminal and go to the root directory, then run:
python ./src/memes_website/app.py
Now visit http://localhost:5001/index
, you should see a very funny meme :)
Run the following commands from the root directory:
cd ./src/memes_website
ENV PYTHONPATH=. pytest
A pact memes-website-memes-service.json
should be generated.
Now let's upload that file to the broker:
cd ../..
make push-pact
If you go to http://localhost
, you should see the pact on the pact broker.
To verify the pact we need to run the provider service, in this case
Memes-Service
.
Run:
make verify-pact
That's see, you just created a pact, share using a pact broker and verified it.
If you want to learn more about the Pact Framework visit: https://docs.pact.io/