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
Markdownlint checks Markdown files for simple issues and formatting. The
markdownlint configuration ensures consistency with the existing
editorconfig.
Signed-off-by: JP-Ellis <josh@jpellis.me>
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -131,9 +131,9 @@ Working on your first Pull Request? You can learn how from this free video serie
131
131
132
132
Please make sure the following is done when submitting a pull request:
133
133
134
-
1. **Keep your PR small.** Small pull requests (~300 lines of diff) are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it.
135
-
2. **Use descriptive titles.** It is recommended to follow this [commit message style](#semantic-commit-messages).
136
-
3. **Test your changes.** Describe your [**test plan**](#test-plan) in your pull request description.
134
+
1. **Keep your PR small.** Small pull requests (~300 lines of diff) are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it.
135
+
2. **Use descriptive titles.** It is recommended to follow this [commit message style](#conventional-commit-messages).
136
+
3. **Test your changes.** Describe your [**test plan**](#test-plan) in your pull request description.
137
137
138
138
All pull requests should be opened against the `master` branch.
Copy file name to clipboardexpand all lines: README.md
+72-76
Original file line number
Diff line number
Diff line change
@@ -10,28 +10,28 @@ For more information about what Pact is, and how it can help you test your code
10
10
11
11
Note: As of Version 1.0 deprecates support for python 2.7 to allow us to incorporate python 3.x features more readily. If you want to still use Python 2.7 use the 0.x.y versions. Only bug fixes will now be added to that release.
12
12
13
-
# How to use pact-python
13
+
##How to use pact-python
14
14
15
-
## Installation
15
+
###Installation
16
16
17
-
```
17
+
```console
18
18
pip install pact-python
19
19
```
20
20
21
-
## Getting started
21
+
###Getting started
22
22
23
23
<!-- Absolute link for rendering page in docs.pact.io -->
24
24
25
25
A guide follows but if you go to the [examples](https://github.com/pact-foundation/pact-python/tree/master/examples). This has a consumer, provider and pact-broker set of tests for both FastAPI and Flask.
26
26
27
-
## Writing a Pact
27
+
###Writing a Pact
28
28
29
29
Creating a complete contract is a two step process:
30
30
31
-
1. Create a test on the consumer side that declares the expectations it has of the provider
32
-
2. Create a provider state that allows the contract to pass when replayed against the provider
31
+
1.Create a test on the consumer side that declares the expectations it has of the provider
32
+
2.Create a provider state that allows the contract to pass when replayed against the provider
33
33
34
-
## Writing the Consumer Test
34
+
###Writing the Consumer Test
35
35
36
36
If we have a method that communicates with one of our external services, which we'll call `Provider`, and our product, `Consumer` is hitting an endpoint on `Provider` at `/users/<user>` to get information about a particular user.
37
37
@@ -104,7 +104,7 @@ Using the Pact object as a [context manager], we call our method under test whic
104
104
pact.verify()
105
105
```
106
106
107
-
### Requests
107
+
####Requests
108
108
109
109
When defining the expected HTTP request that your code is expected to make you can specify the method, path, body, headers, and query:
110
110
@@ -146,11 +146,11 @@ The mock service offers you several important features when building your contra
146
146
- If a request is made that does not match one you defined or if a request from your code is missing it will return an error with details.
147
147
- Finally, it will record your contracts as a JSON file that you can store in your repository or publish to a Pact broker.
148
148
149
-
## Expecting Variable Content
149
+
###Expecting Variable Content
150
150
151
151
The above test works great if that user information is always static, but what happens if the user has a last updated field that is set to the current time every time the object is modified? To handle variable data and make your tests more robust, there are 3 helpful matchers:
152
152
153
-
### Term(matcher, generate)
153
+
####Term(matcher, generate)
154
154
155
155
Asserts the value should match the given regular expression. You could use this to expect a timestamp with a particular format in the request or response where you know you need a particular format, but are unconcerned about the exact date:
156
156
@@ -171,7 +171,7 @@ body = {
171
171
172
172
When you run the tests for the consumer, the mock service will return the value you provided as `generate`, in this case `2016-12-15T20:16:01`. When the contract is verified on the provider, the regex will be used to search the response from the real provider service and the test will be considered successful if the regex finds a match in the response.
173
173
174
-
### Like(matcher)
174
+
####Like(matcher)
175
175
176
176
Asserts the element's type matches the matcher. For example:
177
177
@@ -199,7 +199,7 @@ Like({
199
199
200
200
```
201
201
202
-
### EachLike(matcher, minimum=1)
202
+
####EachLike(matcher, minimum=1)
203
203
204
204
Asserts the value is an array type that consists of elements like the one passed in. It can be used to assert simple arrays:
205
205
@@ -222,14 +222,16 @@ EachLike({
222
222
223
223
> Note, you do not need to specify everything that will be returned from the Provider in a JSON response, any extra data that is received will be ignored and the tests will still pass.
224
224
225
+
<!-- block quote separator -->
226
+
225
227
> Note, to get the generated values from an object that can contain matchers like Term, Like, EachLike, etc. for assertion in self.assertEqual(result, expected) you may need to use get_generated_values() helper function:
@@ -319,11 +321,11 @@ The parameters for this differ slightly in naming from their CLI equivalents:
319
321
|`--consumer-app-version`|`version`|
320
322
|`n/a`|`consumer_name`|
321
323
322
-
## Verifying Pacts Against a Service
324
+
###Verifying Pacts Against a Service
323
325
324
326
In addition to writing Pacts for Python consumers, you can also verify those Pacts against a provider of any language. There are two ways to do this.
325
327
326
-
### CLI
328
+
#### Verifier CLI
327
329
328
330
After installing pact-python a `pact-verifier` application should be available. To get details about its use you can call it with the help argument:
329
331
@@ -341,80 +343,80 @@ Which will immediately invoke the Pact verifier, making HTTP requests to the ser
341
343
342
344
There are several options for configuring how the Pacts are verified:
343
345
344
-
###### --provider-base-url
346
+
-**`--provider-base-url`**
345
347
346
-
Required. Defines the URL of the server to make requests to when verifying the Pacts.
348
+
Required. Defines the URL of the server to make requests to when verifying the Pacts.
347
349
348
-
###### --pact-url
350
+
-**`--pact-url`**
349
351
350
-
Required if --pact-urls not specified. The location of a Pact file you want to verify. This can be a URL to a [Pact Broker] or a local path, to provide multiple files, specify multiple arguments.
352
+
Required if --pact-urls not specified. The location of a Pact file you want to verify. This can be a URL to a [Pact Broker] or a local path, to provide multiple files, specify multiple arguments.
Required if --pact-url not specified. The location of the Pact files you want to verify. This can be a URL to a [Pact Broker] or one or more local paths, separated by a comma.
360
+
Required if --pact-url not specified. The location of the Pact files you want to verify. This can be a URL to a [Pact Broker] or one or more local paths, separated by a comma.
359
361
360
-
###### --provider-states-url
362
+
- **`--provider-states-url`**
361
363
362
-
_DEPRECATED AFTER v 0.6.0._ The URL where your provider application will produce the list of available provider states. The verifier calls this URL to ensure the Pacts specify valid states before making the HTTP requests.
364
+
_DEPRECATED AFTER v 0.6.0._ The URL where your provider application will produce the list of available provider states. The verifier calls this URL to ensure the Pacts specify valid states before making the HTTP requests.
363
365
364
-
###### --provider-states-setup-url
366
+
- **`--provider-states-setup-url`**
365
367
366
-
The URL which should be called to setup a specific provider state before a Pact is verified. This URL will be called with a POST request, and the JSON body `{consumer: 'Consumer name', state: 'a thing exists'}`.
368
+
The URL which should be called to setup a specific provider state before a Pact is verified. This URL will be called with a POST request, and the JSON body `{consumer: 'Consumer name', state: 'a thing exists'}`.
367
369
368
-
###### --pact-broker-url
370
+
- **`--pact-broker-url`**
369
371
370
-
Base URl for the Pact Broker instance to publish pacts to. Can also be specified via the environment variable `PACT_BROKER_BASE_URL`.
372
+
Base URl for the Pact Broker instance to publish pacts to. Can also be specified via the environment variable `PACT_BROKER_BASE_URL`.
371
373
372
-
###### --pact-broker-username
374
+
- **`--pact-broker-username`**
373
375
374
-
The username to use when contacting the Pact Broker. Can also be specified via the environment variable `PACT_BROKER_USERNAME`.
376
+
The username to use when contacting the Pact Broker. Can also be specified via the environment variable `PACT_BROKER_USERNAME`.
375
377
376
-
###### --pact-broker-password
378
+
- **`--pact-broker-password`**
377
379
378
-
The password to use when contacting the Pact Broker. You can also specify this value as the environment variable `PACT_BROKER_PASSWORD`.
380
+
The password to use when contacting the Pact Broker. You can also specify this value as the environment variable `PACT_BROKER_PASSWORD`.
379
381
380
-
###### --pact-broker-token
382
+
- **`--pact-broker-token`**
381
383
382
-
The bearer token to use when contacting the Pact Broker. You can also specify this value as the environment variable `PACT_BROKER_TOKEN`.
384
+
The bearer token to use when contacting the Pact Broker. You can also specify this value as the environment variable `PACT_BROKER_TOKEN`.
383
385
384
-
###### --consumer-version-tag
386
+
- **`--consumer-version-tag`**
385
387
386
-
Retrieve the latest pacts with this consumer version tag. Used in conjunction with `--provider`. May be specified multiple times.
388
+
Retrieve the latest pacts with this consumer version tag. Used in conjunction with `--provider`. May be specified multiple times.
387
389
388
-
###### --consumer-version-selector
390
+
- **`--consumer-version-selector`**
389
391
390
-
You can also retrieve pacts with consumer version selector, a more flexible approach in specifying which pacts you need. May be specified multiple times. Read more about selectors [here](https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/).
392
+
You can also retrieve pacts with consumer version selector, a more flexible approach in specifying which pacts you need. May be specified multiple times. Read more about selectors [here](https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/).
391
393
392
-
###### --provider-version-tag
394
+
- **`--provider-version-tag`**
393
395
394
-
Tag to apply to the provider application version. May be specified multiple times.
396
+
Tag to apply to the provider application version. May be specified multiple times.
395
397
396
-
###### --provider-version-branch
398
+
- **`--provider-version-branch`**
397
399
398
-
Branch to apply to the provider application version.
400
+
Branch to apply to the provider application version.
399
401
400
-
###### --custom-provider-header
402
+
- **`--custom-provider-header`**
401
403
402
-
Header to add to provider state set up and pact verification requests e.g.`Authorization: Basic cGFjdDpwYWN0`
403
-
May be specified multiple times.
404
+
Header to add to provider state set up and pact verification requests e.g.`Authorization: Basic cGFjdDpwYWN0`
405
+
May be specified multiple times.
404
406
405
-
###### -t, --timeout
407
+
- **`-t, --timeout`**
406
408
407
-
The duration in seconds we should wait to confirm that the verification process was successful. Defaults to 30.
409
+
The duration in seconds we should wait to confirm that the verification process was successful. Defaults to 30.
408
410
409
-
###### -a, --provider-app-version
411
+
- **`-a, --provider-app-version`**
410
412
411
-
The provider application version. Required for publishing verification results.
413
+
The provider application version. Required for publishing verification results.
412
414
413
-
###### -r, --publish-verification-results
415
+
- **`-r, --publish-verification-results`**
414
416
415
-
Publish verification results to the broker.
417
+
Publish verification results to the broker.
416
418
417
-
### Python API
419
+
#### Verifier Python API
418
420
419
421
You can use the Verifier class. This allows you to write native python code and the test framework of your choice.
420
422
@@ -468,7 +470,7 @@ You can see more details in the examples
In many cases, your contracts will need very specific data to exist on the provider to pass successfully. If you are fetching a user profile, that user needs to exist, if querying a list of records, one or more records needs to exist. To support decoupling the testing of the consumer and provider, Pact offers the idea of provider states to communicate from the consumer what data should exist on the provider.
474
476
@@ -480,16 +482,16 @@ When setting up the testing of a provider you will also need to setup the manage
480
482
481
483
For more information about provider states, refer to the [Pact documentation] on [Provider States].
482
484
483
-
# Development
485
+
##Development
484
486
485
487
<!-- Absolute link for rendering page in docs.pact.io -->
1. If you want to run tests for all Python versions, install 2.7, 3.3, 3.4, 3.5, and 3.6 from source or using a tool like [pyenv]
492
-
2. Its recommended to create a Python [virtualenv] for the project
493
+
1.If you want to run tests for all Python versions, install 2.7, 3.3, 3.4, 3.5, and 3.6 from source or using a tool like [pyenv]
494
+
2.Its recommended to create a Python [virtualenv] for the project
493
495
494
496
To setup the environment, run tests, and package the application, run: `make release`
495
497
@@ -499,25 +501,25 @@ This creates a `dist/pact-python-N.N.N.tar.gz` file, where the Ns are the curren
499
501
500
502
`pip install ./dist/pact-python-N.N.N.tar.gz`
501
503
502
-
## Offline Installation of Standalone Packages
504
+
###Offline Installation of Standalone Packages
503
505
504
506
Although all Ruby standalone applications are predownloaded into the wheel artifact, it may be useful, for development, purposes to install custom Ruby binaries. In which case, use the `bin-path` flag.
0 commit comments