Consumer¶
Simple Consumer Implementation.
This modules defines a simple consumer which will be tested with Pact in the consumer test. As Pact is a consumer-driven framework, the consumer defines the interactions which the provider must then satisfy.
The consumer is the application which makes requests to another service (the
provider) and receives a response to process. In this example, we have a simple
User
class and the consumer fetches a user's
information from a HTTP endpoint.
Note that the code in this module is agnostic of Pact. The pact-python
dependency only appears in the tests. This is because the consumer is not
concerned with Pact, only the tests are.
Classes¶
User(id: int, name: str, created_on: datetime)
dataclass
¶
UserConsumer(base_uri: str)
¶
Example consumer.
This class defines a simple consumer which will interact with a provider
over HTTP to fetch a user's information, and then return an instance of the
User
class.
PARAMETER | DESCRIPTION |
---|---|
base_uri |
The uri of the provider
TYPE:
|
Source code in examples/src/consumer.py
Attributes¶
base_uri = base_uri
instance-attribute
¶
Functions¶
get_user(user_id: int) -> User
¶
Fetch a user by ID from the server.
PARAMETER | DESCRIPTION |
---|---|
user_id |
The ID of the user to fetch.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
User
|
The user if found. |
User
|
In all other cases, an error dictionary is returned with the key |
User
|
|
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the server returns a non-200 response. |