Skip to content

sergeyklay/consumer-pact-example

Repository files navigation

Consumer API Example

Test Code Coverage Status

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

Interaction diagram

Consumer (this project)

Consumer API Example is a simple HTTP client that makes requests to Provider, gets response from API server and creates data model using the data from responses. For demonstration purposes, the project has simplified logic and should not be considered as a full-fledged Production-ready solution.

Provider

For the purity of the experiment, the provider is implemented as a separate project and can be found at the following repo.

Pact

Sample contracts (pacts) are located in tests/pacts.

Getting Started

Prerequisites

What kind of things you need to install on your workstation to start:

  • Python >= 3.11
  • Docker / Rancher
  • Docker Compose / Rancher Compose

Installing

First, install Python dependencies for consumer:

$ make init
$ make install

Run tests

To run unit tests use the command as follows:

$ make test

Run the dockerized broker using the docker-compose.yml file in the root of the project:

$ docker compose -d

To publish contracts (pacts) to the broker use the following command:

$ ./publish-contracts.sh

Run lint check

To run code style checking use the command as follows:

$ make lint

Project Information

Consumer 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 Consumer API Example you're most welcome!

Support

Should you have any question, any remark, or if you find a bug, or if there is something you can't do with the Consumer API Example, please open an issue.