An open API service indexing awesome lists of open source software.

https://github.com/sergeyklay/provider-pact-example

Provider-side demo using consumer-driven contract testing
https://github.com/sergeyklay/provider-pact-example

api api-project api-server api-service-for-crud api-specification api-testing consumer-driven-contracts contract-driven-development contract-testing contract-tests contracts flask-api flask-application flask-example openapi openapi3 pact pact-provider

Last synced: 11 days ago
JSON representation

Provider-side demo using consumer-driven contract testing

Awesome Lists containing this project

README

        

.. raw:: html

Provider API Example




Test Contracts


Test Code


Lint OpenAPI


Coverage Status

.. teaser-begin

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

.. teaser-end

.. image:: https://raw.githubusercontent.com/sergeyklay/provider-pact-example/main/cdc-example.png
:alt: Interaction diagram

Provider
========

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.

Consumer
========

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

Pact
====

Sample contracts (pacts) are located here:
https://github.com/sergeyklay/consumer-pact-example/tree/main/tests/pacts

Getting Started
===============

Prerequisites
-------------

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

* Python >= 3.11
* SQLite3
* Node.js >= 16

Installing
----------

First, install Python dependencies for provider (Products API):

.. code-block:: console

$ make init
$ make install

Create provider configuration:

.. code-block:: console

$ cp .env.example .env

Run database migrations for provider:

.. code-block:: console

$ make migrate

Add provider seed data to the database:

.. code-block:: console

$ make seed

Next, install Node.js linters and tools:

.. code-block:: console

$ npm install

Run API server
--------------

To run API server use the command as follows:

.. code-block:: console

$ make serve

Run tests
---------

To run unit tests use the command as follows:

.. code-block:: console

$ make test

To verify contracts (pacts) use the command as follows:

.. code-block:: console

$ ./tests/run-pytest.sh

Note that before the contracts verification, you must have deployed the broker,
as well as the contracts must be published.

Run lint check
--------------

To run OpenAPI spec checking use the command as follows:

.. code-block:: console

$ npm run lint

.. -project-information-

Project Information
===================

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!

.. -support-

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 Provider API Example, please
`open an issue `_.