Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow functional arguments for provider callbacks and message producers #890

Merged
merged 13 commits into from
Dec 30, 2024
Merged
6 changes: 3 additions & 3 deletions examples/src/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from the provider is the user's ID, name, and creation date. This is despite the
provider having additional fields in the response.

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.
Note that the code in this module is agnostic of Pact (i.e., this would be your
production code). The `pact-python` dependency only appears in the tests. This
is because the consumer is not concerned with Pact, only the tests are.
"""

from __future__ import annotations
Expand Down
6 changes: 3 additions & 3 deletions examples/src/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
testing will provide feedback on whether the consumer is compatible with the
provider's changes.

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.
Note that the code in this module is agnostic of Pact (i.e., this would be your
production code). The `pact-python` dependency only appears in the tests. This
is because the consumer is not concerned with Pact, only the tests are.
"""

from __future__ import annotations
Expand Down
14 changes: 11 additions & 3 deletions examples/src/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
(the consumer) and returns a response. In this example, we have a simple
endpoint which returns a user's information from a (fake) database.

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.
This also showcases how Pact tests differ from merely testing adherence to an
OpenAPI specification. The Pact tests are more concerned with the practical use
of the API, rather than the formally defined specification. The User class
defined here has additional fields which are not used by the consumer. Should
the provider later decide to add or remove fields, Pact's consumer-driven
testing will provide feedback on whether the consumer is compatible with the
provider's changes.

Note that the code in this module is agnostic of Pact (i.e., this would be your
production code). The `pact-python` dependency only appears in the tests. This
is because the consumer is not concerned with Pact, only the tests are.
"""

from __future__ import annotations
Expand Down
16 changes: 13 additions & 3 deletions examples/src/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
Handler for non-HTTP interactions.

This module implements a very basic handler to handle JSON payloads which might
be sent from Kafka, or some queueing system. Unlike a HTTP interaction, the
handler is solely responsible for processing the message, and does not
necessarily need to send a response.
be sent through a messaging system. Unlike a HTTP interaction, the handler is
solely responsible for processing the message, and does not necessarily need to
send a response. This specific example handles file system events.

Due to the broad range of possible technologies underpinning message systems
(e.g., Kafka, RabbitMQ, SQS, SNS, etc.), Pact's implementation is agnostic to
the transport mechanism. Instead, Pact Python v3 allows to provide a simple
function (or mapping of functions) to produce messages. Under the hood, Pact
uses HTTP to communicate

Note that the code in this module is agnostic of Pact (i.e., this would be your
production code). The `pact-python` dependency only appears in the tests. This
is because the consumer is not concerned with Pact, only the tests are.
"""

from __future__ import annotations
Expand Down
4 changes: 4 additions & 0 deletions examples/src/message_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

This modules implements a very basic message producer which could
send to an eventing system, such as Kafka, or a message queue.

Note that the code in this module is agnostic of Pact (i.e., this would be your
production code). The `pact-python` dependency only appears in the tests. This
is because the consumer is not concerned with Pact, only the tests are.
"""

from __future__ import annotations
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_01_provider_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def mock_pact_provider_states(
"""
Define the provider state.
For Pact to be able to correctly tests compliance with the contract, the
For Pact to be able to correctly test compliance with the contract, the
internal state of the provider needs to be set up correctly. Naively, this
would be achieved by setting up the database with the correct data for the
test, but this can be slow and error-prone. Instead this is best achieved by
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_01_provider_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def mock_pact_provider_states() -> dict[str, str | None]:
"""
Define the provider state.
For Pact to be able to correctly tests compliance with the contract, the
For Pact to be able to correctly test compliance with the contract, the
internal state of the provider needs to be set up correctly. Naively, this
would be achieved by setting up the database with the correct data for the
test, but this can be slow and error-prone. Instead this is best achieved by
Expand Down
148 changes: 0 additions & 148 deletions examples/tests/v3/basic_flask_server.py

This file was deleted.

Loading
Loading