Search code examples
pythonproviderpact

Pact-python how to test a get request having UUID in URL


I am using pact-python (0.10.0). I want to make a request to a provider with an entity id:

    /entity/6000d04d-d5d6-4a5f-81d3-7d8a72b46174

but this (6000d04d-d5d6-4a5f-81d3-7d8a72b46174) should exist in the database.

what'd be the better solution:

  1. Creating a provider state with the data present in it (but how will the provider verifier work? shouldn't the contract be having the id that's present in real provider?)

  2. Query for all the id's in the database and pick one for making the request (for this I need to somehow update and publish pact with the fetched id)

Or is there any better solution available that i might have missed?


Solution

  • You should create a provider state, given entity 6000d04d-d5d6-4a5f-81d3-7d8a72b46174 exists that will set up the entity with the correct UID before the interaction is replayed.

    To use contract testing to its fullest potential, you need to be able to control the data in the provider for each interaction. If you can't, then contract tests are not a good fit for your problem space. Have a read of https://docs.pact.io/documentation/provider_states.html and https://github.com/pact-foundation/pact-ruby/wiki/Why-Pact-may-not-be-the-best-tool-for-testing-public-APIs