Skip to content

Commit c1a5402

Browse files
authored
Merge pull request #2 from pact-foundation/master
merge upstream
2 parents b91f6c3 + 1bcb7d5 commit c1a5402

File tree

13 files changed

+96
-36
lines changed

13 files changed

+96
-36
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
### 0.9.0
2+
* 735aa87 - Set new project minimum requirements (Matthew Balvanz, Sun Oct 22 16:30:12 2017 -0500)
3+
* 295f17c - Merge pull request #60 from ftobia/requirements (Matthew Balvanz, Sun Oct 22 16:09:59 2017 -0500)
4+
* 1dc72da - Merge pull request #48 from bassdread/allow-later-versions-of-requests (Matthew Balvanz, Sun Oct 22 16:09:39 2017 -0500)
5+
* 3265b45 - add suggestion (Chris Hannam, Fri Oct 20 09:33:05 2017 +0100)
6+
* 33504a6 - Resolve #51 verify outputs text instead of bytes (Matthew Balvanz, Thu Oct 19 21:28:39 2017 -0500)
7+
* 51dcda3 - Merge pull request #57 from jceplaras/fix-e2e-test-incorrect-number-of-arg (Matthew Balvanz, Thu Oct 19 20:57:49 2017 -0500)
8+
* 1a4d136 - Relax version requirements in setup.py (vs requirements.txt) (ftobia, Fri Oct 13 19:42:46 2017 -0400)
9+
* 8ece1d6 - Fix incorrect indent on test_incorrect_number_of_arguments on test_e2e (James Plaras, Fri Oct 13 12:54:56 2017 +0800)
10+
* 5f8257b - Resolve #50: Note which version of the Pact specification is supported (Matthew Balvanz, Sat Oct 7 14:05:26 2017 -0500)
11+
* e728301 - Resolve #45: Document request query parameter (Matthew Balvanz, Sat Oct 7 13:58:07 2017 -0500)
12+
* 5de7200 - Merge pull request #49 from pact-foundation/rename-somethinglike (Matt Fellows, Wed Oct 4 22:36:21 2017 +1100)
13+
* d73aa1c - Resolve #43: Rename SomethingLike to Like (Matthew Balvanz, Mon Sep 4 15:49:13 2017 -0500)
14+
* a07c8b6 - Merge pull request #46 from bassdread/fix-setup-url-name (Matthew Balvanz, Mon Sep 4 15:44:45 2017 -0500)
15+
* b5e1f95 - allow later versions of requests (Chris Hannam, Tue Aug 29 13:38:42 2017 +0100)
16+
* 08fe123 - make setup-url name format match above reference (Chris Hannam, Fri Aug 25 11:03:35 2017 +0100)
17+
118
### 0.8.0
219
* edb6c72 - Merge pull request #41 from pact-foundation/fix-running-on-windows (Matthew Balvanz, Thu Aug 10 21:39:27 2017 -0500)
320
* 244fff1 - Merge pull request #42 from pact-foundation/deprecate-provider-states-url (Matthew Balvanz, Thu Aug 10 21:38:44 2017 -0500)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ clean:
2525

2626
.PHONY: deps
2727
deps:
28-
pip install -r requirements_dev.txt
28+
pip install -r requirements_dev.txt -e .
2929

3030

3131
define E2E

README.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Python version of Pact. Enables consumer driven contract testing,
88
providing a mock service and DSL for the consumer project, and
99
interaction playback and verification for the service provider project.
10+
Currently supports version 2 of the [Pact specification].
1011

1112
For more information about what Pact is, and how it can help you
1213
test your code more efficiently, check out the [Pact documentation].
@@ -102,7 +103,36 @@ configured and the interactions verified, use the `setup` and `verify` methods,
102103
result = user('UserA')
103104
# Some additional steps before verifying all interactions have occurred
104105
pact.verify()
105-
````
106+
```
107+
108+
### Requests
109+
110+
When defining the expected HTTP request that your code is expected to make you
111+
can specify the method, path, body, headers, and query:
112+
113+
```python
114+
pact.with_request(
115+
method='GET',
116+
path='/api/v1/my-resources/',
117+
query={'search': 'example'}
118+
)
119+
```
120+
121+
`query` is used to specify URL query parameters, so the above example expects
122+
a request made to `/api/v1/my-resources/?search=example`.
123+
124+
```python
125+
pact.with_request(
126+
method='POST',
127+
path='/api/v1/my-resources/123',
128+
body={'user_ids': [1, 2, 3]},
129+
headers={'Content-Type': 'application/json'},
130+
)
131+
```
132+
133+
You can define exact values for your expected request like the examples above,
134+
or you can use the matchers defined later to assist in handling values that are
135+
variable.
106136

107137
The default hostname and port for the Pact mock service will be
108138
`localhost:1234` but you can adjust this during Pact creation:
@@ -156,24 +186,25 @@ as `generate`, in this case `2016-12-15T20:16:01`. When the contract is verified
156186
provider, the regex will be used to search the response from the real provider service
157187
and the test will be considered successful if the regex finds a match in the response.
158188

159-
### SomethingLike(matcher)
189+
### Like(matcher)
160190
Asserts the element's type matches the matcher. For example:
161191

162192
```python
163-
from pact import SomethingLike
164-
SomethingLike(123) # Matches if the value is an integer
165-
SomethingLike('hello world') # Matches if the value is a string
166-
SomethingLike(3.14) # Matches if the value is a float
193+
from pact import Like
194+
Like(123) # Matches if the value is an integer
195+
Like('hello world') # Matches if the value is a string
196+
Like(3.14) # Matches if the value is a float
167197
```
168-
The argument supplied to `SomethingLike` will be what the mock service responds with.
198+
The argument supplied to `Like` will be what the mock service responds with.
169199

170-
When a dictionary is used as an argument for SomethingLike, all the child objects (and their child objects etc.) will be matched according to their types, unless you use a more specific matcher like a Term.
200+
When a dictionary is used as an argument for Like, all the child objects (and their child objects etc.) will be matched according to their types, unless you use a more specific matcher like a Term.
171201

172202
```python
173-
SomethingLike({
203+
from pact import Like, Term
204+
Like({
174205
'username': Term('[a-zA-Z]+', 'username'),
175206
'id': 123, # integer
176-
'confirmed': false, # boolean
207+
'confirmed': False, # boolean
177208
'address': { # dictionary
178209
'street': '200 Bourke St' # string
179210
}
@@ -194,7 +225,7 @@ EachLike('hello') # All items are strings
194225
Or other matchers can be nested inside to assert more complex objects:
195226

196227
```python
197-
from pact import EachLike, SomethingLike, Term
228+
from pact import EachLike, Term
198229
EachLike({
199230
'username': Term('[a-zA-Z]+', 'username'),
200231
'id': 123,
@@ -278,7 +309,7 @@ states to communicate from the consumer what data should exist on the provider.
278309

279310
When setting up the testing of a provider you will also need to setup the management of
280311
these provider states. The Pact verifier does this by making additional HTTP requests to
281-
the `provider_states_setup_url` you provide. This URL could be
312+
the `--provider-states-setup-url` you provide. This URL could be
282313
on the provider application or a separate one. Some strategies for managing state include:
283314

284315
- Having endpoints in your application that are not active in production that create and delete your datastore state
@@ -321,6 +352,7 @@ End to end: `make e2e`
321352
[Pact Broker]: https://docs.pact.io/documentation/sharings_pacts.html
322353
[Pact documentation]: https://docs.pact.io/
323354
[Pact Mock Service]: https://github.com/bethesque/pact-mock_service
355+
[Pact specification]: https://github.com/pact-foundation/pact-specification
324356
[Provider States]: https://docs.pact.io/documentation/provider_states.html
325357
[pact-provider-verifier]: https://github.com/pact-foundation/pact-provider-verifier
326358
[pyenv]: https://github.com/pyenv/pyenv

e2e/contracts/test_e2e.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,7 @@ def two(a, b):
157157
with pact:
158158
two('one')
159159

160-
self.assertEqual(
161-
e.exception.message, 'two() takes exactly 2 arguments (1 given)')
160+
self.assertEqual(
161+
e.exception.message,
162+
'two() takes exactly 2 arguments (1 given)'
163+
)

pact/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Python methods for interactive with a Pact Mock Service."""
22
from .consumer import Consumer
3-
from .matchers import EachLike, SomethingLike, Term
3+
from .matchers import EachLike, Like, SomethingLike, Term
44
from .pact import Pact
55
from .provider import Provider
66
from .__version__ import __version__ # noqa: F401
77

8-
__all__ = ('Consumer', 'EachLike', 'Pact', 'Provider', 'SomethingLike', 'Term')
8+
__all__ = ('Consumer', 'EachLike', 'Like', 'Pact', 'Provider', 'SomethingLike',
9+
'Term')

pact/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Pact version info."""
22

3-
__version__ = '0.8.0'
3+
__version__ = '0.9.0'

pact/matchers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def generate(self):
6666
'min': self.minimum}
6767

6868

69-
class SomethingLike(Matcher):
69+
class Like(Matcher):
7070
"""
7171
Expect the type of the value to be the same as matcher.
7272
@@ -79,7 +79,7 @@ class SomethingLike(Matcher):
7979
... .upon_receiving('a request for a random number')
8080
... .with_request('get', '/generate-number')
8181
... .will_respond_with(200, body={
82-
... 'number': SomethingLike(1111222233334444)
82+
... 'number': Like(1111222233334444)
8383
... }))
8484
8585
Would expect the response body to be a JSON object, containing the key
@@ -120,6 +120,10 @@ def generate(self):
120120
'contents': from_term(self.matcher)}
121121

122122

123+
# Remove SomethingLike in major version 1.0.0
124+
SomethingLike = Like
125+
126+
123127
class Term(Matcher):
124128
"""
125129
Expect the response to match a specified regular expression.

pact/pact.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ def setup(self):
114114
resp = requests.delete(
115115
self.uri + '/interactions', headers=self.HEADERS)
116116

117-
assert resp.status_code == 200, resp.content
117+
assert resp.status_code == 200, resp.text
118118
resp = requests.put(
119119
self.uri + '/interactions',
120120
headers=self.HEADERS,
121121
json={"interactions": self._interactions})
122122

123-
assert resp.status_code == 200, resp.content
123+
assert resp.status_code == 200, resp.text
124124
except AssertionError:
125125
raise
126126

@@ -191,15 +191,15 @@ def verify(self):
191191
resp = requests.get(
192192
self.uri + '/interactions/verification',
193193
headers=self.HEADERS)
194-
assert resp.status_code == 200, resp.content
194+
assert resp.status_code == 200, resp.text
195195
payload = {
196196
'consumer': {'name': self.consumer.name},
197197
'provider': {'name': self.provider.name},
198198
'pact_dir': self.pact_dir
199199
}
200200
resp = requests.post(
201201
self.uri + '/pact', headers=self.HEADERS, json=payload)
202-
assert resp.status_code == 200, resp.content
202+
assert resp.status_code == 200, resp.text
203203

204204
def with_request(self, method, path, body=None, headers=None, query=None):
205205
"""

pact/test/test_matchers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from unittest import TestCase
22

3-
from ..matchers import EachLike, Matcher, SomethingLike, Term, from_term
3+
from ..matchers import EachLike, Like, Matcher, SomethingLike, Term, from_term
44

55

66
class MatcherTestCase(TestCase):
@@ -56,6 +56,11 @@ def test_nested_matchers(self):
5656
'min': 1})
5757

5858

59+
class LikeTestCase(TestCase):
60+
def test_is_something_like(self):
61+
self.assertIs(SomethingLike, Like)
62+
63+
5964
class SomethingLikeTestCase(TestCase):
6065
def test_valid_types(self):
6166
types = [None, list(), dict(), 1, 1.0, 'string', u'unicode', Matcher()]

pact/test/test_pact.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def setUp(self):
173173

174174
def test_error_deleting_interactions(self):
175175
self.mock_requests.side_effect = iter([
176-
Mock(status_code=500, content='deletion error')])
176+
Mock(status_code=500, text='deletion error')])
177177

178178
with self.assertRaises(AssertionError) as e:
179179
self.target.setup()
@@ -185,7 +185,7 @@ def test_error_deleting_interactions(self):
185185
def test_error_posting_interactions(self):
186186
self.mock_requests.side_effect = iter([
187187
Mock(status_code=200),
188-
Mock(status_code=500, content='post interactions error')])
188+
Mock(status_code=500, text='post interactions error')])
189189

190190
with self.assertRaises(AssertionError) as e:
191191
self.target.setup()
@@ -387,7 +387,7 @@ def test_success(self):
387387

388388
def test_error_verifying_interactions(self):
389389
self.mock_requests.side_effect = iter([
390-
Mock(status_code=500, content='verification error')])
390+
Mock(status_code=500, text='verification error')])
391391

392392
with self.assertRaises(AssertionError) as e:
393393
self.target.verify()
@@ -400,7 +400,7 @@ def test_error_verifying_interactions(self):
400400
def test_error_writing_pacts_to_file(self):
401401
self.mock_requests.side_effect = iter([
402402
Mock(status_code=200),
403-
Mock(status_code=500, content='error writing pact to file')])
403+
Mock(status_code=500, text='error writing pact to file')])
404404

405405
with self.assertRaises(AssertionError) as e:
406406
self.target.verify()

0 commit comments

Comments
 (0)