Skip to content

Feat/v2 consumer suite #546

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

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion pact/v3/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5687,7 +5687,14 @@ def with_matching_rules(
Raises:
RuntimeError: If the rules could not be added.
"""
raise NotImplementedError
success: bool = lib.pactffi_with_matching_rules(
interaction._ref,
part.value,
rules.encode("utf-8"),
)
if not success:
msg = f"Unable to set matching rules for {interaction}."
raise RuntimeError(msg)


def with_multipart_file_v2( # noqa: PLR0913
Expand Down
35 changes: 35 additions & 0 deletions pact/v3/pact.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,41 @@ def with_plugin_contents(
)
return self

def with_matching_rules(
self,
rules: dict[str, Any] | str,
part: Literal["Request", "Response"] | None = None,
) -> Self:
"""
Add matching rules to the interaction.

Matching rules are used to specify how the request or response should be
matched. This is useful for specifying that certain parts of the request
or response are flexible, such as the date or time.

Args:
rules:
Matching rules to add to the interaction. This must be
encodable using [`json.dumps(...)`][json.dumps], or a string.

part:
Whether the matching rules should be added to the request or the
response. If `None`, then the function intelligently determines
whether the matching rules should be added to the request or the
response, based on whether the
[`will_respond_with(...)`][pact.v3.Interaction.will_respond_with]
method has been called.
"""
if isinstance(rules, dict):
rules = json.dumps(rules)

pact.v3.ffi.with_matching_rules(
self._handle,
self._parse_interaction_part(part),
rules,
)
return self


class HttpInteraction(Interaction):
"""
Expand Down
Loading