77is responding with the expected responses. Once these interactions are
88validated, the contracts can be published to a Pact Broker. The contracts can
99then be used to validate the provider's interactions.
10+
11+ A good resource for understanding the consumer tests is the [Pact Consumer
12+ Test](https://docs.pact.io/5-minute-getting-started-guide#scope-of-a-consumer-pact-test)
13+ section of the Pact documentation.
1014"""
1115
1216from __future__ import annotations
1317
1418import logging
1519from http import HTTPStatus
16- from typing import TYPE_CHECKING , Any , Generator
20+ from typing import TYPE_CHECKING , Any , Dict , Generator
1721
1822import pytest
1923import requests
@@ -40,6 +44,11 @@ def user_consumer() -> UserConsumer:
4044 the consumer to use Pact's mock provider. This allows us to define what
4145 requests the consumer will make to the provider, and what responses the
4246 provider will return.
47+
48+ The ability for the client to specify the expected response from the
49+ provider is critical to Pact's consumer-driven approach as it allows the
50+ consumer to declare the minimal response it requires from the provider (even
51+ if the provider is returning more data than the consumer needs).
4352 """
4453 return UserConsumer (str (MOCK_URL ))
4554
@@ -53,7 +62,7 @@ def pact(broker: URL, pact_dir: Path) -> Generator[Pact, Any, None]:
5362 the provider. This mock provider will expect to receive defined requests
5463 and will respond with defined responses.
5564
56- The fixture here simply defines the Consumer and Provide , and sets up the
65+ The fixture here simply defines the Consumer and Provider , and sets up the
5766 mock provider. With each test, we define the expected request and response
5867 from the provider as follows:
5968
@@ -90,7 +99,11 @@ def test_get_existing_user(pact: Pact, user_consumer: UserConsumer) -> None:
9099 This test defines the expected request and response from the provider. The
91100 provider will be expected to return a response with a status code of 200,
92101 """
93- expected : dict [str , Any ] = {
102+ # When setting up the expected response, the consumer should only define
103+ # what it needs from the provider (as opposed to the full schema). Should
104+ # the provider later decide to add or remove fields, Pact's consumer-driven
105+ # approach will ensure that interaction is still valid.
106+ expected : Dict [str , Any ] = {
94107 "id" : Format ().integer ,
95108 "name" : "Verna Hampton" ,
96109 "created_on" : Format ().iso_8601_datetime (),
0 commit comments