Skip to main content

> Simple server to provide an endpoint used by pact to generate a provider state

PyPi Status Travis Status Documentation Status

Usage

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. Default: 127.0.0.1
  --port INTEGER      Port for the endpoint. Default: 1235
  --log-level TEXT    Log Level Name (DEBUG, INFO, ...). Default: INFO
  --help              Show this message and exit.

TL;DR

Example:

$ pact-state-provider --base-module my_provider.states
$ http http://127.0.0.1:1235 consumer=TestConsumer state="user exists" --json
DEBUG: Importing my_provider.states
DEBUG: Getting function "user_exists"
-> "my_provider.states.user_exists('TestConsumer')" is called

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 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.

Development

Makefile

This project uses a Makefile for various tasks. Some of the available tasks are listed below.

  • make clean - Clean build artifacts out of your project

  • make test - Run Tests

  • make plain-test - Run Tests without rebuilding the project

  • make sdist - Build a Python source distribution

  • make docs - Build the Sphinx documentation

  • make lint - Get a codestyle report about your code

  • make plain-lint - Get a codestyle report without rebuilding the project

  • make - Equivalent to make test lint docs sdist

A New Version

  1. Cherrypick all wanted commits onto the support branch (f.e. support/1.0)

  2. Push the commits

  3. Increment the version in setup.py and update the changelog and commit

  4. Tag the commit with the new version (f.e. v1.0.8)

  5. Push the version commit

Travis will build the new version and upload it to Pypi automatically when finding a tag on the support branch.

Metadata

Release files for pact-state-provider 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pact-state-provider 1.0.9
File Size Uploaded
pact_state_provider-1.0.9.tar.gz 11.4 kB Details

Release files / pact_state_provider-1.0.9.tar.gz

Download URL pact_state_provider-1.0.9.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b4d039212d793b9979cb858fe5fcb2fdcf284c8a4225329f8499a504f8abd64e
BLAKE2b-256 checksum
How to use checksums
83997c6c85e866d887338f181050bc59a7569459ec97a92cf7e4e6561e28fd49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

1.0.9 This release

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page