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

Feat/ffi consumer #366

Closed
wants to merge 107 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
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
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
48 changes: 25 additions & 23 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,52 @@ 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 --show-source --exclude examples/area_calculator/area_calculator_pb2.py,examples/area_calculator/area_calculator_pb2_grpc.py,.git,__pycache__,build,dist,.tox
- python -m pydocstyle pact
- python -m tox -e test
# - make examples

linux_arm64_task:
linux_arm64_task:
only_if: $CIRRUS_CHANGE_TITLE !=~ 'ci\(gha\).*'
env:
# PACT_FFI_PATH: .tox/test/lib/python$VERSION/site-packages/pact/bin
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
# - VERSION: 3.6
- VERSION: 3.7
- VERSION: 3.8
- VERSION: 3.9
- VERSION: 3.10
- VERSION: 3.11
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
# - VERSION: 3.6
- VERSION: 3.7
- VERSION: 3.8
- VERSION: 3.9
- VERSION: 3.10
- VERSION: 3.11
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}
- pyenv install ${VERSION}
- pyenv global ${VERSION}
- pyenv rehash
## To install rosetta
# - softwareupdate --install-rosetta --agree-to-license
- chmod +x script/install_plugins.sh
<< : *BUILD_TEST_TASK_TEMPLATE
18 changes: 12 additions & 6 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
- '3.11'
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
# # 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

steps:
- name: Check out code
Expand All @@ -43,11 +43,17 @@ jobs:

- name: Lint with flake8, pydocstyle
run: |
flake8
flake8 --show-source --exclude examples/area_calculator/area_calculator_pb2.py,examples/area_calculator/area_calculator_pb2_grpc.py,.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'
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ __pycache__/
*$py.class

# C extensions
*.so
# *.so

# Distribution / packaging
.Python
Expand Down Expand Up @@ -105,3 +105,5 @@ ENV/

.noseids

# MacOS stuff
.DS_Store
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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
30 changes: 30 additions & 0 deletions examples/area_calculator/area_calculator_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""The Python implementation of the GRPC Area Calculator client."""

from __future__ import print_function

import logging

import grpc
import area_calculator_pb2
import area_calculator_pb2_grpc


def run():
get_rectangle_area('localhost:37757')

def get_rectangle_area(address):
print("Getting rectangle area.")
with grpc.insecure_channel(address) as channel:
stub = area_calculator_pb2_grpc.CalculatorStub(channel)
rect = {
"length": 3,
"width": 4
}
response = stub.calculateOne(area_calculator_pb2.ShapeMessage(rectangle=rect))
print(f"AreaCalculator client received: {response.value[0]}")
return response.value[0]


if __name__ == '__main__':
logging.basicConfig()
run()
42 changes: 42 additions & 0 deletions examples/area_calculator/area_calculator_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading