|
| 1 | +""" |
| 2 | +Tests for user-reported issues. |
| 3 | +""" |
| 4 | + |
| 5 | +import os |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +import pytest |
| 9 | + |
| 10 | +from pact import MessageConsumer, Provider, matchers |
| 11 | + |
| 12 | + |
| 13 | +def test_github_850_issue() -> None: |
| 14 | + """ |
| 15 | + See https://github.com/pact-foundation/pact-python/issues/850. |
| 16 | +
|
| 17 | + User reported an issue with Pact files not being written when using consumer |
| 18 | + and provider names with spaces. A warning was added to the code to alert the |
| 19 | + user that the names should not contain spaces. |
| 20 | + """ |
| 21 | + contract = MessageConsumer("My Consumer").has_pact_with( |
| 22 | + Provider("My Provider"), |
| 23 | + pact_dir="pacts", |
| 24 | + ) |
| 25 | + |
| 26 | + # Define os dados do evento |
| 27 | + event_data = { |
| 28 | + "invoice_id": "12345", |
| 29 | + "amount": 100.00, |
| 30 | + "currency": "USD", |
| 31 | + "created": matchers.Format().iso_8601_datetime(), |
| 32 | + } |
| 33 | + |
| 34 | + # Cria uma mensagem que representa o evento |
| 35 | + contract.given("Create contract").expects_to_receive( |
| 36 | + "An event of contract" |
| 37 | + ).with_content(event_data) |
| 38 | + |
| 39 | + with contract: |
| 40 | + pass |
| 41 | + |
| 42 | + pact_file = Path("pacts/my_consumer-my_provider.json") |
| 43 | + # The file should only be created on non-Windows systems |
| 44 | + assert pact_file.exists() == (os.name != "nt") |
| 45 | + |
| 46 | + |
| 47 | +def test_github_850_fix(recwarn: pytest.WarningsRecorder) -> None: |
| 48 | + """ |
| 49 | + See https://github.com/pact-foundation/pact-python/issues/850. |
| 50 | +
|
| 51 | + User reported an issue with Pact files not being written when using consumer |
| 52 | + and provider names with spaces. A warning was added to the code to alert the |
| 53 | + user that the names should not contain spaces. |
| 54 | + """ |
| 55 | + MessageConsumer("My Consumer").has_pact_with( |
| 56 | + Provider("My Provider"), |
| 57 | + pact_dir="pacts", |
| 58 | + ) |
| 59 | + |
| 60 | + # Check for warnings |
| 61 | + warnings = [str(warning.message) for warning in recwarn] |
| 62 | + assert any( |
| 63 | + "Consumer name should not contain spaces." in warning for warning in warnings |
| 64 | + ) |
| 65 | + assert any( |
| 66 | + "Provider name should not contain spaces." in warning for warning in warnings |
| 67 | + ) |
0 commit comments