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

chore: add test for #850 #858

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions src/pact/message_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
PendingDeprecationWarning,
stacklevel=2,
)
if len(name.split()) > 1:
warnings.warn(

Check warning on line 67 in src/pact/message_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pact/message_consumer.py#L67

Added line #L67 was not covered by tests
"Consumer name should not contain spaces.",
UserWarning,
stacklevel=2
)
self.name = name
self.service_cls = service_cls
self.tags = tags
Expand Down
6 changes: 6 additions & 0 deletions src/pact/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@
PendingDeprecationWarning,
stacklevel=2,
)
if len(name.split()) > 1:
warnings.warn(

Check warning on line 25 in src/pact/provider.py

View check run for this annotation

Codecov / codecov/patch

src/pact/provider.py#L25

Added line #L25 was not covered by tests
"Provider name should not contain spaces.",
UserWarning,
stacklevel=2,
)
self.name = name
67 changes: 67 additions & 0 deletions tests/test_issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Tests for user-reported issues.
"""

import os
from pathlib import Path

import pytest

from pact import MessageConsumer, Provider, matchers


def test_github_850_issue() -> None:
"""
See https://github.com/pact-foundation/pact-python/issues/850.

User reported an issue with Pact files not being written when using consumer
and provider names with spaces. A warning was added to the code to alert the
user that the names should not contain spaces.
"""
contract = MessageConsumer("My Consumer").has_pact_with(
Provider("My Provider"),
pact_dir="pacts",
)

# Define os dados do evento
event_data = {
"invoice_id": "12345",
"amount": 100.00,
"currency": "USD",
"created": matchers.Format().iso_8601_datetime(),
}

# Cria uma mensagem que representa o evento
contract.given("Create contract").expects_to_receive(
"An event of contract"
).with_content(event_data)

with contract:
pass

pact_file = Path("pacts/my_consumer-my_provider.json")
# The file should only be created on non-Windows systems
assert pact_file.exists() == (os.name != "nt")


def test_github_850_fix(recwarn: pytest.WarningsRecorder) -> None:
"""
See https://github.com/pact-foundation/pact-python/issues/850.

User reported an issue with Pact files not being written when using consumer
and provider names with spaces. A warning was added to the code to alert the
user that the names should not contain spaces.
"""
MessageConsumer("My Consumer").has_pact_with(
Provider("My Provider"),
pact_dir="pacts",
)

# Check for warnings
warnings = [str(warning.message) for warning in recwarn]
assert any(
"Consumer name should not contain spaces." in warning for warning in warnings
)
assert any(
"Provider name should not contain spaces." in warning for warning in warnings
)
Loading