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

Feature/add support and example messenger consumer using rust engine 380 #699

Closed
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
31bd379
Adding v3 and v4 message consumer tests
valkolovos May 16, 2024
c6dd880
created MessagePact, cleaned up the verify method to use interaction …
valkolovos May 16, 2024
2891e4a
removing write_message_file method as it is unecessary
valkolovos May 16, 2024
76e9ff2
lint cleanup
valkolovos May 22, 2024
1e62a37
lint cleanup
valkolovos May 22, 2024
d0daa48
revert change that shouldn't have been committed
valkolovos May 22, 2024
3d7dc66
moving message pact verification to interaction
valkolovos May 23, 2024
49f06ee
setting harder version on jsonpath_ng
valkolovos May 28, 2024
2e460f7
cleaning up ffi.py
valkolovos May 31, 2024
1645640
PR changes
valkolovos Jun 5, 2024
deec315
importing Self from typing_extensions for backwards compatibility
valkolovos Jun 5, 2024
9db0021
chore(examples): ensure docker compose is started
JP-Ellis Jun 6, 2024
9aef6b4
chore(examples): wait for servers to start
JP-Ellis Jun 6, 2024
dbcfe80
docs(examples): explain the purpose for fs class
JP-Ellis Jun 6, 2024
713e59d
chore(examples): remove redundant v3 in filename
JP-Ellis Jun 6, 2024
4070ecd
fix(examples): typing annotations
JP-Ellis Jun 6, 2024
cef8f21
chore(examples): silence deprecation warnings
JP-Ellis Jun 6, 2024
0f76c5f
refactor(v3): rename AsyncMessagePactResult to AsyncInteractionResult
JP-Ellis Jun 6, 2024
57d1a07
refactor(v3): merge Pact classes
JP-Ellis Jun 6, 2024
7bfa7b8
chore(v3): remove _pact_handle as it is never used
JP-Ellis Jun 6, 2024
07d413b
docs(v3): add some clarity about interaction parts
JP-Ellis Jun 6, 2024
a972986
docs(ffi): remove unnecessary safety message
JP-Ellis Jun 6, 2024
941f123
chore: use existing method
JP-Ellis Jun 6, 2024
7258455
chore(v3): minor refactor of with_contents
JP-Ellis Jun 6, 2024
dd4af8a
chore(v3): remove public reify
JP-Ellis Jun 6, 2024
8f0815d
chore(v3): use with_metadata_v2
JP-Ellis Jun 6, 2024
f79a20d
chore(v3): publicly export Pact and Verifier
JP-Ellis Jun 6, 2024
9326a90
chore(ffi): minor type/style fixes
JP-Ellis Jun 6, 2024
f777d0c
first pass at fixing tests
valkolovos Jun 11, 2024
ed26782
remove 'import pdb'
valkolovos Jun 11, 2024
4e13c37
chore(ffi): remove message handle
JP-Ellis Jun 11, 2024
1b14be1
chore(v3): add with_metadata
JP-Ellis Jun 12, 2024
73f82fc
style: use snake_case
JP-Ellis Jun 12, 2024
980565b
chore: remove with_content
JP-Ellis Jun 12, 2024
55b42ea
chore: remove interaction verify
JP-Ellis Jun 12, 2024
2d92f86
feat(ffi): use the new with_metadata
JP-Ellis Jun 12, 2024
e56f018
chore(ffi): add enum type alias
JP-Ellis Jun 16, 2024
aafeeda
chore: implement ffi
JP-Ellis Jun 16, 2024
466e107
feat(v3): implement interactions iterator
JP-Ellis Jun 16, 2024
ab3c02b
chore(v3): remove messages iterator
JP-Ellis Jun 16, 2024
5aaf1a7
feat(v3): add verify method for pact messages
JP-Ellis Jun 16, 2024
d64abb0
chore(v3): remove get_provider_states
JP-Ellis Jun 16, 2024
7ab24c8
fix(v3): various typing issues
JP-Ellis Jun 16, 2024
ee99af7
feat: optional freeing of memory
JP-Ellis Jun 18, 2024
d1c0d1b
chore(ffi): minor fixes and implementations
JP-Ellis Jun 18, 2024
5107a59
fix(ffi): ensure parent outline dependent objects
JP-Ellis Jun 18, 2024
d118431
feat(ffi): add `generate_contents` methods
JP-Ellis Jun 18, 2024
db2d343
feat(v3): add with_generators
JP-Ellis Jun 18, 2024
aeb2e95
chore(ffi): minor changes
JP-Ellis Jun 18, 2024
dccb863
feat(v3): add new exception types
JP-Ellis Jun 18, 2024
c3ddcd5
fix(v3): interactions iterator
JP-Ellis Jun 19, 2024
6f0eff6
chore(test): use named tuple more broadly
JP-Ellis Jun 19, 2024
cf6cfd7
refactor(test): v3 message consumer
JP-Ellis Jun 19, 2024
a9fa8f0
refactor(examples): v3 message consumer
JP-Ellis Jun 19, 2024
67f5322
fix(v3): typing issues
JP-Ellis Jun 19, 2024
654c904
feat(ffi): upgrade ffi library to v0.4.21
JP-Ellis Jun 19, 2024
999fb45
ci: add wheel target
JP-Ellis Jun 19, 2024
aed2e09
chore(v3): remove defunct test
JP-Ellis Jun 19, 2024
31b9ed4
refactor(tests): minor drying message consumer tests
JP-Ellis Jun 20, 2024
dd14a47
chore: ignore test outputs
JP-Ellis Jun 21, 2024
9e210f6
docs: fix discovery
JP-Ellis Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lint cleanup
valkolovos committed May 22, 2024
commit 1e62a37358fecfd222da8fef18541fd3aae22ba9
94 changes: 49 additions & 45 deletions tests/v3/compatibility_suite/test_v4_message_consumer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Message consumer feature tests."""
from __future__ import annotations

import json
import os
import pytest
from collections import namedtuple
from typing import Any
from typing import TYPE_CHECKING, Any, NamedTuple

from pytest_bdd import (
given,
@@ -13,49 +12,49 @@
when,
)

from pact.v3.pact import AsyncMessageInteraction
from pact.v3.pact import MessagePact as Pact
from tests.v3.compatibility_suite.util import string_to_int
from pact.v3.pact import AsyncMessageInteraction, MessagePact as Pact

PactInteraction = namedtuple("PactInteraction", ["pact", "interaction"])
if TYPE_CHECKING:
from pathlib import Path


class PactInteraction(NamedTuple):
"""Holder class for Pact and Interaction."""
pact: Pact
interaction: AsyncMessageInteraction

TEST_PACT_FILE_DIRECTORY = os.path.join(os.path.dirname(__file__), 'pacts')

@scenario(
'definition/features/V4/message_consumer.feature',
'Sets the type for the interaction'
"definition/features/V4/message_consumer.feature",
"Sets the type for the interaction"
)
def test_sets_the_type_for_the_interaction():
def test_sets_the_type_for_the_interaction() -> None:
"""Sets the type for the interaction."""


@scenario(
'definition/features/V4/message_consumer.feature',
'Supports adding comments'
"definition/features/V4/message_consumer.feature",
"Supports adding comments"
)
def test_supports_adding_comments():
def test_supports_adding_comments() -> None:
"""Supports adding comments."""


@pytest.fixture(autouse=True)
def handle_pact_file_directory():
if not os.path.exists(TEST_PACT_FILE_DIRECTORY):
os.mkdir(TEST_PACT_FILE_DIRECTORY)
yield
os.rmdir(TEST_PACT_FILE_DIRECTORY)

@scenario(
'definition/features/V4/message_consumer.feature',
'Supports specifying a key for the interaction'
"definition/features/V4/message_consumer.feature",
"Supports specifying a key for the interaction"
)
def test_supports_specifying_a_key_for_the_interaction():
def test_supports_specifying_a_key_for_the_interaction() -> None:
"""Supports specifying a key for the interaction."""


@scenario(
'definition/features/V4/message_consumer.feature',
'Supports specifying the interaction is pending'
"definition/features/V4/message_consumer.feature",
"Supports specifying the interaction is pending"
)
def test_supports_specifying_the_interaction_is_pending():
def test_supports_specifying_the_interaction_is_pending() -> None:
"""Supports specifying the interaction is pending."""


@@ -70,12 +69,14 @@ def test_supports_specifying_the_interaction_is_pending():
def a_comment_is_added_to_the_message_interaction(
pact_interaction: PactInteraction,
comment: str
):
"""a comment "{comment}" is added to the message interaction."""
) -> None:
"""A comment "{comment}" is added to the message interaction."""
pact_interaction.interaction.add_text_comment(comment)


@given(parsers.re(r'a key of "(?P<key>[^"]+)" is specified for the message interaction'))
@given(parsers.re(
r'a key of "(?P<key>[^"]+)" is specified for the message interaction')
)
def a_key_is_specified_for_the_http_interaction(
pact_interaction: PactInteraction,
key: str,
@@ -85,21 +86,21 @@ def a_key_is_specified_for_the_http_interaction(


@given(
'a message interaction is being defined for a consumer test',
target_fixture='pact_interaction'
"a message interaction is being defined for a consumer test",
target_fixture="pact_interaction"
)
def a_message_interaction_is_being_defined_for_a_consumer_test():
"""a message integration is being defined for a consumer test."""
pact = Pact("message_consumer", "message_provider")
def a_message_interaction_is_being_defined_for_a_consumer_test() -> None:
"""A message integration is being defined for a consumer test."""
pact = Pact("consumer", "provider")
pact.with_specification("V4")
yield PactInteraction(pact, pact.upon_receiving("a request", "Async"))


@given('the message interaction is marked as pending')
@given("the message interaction is marked as pending")
def the_message_interaction_is_marked_as_pending(
pact_interaction: PactInteraction
):
"""the message interaction is marked as pending."""
) -> None:
"""The message interaction is marked as pending."""
pact_interaction.interaction.set_pending(pending=True)


@@ -109,17 +110,20 @@ def the_message_interaction_is_marked_as_pending(


@when(
'the Pact file for the test is generated',
target_fixture='pact_data'
"the Pact file for the test is generated",
target_fixture="pact_data"
)
def the_pact_file_for_the_test_is_generated(
pact_interaction: PactInteraction
):
"""the Pact file for the test is generated."""
pact_interaction.pact.write_file(TEST_PACT_FILE_DIRECTORY, overwrite=True)
with open(os.path.join(TEST_PACT_FILE_DIRECTORY, 'message_consumer-message_provider.json')) as file:
pact_interaction: PactInteraction,
temp_dir: Path
) -> None:
"""The Pact file for the test is generated."""
(temp_dir / "pacts").mkdir(exist_ok=True, parents=True)
pact_interaction.pact.write_file(temp_dir / "pacts")
with (
temp_dir / "pacts" / "consumer-provider.json"
).open() as file:
yield json.load(file)
os.remove(os.path.join(TEST_PACT_FILE_DIRECTORY, 'message_consumer-message_provider.json'))


################################################################################