Skip to content

Commit

Permalink
chore: use matchers in v3 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
individual-it committed Oct 7, 2024
1 parent 46160eb commit 2f084b0
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions examples/tests/v3/test_00_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import requests

from examples.src.consumer import UserConsumer
from pact.v3 import Pact
from pact.v3 import Pact, match


@pytest.fixture
Expand Down Expand Up @@ -75,24 +75,17 @@ def test_get_existing_user(pact: Pact) -> None:
expected: Dict[str, Any] = {
"id": 123,
"name": "Verna Hampton",
"created_on": {
# This structure is using the Integration JSON format as described
# in the link below. The preview of V3 currently does not have
# built-in support for matchers and generators, though this is on
# the roadmap and will be available before the final release.
#
# <https://docs.pact.io/implementation_guides/rust/pact_ffi/integrationjson>
"pact:matcher:type": "regex",
"regex": r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}(Z|(\+|-)\d{2}:\d{2})",
"value": datetime.now(tz=timezone.utc).isoformat(),
},
"created_on": match.datetime(
datetime.now(tz=timezone.utc).isoformat(),
format="%Y-%m-%dT%H:%M:%S.%fZ",
),
}
(
pact.upon_receiving("a request for user information")
.given("user exists")
.with_request(method="GET", path="/users/123")
.will_respond_with(200)
.with_body(json.dumps(expected))
.with_body(expected)
)

with pact.serve() as srv:
Expand Down Expand Up @@ -145,17 +138,10 @@ def test_create_user(pact: Pact) -> None:
expected_response: Dict[str, Any] = {
"id": 124,
"name": "Verna Hampton",
"created_on": {
# This structure is using the Integration JSON format as described
# in the link below. The preview of V3 currently does not have
# built-in support for matchers and generators, though this is on
# the roadmap and will be available before the final release.
#
# <https://docs.pact.io/implementation_guides/rust/pact_ffi/integrationjson>
"pact:matcher:type": "regex",
"regex": r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}(Z|(\+|-)\d{2}:\d{2})",
"value": datetime.now(tz=timezone.utc).isoformat(),
},
"created_on": match.datetime(
datetime.now(tz=timezone.utc).isoformat(),
format="%Y-%m-%dT%H:%M:%S.%fZ",
),
}

(
Expand All @@ -164,7 +150,7 @@ def test_create_user(pact: Pact) -> None:
.with_request(method="POST", path="/users/")
.with_body(json.dumps(body), content_type="application/json")
.will_respond_with(status=200)
.with_body(content_type="application/json", body=json.dumps(expected_response))
.with_body(content_type="application/json", body=expected_response)
)

with pact.serve() as srv:
Expand Down

0 comments on commit 2f084b0

Please sign in to comment.