-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: warn if consumer/provider name has spaces
Discoeverd by user-reported issue in #850. Signed-off-by: JP-Ellis <[email protected]>
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |