pact-foundation / pact-python

Python version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
http://pact.io
MIT License
577 stars 137 forks source link

Please document how to run a verification using the provider name and consumer version selectors #285

Open bethesque opened 2 years ago

bethesque commented 2 years ago

I'm trying to find an example for someone because I'm not familiar with the python CLI/API and I can't find one anywhere!

YOU54F commented 1 year ago

It would be good to hook this project up with a python verifier over using the pact-cli

https://github.com/pactflow/example-provider-python

which can be hooked up with this consumer project

https://github.com/pactflow/example-consumer-python

options documented in #346

source code tests here

where the verifier e2e tests live here

We would happily accept contributions to improve the examples, either in this repo, the pactflow examples, or in a pact python workshop (to anyone reading this!)

YOU54F commented 1 year ago

Main docs https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors

Python Example

verifier = Verifier(
    provider="Your provider",
    broker_url="...",
    consumer_version_selectors=[
        {"mainBranch": True}, # (recommended) - Returns the pacts for consumers configured mainBranch property
        {"deployedOrReleased": True}, # (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
        {"deployed": "test"}, # Normally, this would not be needed, Any versions currently deployed to the specified environment.
        {"deployed": "production"}, # Normally, this would not be needed, Any versions currently deployed to the specified environment.
        {"environment": "test"}, #  Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
        {"environment": "production"}, #  Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
    ],
    # ...
)

Taken from my WIP code sample updates on the website - which shows snippets in other languages, and other selectors

https://deploy-preview-189--docs-pact-io.netlify.app/pact_broker/samples_provider_verification_provider_changed#consumer-version-selectors---code-examples-with-branches

https://github.com/pact-foundation/docs.pact.io/pull/189