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.
Provide a Pythonic interface for creating generators.
Motivation
The Pact specification supports generators for most aspects of an interaction. These generators allow for values to be dynamic which can be particularly useful for values such as unique IDs, or datetimes.
At present, functions such as with_body or with_matching_rules only take strings or byte arrays which are passed as-is to the underlying FFI. As a result, while generators are technically supported, the end user is responsible for writing out the generators in a JSON string. This is clearly undesirable.
Proposed Implementation
General Considerations
The proposed changes would apply to all functions that can support generators, whether it be the body, headers, metadata, etc. The specific might change slightly based on context, but the general idea should remain the same.
There should also be consistency between using with_body(...) with a generators, and with_generators(...). That is, a user should be able to straightforward refactor from one to the other. Similarly, adapting a generator from with_body to with_header should be equally straightforward.
Generator Constructor
The specific implementation might depend a bit on what is done for the matching rules in #746, but I would want to follow a similar pattern. That is:
Expose a number of simple functions which can be used to create a matching rule on the fly:
type, min, max, timestamp, time, date, etc.
Have these functions return a Generator object.
It should be transparently supported within the with_body function and friends.
It should overload the & operator to allow for logical and. This would allow for the creation of more generators such as type(42) & min(0) & max(100) for "a random integer between 0 and 100 inclusive".
Types
Unlike the matching rules, the types supported by generators is a bit more restricted and needs to be more properly informed by the underlying capabilities of the Rust library.
Summary
Provide a Pythonic interface for creating generators.
Motivation
The Pact specification supports generators for most aspects of an interaction. These generators allow for values to be dynamic which can be particularly useful for values such as unique IDs, or datetimes.
At present, functions such as
with_body
orwith_matching_rules
only take strings or byte arrays which are passed as-is to the underlying FFI. As a result, while generators are technically supported, the end user is responsible for writing out the generators in a JSON string. This is clearly undesirable.Proposed Implementation
General Considerations
The proposed changes would apply to all functions that can support generators, whether it be the body, headers, metadata, etc. The specific might change slightly based on context, but the general idea should remain the same.
There should also be consistency between using
with_body(...)
with a generators, andwith_generators(...)
. That is, a user should be able to straightforward refactor from one to the other. Similarly, adapting a generator fromwith_body
towith_header
should be equally straightforward.Generator Constructor
The specific implementation might depend a bit on what is done for the matching rules in #746, but I would want to follow a similar pattern. That is:
type
,min
,max
,timestamp
,time
,date
, etc.Generator
object.with_body
function and friends.&
operator to allow for logical and. This would allow for the creation of more generators such astype(42) & min(0) & max(100)
for "a random integer between 0 and 100 inclusive".Types
Unlike the matching rules, the types supported by generators is a bit more restricted and needs to be more properly informed by the underlying capabilities of the Rust library.
References