Skip to main content
Help us improve Python packaging – donate today!

Python implementation for Pact (http://pact.io/)

Project Description

https://travis-ci.org/Kalimaha/pact-test.svg?branch=master https://coveralls.io/repos/github/Kalimaha/pact-test/badge.svg?branch=development

Pact Test for Python

This repository contains a Python implementation for Pact. Pact is a specification for Consumer Driven Contracts Testing. For further information about Pact project, contracts testing, pros and cons and useful resources please refer to the Pact website.

There are two phases in Consumer Driven Contracts Testing: a Consumer sets up a contract (it’s consumer driven after all!), and a Provider honours it.

Providers Tests (Set the Contracts)

TBD.

Consumers Tests (Honour Your Contracts)

Providers run Consumer Tests to verify that they are honouring their pacts with the consumers. There are few examples of an hypothetical restaurant service implemented with the most popular Python web frameworks:

There are few things required to setup and run consumer tests.

Installation

Pact Test is distributed through PyPi so it can be easily included in the requirements.txt file or normally installed with pip:

$ pip install pact-test

Pact Helper

This helper class is used by Pact Test to start and stop the web-app before and after the test. It also defines the ports and endpoint to be used by the test. The following is an example of Pact Helper:

class RestaurantPactHelper(PactHelper):
    process = None

    def setup(self):
        self.process = subprocess.Popen('gunicorn start:app -w 3 -b :8080 --log-level error', shell=True)

    def tear_down(self):
        self.process.kill()

There are few rules for the helper:

  • it must extend PactHelper class from pact_test
  • it must define a setup method
  • it must define a tear_down method

It is also possible to override default url (localhost) and port (9999):

class RestaurantPactHelper(PactHelper):
    test_url = '0.0.0.0'
    test_port = 5000

States

When a consumer sets a pact, it defines certain states. States are basically pre-requisites to your test. Before honouring the pacts, a provider needs to define such states. For example:

@honours_pact_with('UberEats')
@pact_uri('http://Kalimaha.github.io/src/pacts/pact.json')
class UberEats(ServiceConsumerTest):

    @state('some menu items exist')
    def test_get_menu_items(self):
        DB.save(MenuItem('spam'))
        DB.save(MenuItem('eggs'))

In this example, the provider stores some test data in its DB in order to make the system ready to receive mock calls from the consumer and therefore verify the pact.

Configuration

The default configuration of Pact Test assumes the following values:

  • consumer_tests_path: tests/service_consumers
  • provider_tests_path: tests/service_providers
  • pact_broker_uri: None

It is possible to override such values by creating a file named .pact.json in the project’s root. The following is an example of a valid configuration file:

{
  "consumer_tests_path": "mypath/mytests",
  "provider_tests_path": "mypath/mytests",
  "pact_broker_uri": "http://example.com/"
}

All fields are optional: only specified fields will override default configuration values.

Development

Setup

python3 setup.py install

Test

It is possible to run the tests locally with Docker through the following command:

$ ./bin/test

By default this command tests the library against Python 3.6. It is possible to specify the Python version as follows:

$ ./bin/test <ENV>

Available values for ENV are: py27, py33, py34, py35 and py36. It is also possible to test all the versions at once with:

$ ./bin/test all

Upload New Version

$ python3 setup.py sdist upload

With Python Wheels:

$ python3 setup.py sdist bdist_wheel
$ twine upload dist/*

Release history Release notifications

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

0.3.102

History Node

0.3.101

History Node

0.3.100

History Node

0.3.99

History Node

0.3.98

History Node

0.3.97

History Node

0.3.96

History Node

0.3.95

History Node

0.3.94

History Node

0.3.93

History Node

0.3.92

History Node

0.3.91

History Node

0.3.90

History Node

0.3.89

History Node

0.3.88

History Node

0.3.87

History Node

0.3.86

History Node

0.3.85

History Node

0.3.84

History Node

0.3.83

History Node

0.3.82

History Node

0.3.81

History Node

0.3.80

History Node

0.3.79

History Node

0.3.78

History Node

0.3.77

History Node

0.3.76

History Node

0.3.75

History Node

0.3.74

History Node

0.3.73

History Node

0.3.72

History Node

0.3.71

History Node

0.3.70

History Node

0.3.69

History Node

0.3.68

History Node

0.3.67

History Node

0.3.66

History Node

0.3.65

History Node

0.3.64

History Node

0.3.63

History Node

0.3.62

History Node

0.3.61

History Node

0.3.60

History Node

0.3.59

History Node

0.3.58

History Node

0.3.57

History Node

0.3.56

History Node

0.3.55

History Node

0.3.54

History Node

0.3.53

History Node

0.3.52

History Node

0.3.51

History Node

0.3.50

History Node

0.3.49

History Node

0.3.48

History Node

0.3.47

History Node

0.3.46

History Node

0.3.45

History Node

0.3.44

History Node

0.3.43

History Node

0.3.42

History Node

0.3.41

History Node

0.3.40

History Node

0.3.39

History Node

0.3.38

History Node

0.3.37

History Node

0.3.36

History Node

0.3.35

History Node

0.3.34

History Node

0.3.33

History Node

0.3.32

History Node

0.3.31

History Node

0.3.30

History Node

0.3.29

History Node

0.3.28

History Node

0.3.27

History Node

0.3.26

History Node

0.3.25

History Node

0.3.24

History Node

0.3.23

History Node

0.3.22

History Node

0.3.21

History Node

0.3.20

History Node

0.3.19

History Node

0.3.18

History Node

0.3.17

History Node

0.3.16

History Node

0.3.15

History Node

0.3.14

History Node

0.3.13

History Node

0.3.12

History Node

0.3.11

History Node

0.3.10

History Node

0.3.9

History Node

0.3.7

History Node

0.3.6

History Node

0.3.5

History Node

0.3.4

This version
History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

History Node

0.1.50

History Node

0.1.49

History Node

0.1.48

History Node

0.1.47

History Node

0.1.46

History Node

0.1.45

History Node

0.1.44

History Node

0.1.43

History Node

0.1.42

History Node

0.1.41

History Node

0.1.40

History Node

0.1.39

History Node

0.1.38

History Node

0.1.37

History Node

0.1.36

History Node

0.1.35

History Node

0.1.34

History Node

0.1.33

History Node

0.1.32

History Node

0.1.31

History Node

0.1.30

History Node

0.1.29

History Node

0.1.28

History Node

0.1.27

History Node

0.1.26

History Node

0.1.25

History Node

0.1.24

History Node

0.1.23

History Node

0.1.22

History Node

0.1.21

History Node

0.1.20

History Node

0.1.19

History Node

0.1.18

History Node

0.1.17

History Node

0.1.16

History Node

0.1.15

History Node

0.1.14

History Node

0.1.13

History Node

0.1.12

History Node

0.1.11

History Node

0.1.10

History Node

0.1.9

History Node

0.1.8

History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
pact_test-0.3.3-py2.py3-none-any.whl (24.2 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Nov 15, 2017
pact-test-0.3.3.tar.gz (12.9 kB) Copy SHA256 hash SHA256 Source None Nov 15, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page