pact-python icon indicating copy to clipboard operation
pact-python copied to clipboard

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

Open bethesque opened this issue 3 years ago • 2 comments

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!

bethesque avatar Jan 27 '22 22:01 bethesque

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

  • https://github.com/pact-foundation/pact-python/blob/4e3ca3858b8343a5057de506f19a4f3284bb8bd4/tests/test_verifier.py#L75
  • https://github.com/pact-foundation/pact-python/blob/4e3ca3858b8343a5057de506f19a4f3284bb8bd4/tests/cli/test_verify.py#L310

where the verifier e2e tests live here

  • examples/message/tests/provider/test_message_provider.py
  • examples/flask_provider/tests/provider/test_provider.py
  • examples/fastapi_provider/tests/provider/test_provider.py

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 avatar May 03 '23 18:05 YOU54F

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

YOU54F avatar Aug 03 '23 13:08 YOU54F