Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: PactV3 / VerifierV3 / MessageProvider interface (powered by pact_ffi) #367

Closed
wants to merge 177 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
46703bc
feat(V3): added the todo provider (from Pact-JS)
May 29, 2020
fa2e6d0
feat: first initial consumer test with pact-rust mock server
May 31, 2020
c938353
feat: implemented some V3 matchers
May 31, 2020
628bdfd
feat(V3): write out the pact file on successful test
Jun 1, 2020
d1b4486
feat(V3): add the Pact python version to the pact metadata
Jun 1, 2020
78d37bd
chore: update to latest pact libs
Feb 20, 2021
586df30
Merge branch 'master' into feat/V3
Feb 20, 2021
54b2b4e
chore: get todo test working with latest Rust libs
Feb 21, 2021
eadfa4d
chore: update todo readme
Feb 21, 2021
b12bb5d
feat: todo XML example working
Feb 21, 2021
d533bb7
feat: consumer test with binary file
Feb 21, 2021
8d10d5a
feat: got basic provider verifier working
Feb 21, 2021
4fdabdd
feat: added rust linux/osx support
elliottmurray Jul 17, 2021
2d7f943
feat: fix to pytest request signature@
elliottmurray Jul 17, 2021
488d55f
feat: first ffi interface
elliottmurray Jul 19, 2021
cf77d09
feat: added so file
elliottmurray Jul 19, 2021
f914c50
fix: so now a relative path so picked up by tests (temp fix) Also som…
elliottmurray Jul 19, 2021
cd85969
chore: move dyn libs to libs folder@
elliottmurray Jul 24, 2021
2b67e39
feat: some work on preparing verify call
elliottmurray Jul 24, 2021
60ac756
feat: refactoring to prepare verify
elliottmurray Jul 24, 2021
34f67a7
feat: added rust linux/osx support
elliottmurray Jul 17, 2021
afd0931
feat: fix to pytest request signature@
elliottmurray Jul 17, 2021
6c95248
feat: first ffi interface
elliottmurray Jul 19, 2021
de93a1f
feat: added so file
elliottmurray Jul 19, 2021
be6c971
fix: so now a relative path so picked up by tests (temp fix) Also som…
elliottmurray Jul 19, 2021
4b239e4
chore: move dyn libs to libs folder@
elliottmurray Jul 24, 2021
e7d686a
feat: some work on preparing verify call
elliottmurray Jul 24, 2021
050ee0e
feat: refactoring to prepare verify
elliottmurray Jul 24, 2021
7d18a2f
docs(readme): trivial 'hello world' changes :)
mikegeeves Aug 18, 2021
214c47d
docs(readme): update python versions mentioned to those supported (go…
mikegeeves Aug 18, 2021
a84f856
build(flake8): exclude venv and tox dirs from flake8 linting
mikegeeves Aug 18, 2021
2d30706
build(ffi): use libs from pact dir instead of libs. Bump to 0.0.1. Mi…
mikegeeves Aug 18, 2021
c6ded0a
feat(ffi verifier): very basic call of verify, with no args
mikegeeves Aug 20, 2021
e9c1bb0
feat(ffi verifier): verifier test, looking at log output
mikegeeves Aug 21, 2021
358748f
feat(ffi verifier): verifier test, looking at log output
mikegeeves Aug 21, 2021
070f905
feat(ffi verifier): set log level for output
mikegeeves Aug 21, 2021
cf0bfee
feat(ffi verifier): help and version tests
mikegeeves Aug 21, 2021
3471c12
feat(ffi verifier cli): use FFI to determine the args for the CLI wra…
mikegeeves Aug 22, 2021
11228ed
feat(ffi verifier): add possible values e.g. to loglevel
mikegeeves Aug 23, 2021
69233a6
feat(ffi verify): add in default value
mikegeeves Aug 23, 2021
3486281
feat(ffi verifier cli): handle both flags and options, along with mul…
mikegeeves Aug 26, 2021
283dcef
feat(ffi verifier cli): construct args string from inputs. Call pactf…
mikegeeves Aug 27, 2021
411ad66
feat(ffi verifier): add a first (currently broken) test
mikegeeves Aug 27, 2021
bd809ff
feat(ffi verifier cli): call verifier from CLI
mikegeeves Aug 27, 2021
d773d85
Add support for ENVs, tidy, docs
mikegeeves Sep 8, 2021
a2ce9f4
feat(ffi verifier cli): correct return type of cli_args
mikegeeves Sep 8, 2021
65d99d3
feat(ffi verifier): switch to using the log buffer instead of interme…
mikegeeves Sep 8, 2021
ccb2641
feat(ffi verifier cli): adding in real test using httpserver
mikegeeves Sep 8, 2021
273e1f3
feat(ffi verifier cli): both a successful and an unsuccessful verific…
mikegeeves Sep 8, 2021
55f4e55
feat(ffi verifier): add same success and fail tests to the verifier d…
mikegeeves Sep 8, 2021
8701015
feat(ffi verifier): minor tidy
mikegeeves Sep 8, 2021
087a655
feat(ffi verifier): generate Verifier args class by various methods
mikegeeves Sep 8, 2021
f3601fd
Merge branch 'master' into feat/ffi-provider-mike
mikegeeves Sep 13, 2021
741cf99
feat(ffi verifier): tidy, comments
mikegeeves Sep 13, 2021
5703160
Merge branch 'feat/ffi-provider-mike' of https://github.com/mikegeeve…
mikegeeves Sep 13, 2021
b18128a
refactor(setup.py): minor tidy
mikegeeves Sep 13, 2021
5ebf947
feat(ffi verifier): tidying up
mikegeeves Sep 20, 2021
53819eb
feat(ffi verifier cli): tidy usage etc, add info about ENVs being used
mikegeeves Sep 21, 2021
3882837
test(pact): fixing tests, failing after allowRedirect was added elsew…
mikegeeves Sep 21, 2021
3c82f1f
refactor(setup.py): black
mikegeeves Sep 21, 2021
778ef4c
feat(ffi): use the same approach to download the FFI libs as the Ruby…
mikegeeves Sep 21, 2021
f91e9b1
Merge branch 'feat/ffi-provider' into feat/ffi-provider-mike
mikegeeves Sep 21, 2021
d21f906
Merge branch 'feat/ffi-provider-mike' of github.com:mikegeeves/pact-p…
YOU54F Nov 20, 2022
8704666
chore: dl ffi & ruby
YOU54F Nov 20, 2022
331e9f0
chore: extract ffi & ruby
YOU54F Nov 20, 2022
fe9e49a
chore: rm ffi & ruby archives
YOU54F Nov 20, 2022
db28c44
chore: arm64 m1 support
YOU54F Nov 20, 2022
c4e8bf2
chore: update tests/ffi/test_ffi_verifier.py
YOU54F Nov 20, 2022
7b30792
chore: add missing deps
YOU54F Nov 20, 2022
a6edc5f
feat(verifier): support all verification modes - local and broker
YOU54F Jun 15, 2023
399a325
chore(standalone): use v2.0.2 of pact-ruby-standalone
YOU54F Jun 15, 2023
b549cc9
chore(docker): support testing examples with docker on non linux systems
YOU54F Jun 15, 2023
e38f869
feat(verifier): verify_with_broker via pact url
YOU54F Jun 15, 2023
3f7fa54
chore: lint
YOU54F Jun 15, 2023
bd7c316
chore: lint
YOU54F Jun 15, 2023
e102203
chore(docker): override url if not linux
YOU54F Jun 15, 2023
dbf30bb
chore(docker): linux gha
YOU54F Jun 16, 2023
bad4cb6
chore(docker): support macos
YOU54F Jun 16, 2023
e93a34d
Merge branch 'feat/ffi-provider' into feat/ffi
YOU54F Jun 16, 2023
9e6f1ec
chore(ffi): use latest ffi
YOU54F Jun 16, 2023
7e3de6f
chore(ffi): dynamically read in header file to load ffi namespace
YOU54F Jun 16, 2023
ca809d1
chore(ffi): allow setting of PACT_FFI_PATH and flake8/doc fixes
YOU54F Jun 16, 2023
efa6e0c
chore(python) replace f string usage for format for 3.6/3.7
YOU54F Jun 16, 2023
6915fe3
ci(cirrus): use non slim image, python -m flake8
YOU54F Jun 16, 2023
c99dd56
ci(test): test with 2.0.1 standalone
YOU54F Jun 16, 2023
532a756
chore: show errors when downloading
YOU54F Jun 16, 2023
95b55f4
chore: dl with urblib3 and backoff
YOU54F Jun 16, 2023
950345b
chore: --version args on pact-verifier and pact-verifier-ffi
YOU54F Jun 16, 2023
cc1a3e0
chore(ffi): start usign shared verifier
YOU54F Jun 17, 2023
440aacd
chore(ffi): initita ffi verifier progress
YOU54F Jun 17, 2023
22b12a8
chore(ffi_verifier): support local and url based pacts for verification
YOU54F Jun 17, 2023
3bbf431
feat: ffi verifier broker + beginning of plugin verification
YOU54F Jul 7, 2023
9ea9f24
chore: flake8 errors
YOU54F Jul 7, 2023
6644cb2
chore: allow setting of PACT_FFI_PATH for tox
YOU54F Jul 7, 2023
858addd
fix: paths to ffi lib names for non macos arm platforms
YOU54F Jul 7, 2023
7bf1a73
test: use test.pactflow with uploaded pacts
YOU54F Jul 7, 2023
5b5dda9
test: skip cli ffi tests as issues with conflicting logs - pactffi_fe…
YOU54F Jul 7, 2023
a3810c5
chore(ci): macos arm64 set VERSION env var
YOU54F Jul 7, 2023
0811665
chore: move PACT_FFI_PATH to constants
YOU54F Jul 26, 2023
e492da6
chore: update release script to support beta release tag formats
YOU54F Jul 26, 2023
f7b75ea
feat(examples): showcase FFIVerify for HTTP
YOU54F Jul 26, 2023
f1cea52
feat: MessageProvider Verifier with FFIVerify plus examples
YOU54F Jul 26, 2023
5dea5dc
Merge remote-tracking branch 'origin/master' into feat/ffi
YOU54F Jul 26, 2023
e5d46e9
feat: MessageProvider now returns VerifyResult(return_code, logs)
YOU54F Jul 26, 2023
c867226
chore: avoid full path when checking for error message in test
YOU54F Jul 26, 2023
6916758
chore(test): add PACT_DO_NOT_TRACK
YOU54F Jul 26, 2023
6e69633
chore(test): add PACT_DO_NOT_TRACK
YOU54F Jul 26, 2023
8c07bc3
chore(test): windows has diff error for file not found
YOU54F Jul 26, 2023
28776c2
chore!: drop ci testing of python 3.6 - fails in cirrus
YOU54F Jul 26, 2023
703bac6
test: showcase grpc v4 pact verification
YOU54F Jul 26, 2023
11ed3c2
ci(gha): test windows with plugins only
YOU54F Jul 26, 2023
8ce9f57
ci: renable all os
YOU54F Jul 26, 2023
823fb49
chore(deps): update grpcio/grpcio-tools to latest
YOU54F Jul 26, 2023
884fd8b
test: add v2-http ffi verifier test with local pact
YOU54F Jul 27, 2023
0317427
chore: reorder shutdown before getting logs
YOU54F Jul 27, 2023
aa6fad5
chore: pactffi_string_delete after decoding pactffi_verifier_logs
YOU54F Jul 27, 2023
38a8caf
test: reinstate ffi cli tests
YOU54F Jul 27, 2023
7145a02
test: local http v3 pact verification with matchers
YOU54F Jul 27, 2023
7b5b3a0
feat: show initial pact consumer ffi examples
YOU54F Jul 27, 2023
45ba04a
chore: write pact-python version to pact
YOU54F Jul 28, 2023
3ffa208
feat: initial pact ffi_consumer
YOU54F Jul 28, 2023
1e16761
feat: MockServer class
YOU54F Jul 28, 2023
145f0b3
Merge remote-tracking branch 'you54f/feat/v3' into feat/ffi_consumer_…
YOU54F Jul 31, 2023
67cf669
feat: V3Verifier
YOU54F Jul 31, 2023
9735923
docs: upgrade guide for VerifierV3
YOU54F Jul 31, 2023
9397511
chore: doc style
YOU54F Aug 1, 2023
c902f21
chore: fixup array of pointers
YOU54F Aug 1, 2023
ed1533f
feat: PactV3 interfact with V3Matcher
YOU54F Aug 1, 2023
113cec7
chore: docstyle
YOU54F Aug 1, 2023
f792b88
chore: use content-type from header
YOU54F Aug 1, 2023
956a813
chore: rename upgrades docs, windows doesnt like it
YOU54F Aug 1, 2023
79b6c6f
chore: NamedTuple not TypedDict for 3.7
YOU54F Aug 1, 2023
128bb81
chore: remove f string for 3.7 flake8
YOU54F Aug 1, 2023
0838fc2
chore: update e2e examples to use VerifierV3
YOU54F Aug 1, 2023
4b57fdc
chore: verifier.verify_pacts +
YOU54F Aug 1, 2023
ec68ea7
chore: add Format to V3Matcher Class
YOU54F Aug 1, 2023
2f39884
feat: test_user_consumer with PactV3 interface
YOU54F Aug 1, 2023
1dbc60d
feat: todo xml example (note issues)
YOU54F Aug 1, 2023
f18cefb
chore: linting
YOU54F Aug 1, 2023
706b26d
chore: linting
YOU54F Aug 1, 2023
b5db6b3
chore(deps): libpact_ffi 0.4.7
YOU54F Aug 1, 2023
3a6f853
chore: yak shave xml content types
YOU54F Aug 1, 2023
37e77ce
chore: flake8
YOU54F Aug 1, 2023
d579913
chore(test): todo verifier expected to fail atm
YOU54F Aug 1, 2023
59e2ef6
chore: allow conditional running with PactFlow for a self-hosted broker
YOU54F Aug 2, 2023
577e84b
ci(test): support running examples on macos/linux
YOU54F Aug 2, 2023
606efec
chore: use .bat ext for ruby standalone on win
YOU54F Aug 2, 2023
cd13fdd
chore: use .bat ext for ruby standalone on win
YOU54F Aug 2, 2023
ce2a3b7
ci: just test on windows for now
YOU54F Aug 2, 2023
5f9fd62
ci(win): use os.join for multiplat paths in sharedfixture
YOU54F Aug 2, 2023
b7cec07
ci(win): skip flask
YOU54F Aug 2, 2023
3370a3c
ci(win): skip messaging, 2 provider tests fail
YOU54F Aug 2, 2023
48d1dee
ci(win): only use fork on macos https://github.com/pytest-dev/pytest-…
YOU54F Aug 2, 2023
29b95db
ci: renable everything, skip todo provider on windows
YOU54F Aug 2, 2023
c2a9999
ci(test): try 127.0.0.1 for flask provider
YOU54F Aug 3, 2023
d1a0735
ci: test messaging provider
YOU54F Aug 3, 2023
9a4c5e6
ci: add testcontainers in examples/message
YOU54F Aug 3, 2023
460fab3
ci: 127.0.0.1 in message provider for win
YOU54F Aug 3, 2023
efd2a6d
ci: set 127.0.0.1 as default for MessageProvider
YOU54F Aug 3, 2023
68d3675
chore: update test for MessageProvider to expect 127.0.0.1
YOU54F Aug 3, 2023
4f4feb9
chore: reinstate testing all examples bar todo
YOU54F Aug 3, 2023
019957a
ci: reinstate full version testing
YOU54F Aug 3, 2023
8c743cd
chore: workarounds for python 3.6
YOU54F Aug 3, 2023
47632c7
chore: move grpc tests into examples folder
YOU54F Aug 3, 2023
6615780
chore: ignore grpc autogenned files
YOU54F Aug 3, 2023
23176f2
ci: test cirrus cli with python 3.6
YOU54F Aug 3, 2023
df42bbb
ci(3.6) - enable for GHA
YOU54F Aug 3, 2023
4e5bc9b
ci: renable all versions
YOU54F Aug 3, 2023
b6570f7
feat: binary payload test example in todo consumer
YOU54F Aug 3, 2023
a031bb7
chore: pydocstyle
YOU54F Aug 3, 2023
43e3e9c
chore: add binary payload test
YOU54F Aug 4, 2023
e087206
chore: test todo pickle errors
YOU54F Aug 4, 2023
dea4c12
chore: test todo, binary content yak shave
YOU54F Aug 7, 2023
1b319b1
ci: test with image/jpeg on consumer + test
YOU54F Aug 7, 2023
00b1843
fix: x-plat mime type detection issues
YOU54F Aug 7, 2023
9c202f5
chore: set content-type conditionally
YOU54F Aug 7, 2023
18218e3
Merge pull request #1 from YOU54F/test/todo_binary
YOU54F Aug 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 32 additions & 26 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,56 @@ BUILD_TEST_TASK_TEMPLATE: &BUILD_TEST_TASK_TEMPLATE
arch_check_script:
- uname -am
test_script:
- script/install_plugins.sh
- python --version
- python -m pip install --upgrade pip
- python -m pip install -r requirements_dev.txt
- python -m flake8
- python -m flake8 --exclude '*pb2*',.git,__pycache__,build,dist,.tox --show-source
- python -m pydocstyle pact
- python -m tox -e test
# - make examples
- make todo

linux_arm64_task:
env:
RUN_BROKER: 0
USE_HOSTED_PACT_BROKER: 1
USE_STANDALONE: 1

PYTHON_VERSION_MATRIX: &PYTHON_VERSION_MATRIX
- VERSION: 3.11
# - VERSION: 3.6
# - VERSION: 3.7
# - VERSION: 3.8
# - VERSION: 3.9
# - VERSION: 3.10

linux_arm64_task:
only_if: $CIRRUS_CHANGE_TITLE !=~ 'ci\(gha\).*'
env:
# PACT_FFI_PATH: .tox/test/lib/python$VERSION/site-packages/pact/bin
LANG: C.UTF-8 # required for python 3.6 docker image
matrix:
# - IMAGE: python:3.6-slim # This works locally, with cirrus run, but fails in CI
- IMAGE: python:3.7-slim
- IMAGE: python:3.8-slim
- IMAGE: python:3.9-slim
- IMAGE: python:3.10-slim
<<: *PYTHON_VERSION_MATRIX
arm_container:
image: $IMAGE
image: python:$VERSION-slim
install_script:
- apt update --yes && apt install --yes gcc make
- apt update --yes && apt install --yes gcc make curl
<< : *BUILD_TEST_TASK_TEMPLATE


macosx_arm64_task:
macos_arm64_task:
only_if: $CIRRUS_CHANGE_TITLE !=~ 'ci\(gha\).*'
macos_instance:
image: ghcr.io/cirruslabs/macos-ventura-base:latest
env:
PATH: ${HOME}/.pyenv/shims:${PATH}
# PACT_FFI_PATH: .tox/test/lib/python$VERSION/site-packages/pact/bin
matrix:
- PYTHON: 3.6
- PYTHON: 3.7
- PYTHON: 3.8
- PYTHON: 3.9
- PYTHON: 3.10
<<: *PYTHON_VERSION_MATRIX
install_script:
# Per the pyenv homebrew recommendations.
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment
# - xcode-select --install # Unnecessary on Cirrus
- brew update
# - brew install openssl readline sqlite3 xz zlib
- brew install pyenv
- pyenv install ${PYTHON}
- pyenv global ${PYTHON}
- brew install pyenv protobuf shared-mime-info # protobuf only needed if using grpc plugins
- pyenv install ${VERSION}
- pyenv global ${VERSION}
- pyenv rehash
## To install rosetta
# - softwareupdate --install-rosetta --agree-to-license
- chmod +x script/install_plugins.sh
- find examples -name '*.sh' -exec chmod +x {} \;
<< : *BUILD_TEST_TASK_TEMPLATE
45 changes: 35 additions & 10 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@ jobs:

matrix:
python-version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
# - '3.7'
# - '3.8'
# - '3.9'
# - '3.10'
- '3.11'
os: [ ubuntu-latest, windows-latest, macos-latest ]
os: [
ubuntu-latest,
windows-latest,
macos-latest
]

# These versions are no longer supported by Python team, and may
# eventually be dropped from GitHub Actions.
include:
- python-version: '3.6'
os: ubuntu-20.04
# include:
# - python-version: '3.6'
# os: ubuntu-20.04
# - python-version: '3.6'
# os: windows-latest
# - python-version: '3.6'
# os: macos-latest

steps:
- name: Check out code
Expand All @@ -43,12 +51,29 @@ jobs:

- name: Lint with flake8, pydocstyle
run: |
flake8
flake8 --show-source --exclude '*pb2*',.git,__pycache__,build,dist,.tox
pydocstyle pact

- name: Install Pact plugins for tests
run: script/install_plugins.sh
shell: bash

- name: Test with pytest
run: tox -e test
# env:
# PACT_FFI_PATH: .tox/test/lib/python${{ matrix.python-version }}/site-packages/pact/bin

- name: Test examples
if: runner.os == 'Linux'
run: make examples
run: make todo

- name: Test examples
# no docker so we use a hosted pact broker and pact-ruby-standalone for publishing
if: runner.os != 'Linux'
run: make todo
env:
RUN_BROKER: 0
USE_HOSTED_PACT_BROKER: 1
USE_STANDALONE: 1
PACT_LOG_LEVEL: DEBUG
PACT_LOG_OUTPUT: STDOUT
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pact-python specific ignores
e2e/pacts
userserviceclient-userservice.json
detectcontentlambda-contentprovider.json
# userserviceclient-userservice.json # unexcluded for cirrus ci locally
# detectcontentlambda-contentprovider.json # unexcluded for cirrus ci locally
pact/bin

# Byte-compiled / optimized / DLL files
Expand All @@ -10,7 +10,7 @@ __pycache__/
*$py.class

# C extensions
*.so
# *.so

# Distribution / packaging
.Python
Expand Down Expand Up @@ -91,6 +91,7 @@ celerybeat-schedule
venv/
.venv/
ENV/
.venv/

# Spyder project settings
.spyderproject
Expand All @@ -105,3 +106,7 @@ ENV/

.noseids

# MacOS stuff
.DS_Store
# Generated pact directories
# /pacts/
7 changes: 7 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ pact/message_consumer.py
pact/message_pact.py
pact/message_provider.py
pact/pact.py
pact/pact_exception.py
pact/provider.py
pact/verifier.py
pact/verify_wrapper.py
pact/bin/libpact_ffi-linux-aarch64.so.gz
pact/bin/libpact_ffi-linux-x86_64.so.gz
pact/bin/libpact_ffi-osx-aarch64-apple-darwin.dylib.gz
pact/bin/libpact_ffi-osx-x86_64.dylib.gz
pact/bin/pact-2.0.3-linux-arm64.tar.gz
pact/bin/pact-2.0.3-linux-x86_64.tar.gz
pact/bin/pact-2.0.3-osx-arm64.tar.gz
pact/bin/pact-2.0.3-osx-x86_64.tar.gz
pact/bin/pact-2.0.3-windows-x86.zip
pact/bin/pact-2.0.3-windows-x86_64.zip
pact/bin/pact.h
pact/bin/pact_ffi-windows-x86_64.dll.gz
pact/cli/__init__.py
pact/cli/verify.py
33 changes: 31 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ help:
@echo " fastapi to run the example FastApi provider tests"
@echo " flask to run the example Flask provider tests"
@echo " messaging to run the example messaging e2e tests"
@echo " grpc to run the example grpc e2e tests"
@echo " todo to run the example todo tests"
@echo " package to create a distribution package in /dist/"
@echo " release to perform a release build, including deps, test, and package targets"
@echo " test to run all tests"
Expand Down Expand Up @@ -78,6 +80,24 @@ define MESSAGING
endef
export MESSAGING

define GRPC
echo "grpc make"
cd examples/grpc
pip install -q -r requirements.txt
pip install -e ../../
./run_pytest.sh
endef
export GRPC

define TODO
echo "todo make"
cd examples/todo
pip install -r requirements.txt
pip install -e ../../
./run_pytest.sh
endef
export TODO


.PHONY: consumer
consumer:
Expand All @@ -98,9 +118,18 @@ fastapi:
messaging:
bash -c "$$MESSAGING"

.PHONY: grpc
grpc:
bash -c "$$GRPC"

.PHONY: todo
todo:
bash -c "$$TODO"


.PHONY: examples
examples: consumer flask fastapi messaging
examples: consumer flask fastapi messaging grpc todo
# examples: consumer flask fastapi messaging todo


.PHONY: package
Expand All @@ -110,7 +139,7 @@ package:

.PHONY: test
test: deps
flake8
flake8 --exclude examples/area_calculator/area_calculator_pb2.py,examples/area_calculator/area_calculator_pb2_grpc.py
pydocstyle pact
coverage erase
tox
Expand Down
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ Note: As of Version 1.0 deprecates support for python 2.7 to allow us to incorpo
# How to use pact-python

## Installation

```
pip install pact-python
```

## Getting started

<!-- Absolute link for rendering page in docs.pact.io -->
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.

## Writing a Pact

Creating a complete contract is a two step process:
Creating a complete contract is a two-step process:

1. Create a test on the consumer side that declares the expectations it has of the provider
2. Create a provider state that allows the contract to pass when replayed against the provider
Expand Down Expand Up @@ -82,7 +84,6 @@ class GetUserInfoContract(unittest.TestCase):
result = user('UserA')

self.assertEqual(result, expected)

```

This does a few important things:
Expand Down Expand Up @@ -164,11 +165,13 @@ The mock service offers you several important features when building your contra
- Finally, it will record your contracts as a JSON file that you can store in your repository or publish to a Pact broker.

## Expecting Variable Content

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:

### Term(matcher, generate)

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:
Expand All @@ -194,6 +197,7 @@ provider, the regex will be used to search the response from the real provider s
and the test will be considered successful if the regex finds a match in the response.

### Like(matcher)

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

```python
Expand All @@ -202,6 +206,7 @@ Like(123) # Matches if the value is an integer
Like('hello world') # Matches if the value is a string
Like(3.14) # Matches if the value is a float
```

The argument supplied to `Like` will be what the mock service responds with.

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.
Expand Down Expand Up @@ -453,7 +458,8 @@ The provider application version. Required for publishing verification results.
Publish verification results to the broker.

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

You can use the Verifier class. This has all the same parameters as the cli tool but allows you to write native python code and the test framework of your choice.

```python
verifier = Verifier(provider='UserService',
Expand Down Expand Up @@ -507,6 +513,7 @@ You can see more details in the examples
- [FastAPI Provider Verifier Test](https://github.com/pact-foundation/pact-python/tree/master/examples/fastapi_provider/tests/provider/test_provider.py)

### Provider States

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
Expand All @@ -525,18 +532,20 @@ on the provider application or a separate one. Some strategies for managing stat
For more information about provider states, refer to the [Pact documentation] on [Provider States].

# Development

<!-- Absolute link for rendering page in docs.pact.io -->
Please read [CONTRIBUTING.md](https://github.com/pact-foundation/pact-python/blob/master/CONTRIBUTING.md)

To setup a development environment:

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]
2. Its recommended to create a Python [virtualenv] for the project
1. If you want to run tests for all Python versions, install 3.6, 3.7, 3.8, and 3.9 from source or using a tool like [pyenv]
2. It's recommended to create a Python [virtualenv] for the project.
3. We are now using FFI bindings. For mac you might want to read these [setup FFI](https://cffi.readthedocs.io/en/latest/installation.html)

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

If you are just interested in packaging pact-python so you can install it using pip:
If you are just interested in packaging pact-python you can install it using pip:

`make package`

Expand Down
Loading