From c697c9c5542353ddc27d368a43691d3b45dc06fc Mon Sep 17 00:00:00 2001 From: Kalimaha Date: Thu, 18 Jan 2018 11:40:33 +1100 Subject: [PATCH] Fixed README --- README.rst | 64 +++++++++++++++++++++++++++++++++--------------------- setup.py | 2 +- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/README.rst b/README.rst index 15cdc25..ef7ab84 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,17 @@ Consumer Driven Contracts Testing. For further information about Pact project, c 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. +after all!*), and a Provider honours it. But, before that... + +Installation +~~~~~~~~~~~~ + +Pact Test is distributed through `PyPi `_ 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*) ------------------------------------- @@ -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*) ----------------------------------------- @@ -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 `_ 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 ~~~~~~~~~~~ @@ -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: @@ -200,7 +214,7 @@ possible to test all the versions at once with: $ ./bin/test all Upload New Version ------------------- +~~~~~~~~~~~~~~~~~~ .. code:: bash diff --git a/setup.py b/setup.py index 55dfa2d..9f94e74 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='pact-test', - version='0.3.102', + version='1.0.3', author='Guido Barbaglia', author_email='guido.barbaglia@gmail.com', packages=find_packages(),