Skip to main content

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

Project description

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

https://travis-ci.org/nalch/pact-state-provider.svg?branch=master

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pact_state_provider-1.0.3.tar.gz (10.8 kB view details)

Uploaded Source

File details

Details for the file pact_state_provider-1.0.3.tar.gz.

File metadata

  • Download URL: pact_state_provider-1.0.3.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.7

File hashes

Hashes for pact_state_provider-1.0.3.tar.gz
Algorithm Hash digest
SHA256 78d0f267c97a17b798739f8b00f52ee20a6cb670202e7aa2a92ba6d03c7f1774
MD5 6e148df07950aa6e5d540ece2e09b052
BLAKE2b-256 6981fc91b134ed07c5f1f68db0f317db1d1b472ef6a468447bffd9684c37f605

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page