Skip to content

Commit 93a5432

Browse files
committed
chore(tests): add v4 message provider compatibility suite
Signed-off-by: JP-Ellis <[email protected]>
1 parent 058c9ac commit 93a5432

File tree

3 files changed

+175
-26
lines changed

3 files changed

+175
-26
lines changed

tests/v3/compatibility_suite/test_v3_message_producer.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
InteractionState,
2727
)
2828
from tests.v3.compatibility_suite.util.provider import (
29+
a_pact_file_for_message_is_to_be_verified,
2930
a_provider_is_started_that_can_generate_the_message,
3031
a_provider_state_callback_is_configured,
3132
start_provider,
@@ -199,6 +200,7 @@ def test_verifying_multiple_pact_files() -> None:
199200

200201
a_provider_is_started_that_can_generate_the_message()
201202
a_provider_state_callback_is_configured()
203+
a_pact_file_for_message_is_to_be_verified("V3")
202204

203205

204206
@given(
@@ -240,32 +242,6 @@ def a_pact_file_for_is_to_be_verified_with_the_following(
240242
verifier.add_source(temp_dir / "pacts")
241243

242244

243-
@given(
244-
parsers.re(
245-
r'a Pact file for "(?P<name>[^"]+)":"(?P<fixture>[^"]+)" is to be verified'
246-
)
247-
)
248-
def a_pact_file_for_is_to_be_verified(
249-
verifier: Verifier,
250-
temp_dir: Path,
251-
name: str,
252-
fixture: str,
253-
) -> None:
254-
pact = Pact("consumer", "provider")
255-
pact.with_specification("V3")
256-
interaction_definition = InteractionDefinition(
257-
type="Async",
258-
description=name,
259-
body=fixture,
260-
)
261-
interaction_definition.add_to_pact(pact, name)
262-
(temp_dir / "pacts").mkdir(exist_ok=True, parents=True)
263-
pact.write_file(temp_dir / "pacts")
264-
with (temp_dir / "pacts" / "consumer-provider.json").open() as f:
265-
logger.debug("Pact file contents: %s", f.read())
266-
verifier.add_source(temp_dir / "pacts")
267-
268-
269245
@given(
270246
parsers.re(
271247
r'a Pact file for "(?P<name>[^"]+)":"(?P<fixture>[^"]+)"'
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""
2+
Basic HTTP provider feature test.
3+
"""
4+
5+
from __future__ import annotations
6+
7+
import logging
8+
import sys
9+
10+
import pytest
11+
from pytest_bdd import scenario
12+
13+
from tests.v3.compatibility_suite.util.provider import (
14+
a_pact_file_for_message_is_to_be_verified,
15+
a_pact_file_for_message_is_to_be_verified_with_comments,
16+
a_provider_is_started_that_can_generate_the_message,
17+
the_comment_will_have_been_printed_to_the_console,
18+
the_name_of_the_test_will_be_displayed_as_the_original_test_name,
19+
the_verification_is_run,
20+
the_verification_results_will_contain_a_error,
21+
the_verification_will_be_successful,
22+
there_will_be_a_pending_error,
23+
)
24+
25+
logger = logging.getLogger(__name__)
26+
27+
28+
################################################################################
29+
## Scenario
30+
################################################################################
31+
32+
33+
@pytest.mark.skipif(
34+
sys.platform.startswith("win"),
35+
reason="See pact-foundation/pact-python#639",
36+
)
37+
@scenario(
38+
"definition/features/V4/message_provider.feature",
39+
"Verifying a pending message interaction",
40+
)
41+
def test_verifying_a_pending_message_interaction() -> None:
42+
"""
43+
Verifying a pending message interaction.
44+
"""
45+
46+
47+
@pytest.mark.skipif(
48+
sys.platform.startswith("win"),
49+
reason="See pact-foundation/pact-python#639",
50+
)
51+
@scenario(
52+
"definition/features/V4/message_provider.feature",
53+
"Verifying a message interaction with comments",
54+
)
55+
def test_verifying_a_message_interaction_with_comments() -> None:
56+
"""
57+
Verifying a message interaction with comments.
58+
"""
59+
60+
61+
################################################################################
62+
## Given
63+
################################################################################
64+
65+
66+
a_provider_is_started_that_can_generate_the_message()
67+
a_pact_file_for_message_is_to_be_verified("V4")
68+
a_pact_file_for_message_is_to_be_verified_with_comments("V4")
69+
70+
71+
################################################################################
72+
## When
73+
################################################################################
74+
75+
76+
the_verification_is_run()
77+
78+
79+
################################################################################
80+
## Then
81+
################################################################################
82+
83+
84+
the_comment_will_have_been_printed_to_the_console()
85+
the_name_of_the_test_will_be_displayed_as_the_original_test_name()
86+
the_verification_results_will_contain_a_error()
87+
the_verification_will_be_successful()
88+
there_will_be_a_pending_error()

tests/v3/compatibility_suite/util/provider.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,45 @@ def _(
777777
verifier.add_source(temp_dir / "pacts")
778778

779779

780+
def a_pact_file_for_message_is_to_be_verified(
781+
version: str,
782+
stacklevel: int = 1,
783+
) -> None:
784+
@given(
785+
parsers.re(
786+
r'a Pact file for "(?P<name>[^"]+)":"(?P<fixture>[^"]+)" is to be verified'
787+
r"(?P<pending>(, but is marked pending)?)",
788+
),
789+
converters={"pending": lambda x: x != ""},
790+
stacklevel=stacklevel + 1,
791+
)
792+
def _(
793+
verifier: Verifier,
794+
temp_dir: Path,
795+
name: str,
796+
fixture: str,
797+
pending: bool, # noqa: FBT001
798+
) -> None:
799+
defn = InteractionDefinition(
800+
type="Async",
801+
description=name,
802+
body=fixture,
803+
)
804+
defn.pending = pending
805+
logger.debug("Adding message interaction: %s", defn)
806+
807+
pact = Pact("consumer", "provider")
808+
pact.with_specification(version)
809+
defn.add_to_pact(pact, name)
810+
(temp_dir / "pacts").mkdir(exist_ok=True, parents=True)
811+
pact.write_file(temp_dir / "pacts")
812+
813+
with (temp_dir / "pacts" / "consumer-provider.json").open() as f:
814+
logger.debug("Pact file contents: %s", f.read())
815+
816+
verifier.add_source(temp_dir / "pacts")
817+
818+
780819
def a_pact_file_for_interaction_is_to_be_verified_with_comments(
781820
version: str,
782821
stacklevel: int = 1,
@@ -832,6 +871,52 @@ def _(
832871
verifier.add_source(temp_dir / "pacts")
833872

834873

874+
def a_pact_file_for_message_is_to_be_verified_with_comments(
875+
version: str,
876+
stacklevel: int = 1,
877+
) -> None:
878+
@given(
879+
parsers.re(
880+
r'a Pact file for "(?P<name>[^"]+)":"(?P<fixture>[^"]+)" is to be verified'
881+
r" with the following comments:\n(?P<comments>.+)",
882+
re.DOTALL,
883+
),
884+
converters={"comments": parse_markdown_table},
885+
stacklevel=stacklevel + 1,
886+
)
887+
def _(
888+
verifier: Verifier,
889+
temp_dir: Path,
890+
name: str,
891+
fixture: str,
892+
comments: list[dict[str, str]],
893+
) -> None:
894+
defn = InteractionDefinition(
895+
type="Async",
896+
description=name,
897+
body=fixture,
898+
)
899+
for comment in comments:
900+
if comment["type"] == "text":
901+
defn.text_comments.append(comment["comment"])
902+
elif comment["type"] == "testname":
903+
defn.test_name = comment["comment"]
904+
else:
905+
defn.comments[comment["type"]] = comment["comment"]
906+
logger.info("Updated interaction: %s", defn)
907+
908+
pact = Pact("consumer", "provider")
909+
pact.with_specification(version)
910+
defn.add_to_pact(pact, name)
911+
(temp_dir / "pacts").mkdir(exist_ok=True, parents=True)
912+
pact.write_file(temp_dir / "pacts")
913+
914+
with (temp_dir / "pacts" / "consumer-provider.json").open() as f:
915+
logger.debug("Pact file contents: %s", f.read())
916+
917+
verifier.add_source(temp_dir / "pacts")
918+
919+
835920
def a_pact_file_for_interaction_is_to_be_verified_from_a_pact_broker(
836921
version: str,
837922
stacklevel: int = 1,

0 commit comments

Comments
 (0)