Skip to content

Commit ceff89b

Browse files
YOU54FB3nnyLelliottmurray
authored
Publish verify branches (#306)
* feat: support branch * feat: support build-url parameter * chore: renaming test * feat: support auto_detect_version_properties parameter * chore: update comment * feat: set auto_detect_version_property default value to false * feat: support consumer message with branch, build_url and auto_detect_version_property * docs: chore add publishing instructions * chore: merge master * chore: support py3.10 and add contributing instructions * ci: 3.10 py version * chore: update pytest for 3.10 * ci: fail-fast false * chore: reduce complexity rules / add verification with broker to readme Co-authored-by: B3nnyL <13126965+B3nnyL@users.noreply.github.com> Co-authored-by: Elliott Murray <elliottmurray@gmail.com>
1 parent 89733d6 commit ceff89b

File tree

11 files changed

+126
-36
lines changed

11 files changed

+126
-36
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
22
ignore = E226,E302,E41,W503
33
max-line-length = 160
4-
max-complexity = 15
4+
max-complexity = 12
55
exclude = .git,venv,.venv,.tox,.pytest_cache,.direnv

.github/workflows/build_and_test.yml

+21-21
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ on: [push, pull_request]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
98
strategy:
109
matrix:
11-
python-version: [3.7, 3.8, 3.9]
10+
python-version: [3.7, 3.8, 3.9, "3.10"]
11+
fail-fast: false
1212

1313
steps:
14-
- uses: actions/checkout@v2
15-
- name: Set up Python ${{ matrix.python-version }}
16-
uses: actions/setup-python@v2
17-
with:
18-
python-version: ${{ matrix.python-version }}
19-
- name: Install dependencies
20-
run: |
21-
python -m pip install --upgrade pip
22-
pip install -r requirements_dev.txt
23-
- name: Lint with flake8, pydocstyle
24-
run: |
25-
flake8
26-
pydocstyle pact
27-
- name: Test with pytest
28-
run: |
29-
tox -e test
30-
- name: Test examples
31-
run: |
32-
make examples
14+
- uses: actions/checkout@v2
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -r requirements_dev.txt
23+
- name: Lint with flake8, pydocstyle
24+
run: |
25+
flake8
26+
pydocstyle pact
27+
- name: Test with pytest
28+
run: |
29+
tox -e test
30+
- name: Test examples
31+
run: |
32+
make examples

CONTRIBUTING.md

+27-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ _Before raising an issue, please ensure that you are using the latest version of
44

55
Please provide the following information with your issue to enable us to respond as quickly as possible.
66

7-
* The relevant versions of the packages you are using.
8-
* The steps to recreate your issue.
9-
* The full stacktrace if there is an exception.
10-
* An executable code example where possible. You can fork this repository and use the [e2e] directory to quickly recreate your issue.
7+
- The relevant versions of the packages you are using.
8+
- The steps to recreate your issue.
9+
- The full stacktrace if there is an exception.
10+
- An executable code example where possible. You can fork this repository and use the [e2e] directory to quickly recreate your issue.
1111

1212
# Contributing
1313

@@ -27,6 +27,7 @@ you submit.
2727
[e2e]: https://github.com/pact-foundation/pact-python/tree/master/e2e
2828

2929
## Commit messages
30+
3031
Pact Python is adopting the Conventional Changelog commit message conventions. Please ensure you follow the guidelines, we don't want to be that person, but the commit messages are very important to the automation of our release process.
3132

3233
Take a look at the git history (git log) to get the gist of it.
@@ -40,4 +41,25 @@ npm i -g cz-conventional-changelog
4041

4142
git cz to commit and commitizen will guide you.
4243

43-
There is a pypi package that does similar [commitizen]: https://pypi.org/project/commitizen/. This would make a great feature to add! There is a check on the travis build that your commits follow this convention. On creating a PR any commits that don't will instantly fail the build and you will have to rename them.
44+
There is a pypi package that does similar [commitizen]: https://pypi.org/project/commitizen/. This would make a great feature to add! There is a check on the travis build that your commits follow this convention. On creating a PR any commits that don't will instantly fail the build and you will have to rename them.
45+
46+
## Running the tests
47+
48+
You can run the tests locally with `make test`, this will run the tests with `tox`
49+
50+
You will need `pyenv` to test on different versions `3.6`, `3.7`, `3.8`, `3.9`, `3.10`
51+
52+
`pyenv install 3.6.15 3.7.13 3.8.13 3.9.14 3.10.6` - Download and install python versions
53+
`pyenv local 3.6.15 3.8.13 3.7.13 3.9.14 3.10.6` - Set these versions locally for the project
54+
`make test` - Run the tests
55+
56+
### MacOS Setup Guide
57+
58+
See the following guides to setup `Python` and configure `pyenv` on your Mac.
59+
60+
- https://yellowdesert.consulting/2018/02/04/python-on-mac-one-of-the-good-ways/
61+
- https://yellowdesert.consulting/2020/10/24/tox-testing-multiple-python-versions-with-pyenv/
62+
63+
## Running the examples
64+
65+
Make sure you have docker running!

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ help:
1111
@echo ""
1212
@echo " clean to clear build and distribution directories"
1313
@echo " deps to install the required files for development"
14-
@echo " verifier to run the verifier end to end tests"
1514
@echo " examples to run the example end to end tests (consumer, fastapi, flask, messaging)"
1615
@echo " consumer to run the example consumer tests"
1716
@echo " fastapi to run the example FastApi provider tests"
@@ -136,4 +135,4 @@ venv:
136135
ln -sf ${CURDIR}/.venv ~/.pyenv/versions/${PROJECT}
137136

138137
@echo "\n$(green)Use it! (populate .python-version)$(sgr0)"
139-
pyenv local ${PROJECT}
138+
pyenv local ${PROJECT}

README.md

+70-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,54 @@ Like({
290290

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

293+
## Uploading pact files to a Pact Broker
294+
295+
There are two ways to publish your pact files, to a Pact Broker.
296+
297+
1. [Pact CLI tools](https://docs.pact.io/pact_broker/client_cli) **recommended**
298+
2. Pact Python API
299+
300+
### CLI
301+
302+
See [Publishing and retrieving pacts](https://docs.pact.io/pact_broker/publishing_and_retrieving_pacts)
303+
304+
Example uploading to a Pact Broker
305+
306+
```
307+
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
308+
```
309+
310+
Example uploading to a Pactflow Broker
311+
312+
```
313+
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
314+
```
315+
316+
### Python API
317+
318+
```python
319+
broker = Broker(broker_base_url="http://localhost")
320+
broker.publish("TestConsumer",
321+
"2.0.1",
322+
branch='consumer-branch',
323+
pact_dir='.')
324+
325+
output, logs = verifier.verify_pacts('./userserviceclient-userservice.json')
326+
327+
```
328+
329+
The parameters for this differ slightly in naming from their CLI equivalents:
330+
| CLI | native Python |
331+
|-----------------|-------------------------------------------------------------------------------------------------|
332+
| `--branch` | `branch` |
333+
| `--build-url` | `build_url` |
334+
| `--auto-detect-version-properties` | `auto_detect_version_properties` |
335+
| `--tag=TAG` | `consumer_tags` |
336+
| `--tag-with-git-branch` | `tag_with_git_branch` |
337+
| `PACT_DIRS_OR_FILES` | `pact_dir` |
338+
| `--consumer-app-version` | `version` |
339+
| `n/a` | `consumer_name` |
340+
293341
## Verifying Pacts Against a Service
294342

295343
In addition to writing Pacts for Python consumers, you can also verify those Pacts
@@ -409,7 +457,28 @@ You can use the Verifier class. This allows you to write native python code and
409457
verifier = Verifier(provider='UserService',
410458
provider_base_url=PACT_URL)
411459

412-
output, logs = verifier.verify_pacts('./userserviceclient-userservice.json')
460+
# Using a local pact file
461+
462+
success, logs = verifier.verify_pacts('./userserviceclient-userservice.json')
463+
assert success == 0
464+
465+
# Using a pact broker
466+
467+
- For OSS Pact Broker, use broker_username / broker_password
468+
- For Pactflow Pact Broker, use broker_token
469+
470+
success, logs = verifier.verify_with_broker(
471+
# broker_username=PACT_BROKER_USERNAME,
472+
# broker_password=PACT_BROKER_PASSWORD,
473+
broker_url=PACT_BROKER_URL,
474+
broker_token=PACT_BROKER_TOKEN,
475+
publish_version=APPLICATION_VERSION,
476+
publish_verification_results=True,
477+
verbose=True,
478+
provider_version_branch=PROVIDER_BRANCH,
479+
enable_pending=True,
480+
)
481+
assert success == 0
413482

414483
```
415484

examples/consumer/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pytest==5.4.1
1+
pytest==7.1.3
22
requests>=2.26.0
33
testcontainers==3.3.0
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fastapi==0.67.0
2-
pytest==5.4.1
2+
pytest==7.1.3
33
requests>=2.26.0
44
uvicorn>=0.14.0
55
testcontainers==3.3.0
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Flask==1.1.4
2-
pytest==5.4.1
2+
pytest==7.1.3
33
requests>=2.26.0
44
testcontainers==3.3.0
55
markupsafe==2.0.1

examples/message/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==1.1.1
2-
pytest==5.4.1
2+
pytest==7.1.3
33
requests>=2.26.0

requirements_dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ psutil==5.7.0
88
pycodestyle==2.6.0
99
pydocstyle==4.0.1
1010
tox==3.14.0
11-
pytest==5.4.1
11+
pytest==7.1.3
1212
pytest-cov==2.11.1
1313
requests>=2.26.0
1414
tox-travis==0.8

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist=py{36,37,38,39}-{test,install}
2+
envlist=py{36,37,38,39,310}-{test,install}
33
[testenv]
44
deps=
55
test: -rrequirements_dev.txt

0 commit comments

Comments
 (0)