You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-12Lines changed: 44 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@
7
7
Python version of Pact. Enables consumer driven contract testing,
8
8
providing a mock service and DSL for the consumer project, and
9
9
interaction playback and verification for the service provider project.
10
+
Currently supports version 2 of the [Pact specification].
10
11
11
12
For more information about what Pact is, and how it can help you
12
13
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,
102
103
result = user('UserA')
103
104
# Some additional steps before verifying all interactions have occurred
104
105
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.
106
136
107
137
The default hostname and port for the Pact mock service will be
108
138
`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
156
186
provider, the regex will be used to search the response from the real provider service
157
187
and the test will be considered successful if the regex finds a match in the response.
158
188
159
-
### SomethingLike(matcher)
189
+
### Like(matcher)
160
190
Asserts the element's type matches the matcher. For example:
161
191
162
192
```python
163
-
from pact importSomethingLike
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 importLike
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
167
197
```
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.
169
199
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.
171
201
172
202
```python
173
-
SomethingLike({
203
+
from pact import Like, Term
204
+
Like({
174
205
'username': Term('[a-zA-Z]+', 'username'),
175
206
'id': 123, # integer
176
-
'confirmed': false, # boolean
207
+
'confirmed': False, # boolean
177
208
'address': { # dictionary
178
209
'street': '200 Bourke St'# string
179
210
}
@@ -194,7 +225,7 @@ EachLike('hello') # All items are strings
194
225
Or other matchers can be nested inside to assert more complex objects:
195
226
196
227
```python
197
-
from pact import EachLike, SomethingLike, Term
228
+
from pact import EachLike, Term
198
229
EachLike({
199
230
'username': Term('[a-zA-Z]+', 'username'),
200
231
'id': 123,
@@ -278,7 +309,7 @@ states to communicate from the consumer what data should exist on the provider.
278
309
279
310
When setting up the testing of a provider you will also need to setup the management of
280
311
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
282
313
on the provider application or a separate one. Some strategies for managing state include:
283
314
284
315
- Having endpoints in your application that are not active in production that create and delete your datastore state
0 commit comments