Skip to content

Commit

Permalink
Fixed README
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalimaha committed Jan 18, 2018
1 parent f2bb670 commit c697c9c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
64 changes: 39 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ Consumer Driven Contracts Testing. For further information about Pact project, c
useful resources please refer to the `Pact website <http://pact.io/>`_.

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.
after all!*), and a Provider honours it. But, before that...

Installation
~~~~~~~~~~~~

Pact Test is distributed through `PyPi <https://pypi.python.org/pypi/pact-test>`_ so it can be easily included in the
:code:`requirements.txt` file or normally installed with :code:`pip`:

.. code:: bash
$ pip install pact-test
Providers Tests (*Set the Contracts*)
-------------------------------------
Expand All @@ -44,21 +54,35 @@ all the interactions with their providers in the following way:

.. code:: python
@service_consumer('UberEats')
@has_pact_with('Dominos Pizza')
class DominosPizzaTest(ServiceProviderTest):
@service_consumer('PythonEats')
@has_pact_with('PyzzaHut')
class PyzzaHutTest(ServiceProviderTest):
@given('some pizza exist')
@upon_receiving('a request for an hawaiian pizza')
@with_request({'method': 'get', 'path': '/pizzas/hawaiian/'})
@will_respond_with({'status': 404, 'body': json.dumps({'reason': 'we do not serve pineapple with pizza'})})
def test_get_pizza(self):
pizza = get_pizza('hawaiian')
assert pizza.status_code == 404
@given('some pizzas exist')
@upon_receiving('a request for a pepperoni pizza')
@with_request({'method': 'get', 'path': '/pizzas/pepperoni/'})
@will_respond_with({'status': 200, 'body': {'id': 42, 'type': 'pepperoni'}})
def test_get_pepperoni_pizza(self):
pizza = get_pizza('pepperoni')
assert pizza['id'] == 42
assert pizza['type'] == 'pepperoni'
This test verifies, against a mock server, the expected interaction and creates
a JSON file (*the pact*) that will be stored locally and also sent to the
Pact Broker, if available.
Pact Broker, if available. It is possible to define multiple tests for the same
state in order to verify all the scenarios of interest, For example, we can
test an unhappy :code:`404` situation:

.. code:: python
@given('some pizzas exist')
@upon_receiving('a request for an hawaiian pizza')
@with_request({'method': 'get', 'path': '/pizzas/hawaiian/'})
@will_respond_with({'status': 404, 'body': {'message': 'we do not serve pineapple with pizza'}})
def test_get_hawaiian_pizza(self):
pizza = get_pizza('hawaiian')
assert pizza.status_code == 404
assert pizza.json()['message'] == 'we do not serve pineapple with pizza'
Consumers Tests (*Honour Your Contracts*)
-----------------------------------------
Expand All @@ -83,16 +107,6 @@ of an hypothetical restaurant service implemented with the most popular Python w

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

Installation
~~~~~~~~~~~~

Pact Test is distributed through `PyPi <https://pypi.python.org/pypi/pact-test>`_ so it can be easily included in the
:code:`requirements.txt` file or normally installed with :code:`pip`:

.. code:: bash
$ pip install pact-test
Pact Helper
~~~~~~~~~~~

Expand Down Expand Up @@ -171,14 +185,14 @@ Development
===========

Setup
-----
~~~~~

.. code:: bash
python3 setup.py install
Test
----
~~~~

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

Expand All @@ -200,7 +214,7 @@ possible to test all the versions at once with:
$ ./bin/test all
Upload New Version
------------------
~~~~~~~~~~~~~~~~~~

.. code:: bash
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='pact-test',
version='0.3.102',
version='1.0.3',
author='Guido Barbaglia',
author_email='[email protected]',
packages=find_packages(),
Expand Down

0 comments on commit c697c9c

Please sign in to comment.