From 2f084b0c0797a81f95909be8d5b23b6775eb0627 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Mon, 7 Oct 2024 13:27:24 +0545 Subject: [PATCH] chore: use matchers in v3 examples --- examples/tests/v3/test_00_consumer.py | 36 ++++++++------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/examples/tests/v3/test_00_consumer.py b/examples/tests/v3/test_00_consumer.py index 2807d1fc4..6f5e06fdf 100644 --- a/examples/tests/v3/test_00_consumer.py +++ b/examples/tests/v3/test_00_consumer.py @@ -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 @@ -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. - # - # - "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: @@ -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. - # - # - "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", + ), } ( @@ -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: