Skip to content

Commit 46802e9

Browse files
committed
chore(dev): add markdownlint pre-commit
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>
1 parent dc73777 commit 46802e9

7 files changed

+104
-87
lines changed

.markdownlint.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
default: true
2+
list-marker-space:
3+
ul_single: 3
4+
ul_multi: 3
5+
ol_single: 2
6+
ol_multi: 2
7+
line-length: false

.pre-commit-config.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,13 @@ repos:
6565
types: [python]
6666
exclude: ^(pact|tests)/(?!v3/).*\.py$
6767
stages: [pre-push]
68+
69+
- repo: https://github.com/igorshubovych/markdownlint-cli
70+
rev: v0.38.0
71+
hooks:
72+
- id: markdownlint
73+
exclude: |
74+
(?x)^(
75+
.github/PULL_REQUEST_TEMPLATE\.md
76+
| CHANGELOG.md
77+
)

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ Working on your first Pull Request? You can learn how from this free video serie
131131
132132
Please make sure the following is done when submitting a pull request:
133133
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.
137137
138138
All pull requests should be opened against the `master` branch.
139139

README.md

+72-76
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ For more information about what Pact is, and how it can help you test your code
1010

1111
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.
1212

13-
# How to use pact-python
13+
## How to use pact-python
1414

15-
## Installation
15+
### Installation
1616

17-
```
17+
```console
1818
pip install pact-python
1919
```
2020

21-
## Getting started
21+
### Getting started
2222

2323
<!-- Absolute link for rendering page in docs.pact.io -->
2424

2525
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.
2626

27-
## Writing a Pact
27+
### Writing a Pact
2828

2929
Creating a complete contract is a two step process:
3030

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
3333

34-
## Writing the Consumer Test
34+
### Writing the Consumer Test
3535

3636
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.
3737

@@ -104,7 +104,7 @@ Using the Pact object as a [context manager], we call our method under test whic
104104
pact.verify()
105105
```
106106

107-
### Requests
107+
#### Requests
108108

109109
When defining the expected HTTP request that your code is expected to make you can specify the method, path, body, headers, and query:
110110

@@ -146,11 +146,11 @@ The mock service offers you several important features when building your contra
146146
- 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.
147147
- Finally, it will record your contracts as a JSON file that you can store in your repository or publish to a Pact broker.
148148

149-
## Expecting Variable Content
149+
### Expecting Variable Content
150150

151151
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:
152152

153-
### Term(matcher, generate)
153+
#### Term(matcher, generate)
154154

155155
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:
156156

@@ -171,7 +171,7 @@ body = {
171171

172172
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.
173173

174-
### Like(matcher)
174+
#### Like(matcher)
175175

176176
Asserts the element's type matches the matcher. For example:
177177

@@ -199,7 +199,7 @@ Like({
199199

200200
```
201201

202-
### EachLike(matcher, minimum=1)
202+
#### EachLike(matcher, minimum=1)
203203

204204
Asserts the value is an array type that consists of elements like the one passed in. It can be used to assert simple arrays:
205205

@@ -222,14 +222,16 @@ EachLike({
222222

223223
> 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.
224224
225+
<!-- block quote separator -->
226+
225227
> 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:
226228
227229
```python
228230
from pact.matchers import get_generated_values
229231
self.assertEqual(result, get_generated_values(expected))
230232
```
231233

232-
### Match common formats
234+
#### Match common formats
233235

234236
Often times, you find yourself having to re-write regular expressions for common formats.
235237

@@ -271,30 +273,30 @@ Like({
271273

272274
For more information see [Matching](https://docs.pact.io/getting_started/matching)
273275

274-
## Uploading pact files to a Pact Broker
276+
### Uploading pact files to a Pact Broker
275277

276278
There are two ways to publish your pact files, to a Pact Broker.
277279

278-
1. [Pact CLI tools](https://docs.pact.io/pact_broker/client_cli) **recommended**
279-
2. Pact Python API
280+
1. [Pact CLI tools](https://docs.pact.io/pact_broker/client_cli) **recommended**
281+
2. Pact Python API
280282

281-
### CLI
283+
#### Broker CLI
282284

283285
See [Publishing and retrieving pacts](https://docs.pact.io/pact_broker/publishing_and_retrieving_pacts)
284286

285287
Example uploading to a Pact Broker
286288

287-
```
289+
```console
288290
pact-broker publish /path/to/pacts/consumer-provider.json --consumer-app-version 1.0.0 --branch main --broker-base-url https://test.pactflow.io --broker-username someUsername --broker-password somePassword
289291
```
290292

291293
Example uploading to a PactFlow Broker
292294

293-
```
295+
```console
294296
pact-broker publish /path/to/pacts/consumer-provider.json --consumer-app-version 1.0.0 --branch main --broker-base-url https://test.pactflow.io --broker-token SomeToken
295297
```
296298

297-
### Python API
299+
#### Broker Python API
298300

299301
```python
300302
broker = Broker(broker_base_url="http://localhost")
@@ -319,11 +321,11 @@ The parameters for this differ slightly in naming from their CLI equivalents:
319321
| `--consumer-app-version` | `version` |
320322
| `n/a` | `consumer_name` |
321323

322-
## Verifying Pacts Against a Service
324+
### Verifying Pacts Against a Service
323325

324326
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.
325327

326-
### CLI
328+
#### Verifier CLI
327329

328330
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:
329331

@@ -341,80 +343,80 @@ Which will immediately invoke the Pact verifier, making HTTP requests to the ser
341343

342344
There are several options for configuring how the Pacts are verified:
343345

344-
###### --provider-base-url
346+
- **`--provider-base-url`**
345347

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.
347349

348-
###### --pact-url
350+
- **`--pact-url`**
349351

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.
351353

352-
```
353-
pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pacts/one.json --pact-url=./pacts/two.json
354-
```
354+
```console
355+
pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pacts/one.json --pact-url=./pacts/two.json
356+
```
355357

356-
###### --pact-urls
358+
- **`--pact-urls`**
357359

358-
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.
359361

360-
###### --provider-states-url
362+
- **`--provider-states-url`**
361363

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.
363365

364-
###### --provider-states-setup-url
366+
- **`--provider-states-setup-url`**
365367

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'}`.
367369

368-
###### --pact-broker-url
370+
- **`--pact-broker-url`**
369371

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`.
371373

372-
###### --pact-broker-username
374+
- **`--pact-broker-username`**
373375

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`.
375377

376-
###### --pact-broker-password
378+
- **`--pact-broker-password`**
377379

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`.
379381

380-
###### --pact-broker-token
382+
- **`--pact-broker-token`**
381383

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`.
383385

384-
###### --consumer-version-tag
386+
- **`--consumer-version-tag`**
385387

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.
387389

388-
###### --consumer-version-selector
390+
- **`--consumer-version-selector`**
389391

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/).
391393

392-
###### --provider-version-tag
394+
- **`--provider-version-tag`**
393395

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.
395397

396-
###### --provider-version-branch
398+
- **`--provider-version-branch`**
397399

398-
Branch to apply to the provider application version.
400+
Branch to apply to the provider application version.
399401

400-
###### --custom-provider-header
402+
- **`--custom-provider-header`**
401403

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.
404406

405-
###### -t, --timeout
407+
- **`-t, --timeout`**
406408

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.
408410

409-
###### -a, --provider-app-version
411+
- **`-a, --provider-app-version`**
410412

411-
The provider application version. Required for publishing verification results.
413+
The provider application version. Required for publishing verification results.
412414

413-
###### -r, --publish-verification-results
415+
- **`-r, --publish-verification-results`**
414416

415-
Publish verification results to the broker.
417+
Publish verification results to the broker.
416418

417-
### Python API
419+
#### Verifier Python API
418420

419421
You can use the Verifier class. This allows you to write native python code and the test framework of your choice.
420422

@@ -468,7 +470,7 @@ You can see more details in the examples
468470
- [Flask Provider Verifier Test](https://github.com/pact-foundation/pact-python/blob/master/examples/tests/test_01_provider_flask.py)
469471
- [FastAPI Provider Verifier Test](https://github.com/pact-foundation/pact-python/blob/master/examples/tests/test_01_provider_fastapi.py)
470472

471-
### Provider States
473+
#### Provider States
472474

473475
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.
474476

@@ -480,16 +482,16 @@ When setting up the testing of a provider you will also need to setup the manage
480482

481483
For more information about provider states, refer to the [Pact documentation] on [Provider States].
482484

483-
# Development
485+
## Development
484486

485487
<!-- Absolute link for rendering page in docs.pact.io -->
486488

487489
Please read [CONTRIBUTING.md](https://github.com/pact-foundation/pact-python/blob/master/CONTRIBUTING.md)
488490

489491
To setup a development environment:
490492

491-
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
493495

494496
To setup the environment, run tests, and package the application, run: `make release`
495497

@@ -499,25 +501,25 @@ This creates a `dist/pact-python-N.N.N.tar.gz` file, where the Ns are the curren
499501

500502
`pip install ./dist/pact-python-N.N.N.tar.gz`
501503

502-
## Offline Installation of Standalone Packages
504+
### Offline Installation of Standalone Packages
503505

504506
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.
505507

506-
```
508+
```console
507509
pip install pact-python --bin-path=/absolute/path/to/folder/containing/pact/binaries/for/your/os
508510
```
509511

510512
Pact binaries can be found at [Pact Ruby Releases](https://github.com/pact-foundation/pact-ruby-standalone/releases).
511513

512-
## Testing
514+
### Testing
513515

514516
This project has unit and end to end tests, which can both be run from make:
515517

516518
Unit: `make test`
517519

518520
End to end: `make e2e`
519521

520-
## Contact
522+
### Contact
521523

522524
Join us in slack: [![slack](https://slack.pact.io/badge.svg)](https://slack.pact.io)
523525

@@ -526,16 +528,10 @@ or
526528
- Twitter: [@pact_up](https://twitter.com/pact_up)
527529
- Stack Overflow: [stackoverflow.com/questions/tagged/pact](https://stackoverflow.com/questions/tagged/pact)
528530

529-
[bundler]: http://bundler.io/
530531
[context manager]: https://en.wikibooks.org/wiki/Python_Programming/Context_Managers
531-
[Pact]: https://docs.pact.io
532532
[Pact Broker]: https://docs.pact.io/pact_broker
533533
[Pact documentation]: https://docs.pact.io/
534-
[Pact Mock Service]: https://github.com/pact-foundation/pact-mock_service
535534
[Pact specification]: https://github.com/pact-foundation/pact-specification
536535
[Provider States]: https://docs.pact.io/getting_started/provider_states
537-
[pact-provider-verifier]: https://github.com/pact-foundation/pact-provider-verifier
538536
[pyenv]: https://github.com/pyenv/pyenv
539-
[rvm]: https://rvm.io/
540-
[rbenv]: https://github.com/rbenv/rbenv
541537
[virtualenv]: http://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/

0 commit comments

Comments
 (0)