Introduction

> pact-state-provider


Installation

  1. Install the package:

    pip install pact_state_provider
    

Client

Entrypoint pact-state-provider:

Usage: pact-state-provider [OPTIONS]

Start the state provider server on the specified host and port.

Options:
    --base-module TEXT  Module containing the state providers.
    --host TEXT         Host for the endpoint.
    --port INTEGER      Port for the endpoint.
    --help              Show this message and exit.

TL;DR

Example:

pact-state-provider --base-module my_provider.states
# pact requests a state:
# GET http://127.0.0.1:1235 {'consumer': 'TestConsumer', 'state': 'user exists'}
-> function "my_provider.states.user_exists('TestConsumer')" is executed

Not Long Enough;Will Read

When verifying contracts with Pact a state provider is called for the particular consumer with the state requested. A consumer :code:´TestConsumer´ with a contract starting with given('user exists') requests the configured endpoint with the payload:

{
    'consumer': 'TestConsumer',
    'state': 'user exists'
}

In order to execute the specific provider functions without having to implement a dedicated endpoint on the provider or a dedicated application with provider specific code pact-state-provider provides a simple http server endpoint which calls an existing module function based on the request payload.

In the given example a function called user_exists (invalid characters are translated to underscores) will be executed on the specified base module (--base-module parameter).

This gives the user to maintain the state provider code in the actual provider codebase, but easily have an endpoint to use with pact.