|
2 | 2 | Tests for user-reported issues.
|
3 | 3 | """
|
4 | 4 |
|
5 |
| -import json |
6 |
| -from pathlib import Path |
| 5 | +import pytest |
7 | 6 |
|
8 |
| -from pact import MessageConsumer, Provider, matchers |
| 7 | +from pact import MessageConsumer, Provider |
9 | 8 |
|
10 | 9 |
|
11 |
| -def test_github_850() -> None: |
| 10 | +def test_github_850(recwarn: pytest.WarningsRecorder) -> None: |
12 | 11 | """
|
13 | 12 | See https://github.com/pact-foundation/pact-python/issues/850.
|
| 13 | +
|
| 14 | + User reported an issue with Pact files not being written when using consumer |
| 15 | + and provider names with spaces. A warning was added to the code to alert the |
| 16 | + user that the names should not contain spaces. |
14 | 17 | """
|
15 |
| - contract = MessageConsumer("my_contract_consumer").has_pact_with( |
16 |
| - Provider("my_contract_provider"), |
| 18 | + MessageConsumer("my_contract Consumer").has_pact_with( |
| 19 | + Provider("my_contract Provider"), |
17 | 20 | pact_dir="pacts",
|
18 | 21 | )
|
19 | 22 |
|
20 |
| - event_data = { |
21 |
| - "invoice_id": "12345", |
22 |
| - "amount": 100.00, |
23 |
| - "currency": "USD", |
24 |
| - "created": matchers.Format().iso_8601_datetime(), |
25 |
| - } |
26 |
| - |
27 |
| - contract.given("Create contract").expects_to_receive( |
28 |
| - "An event of contract" |
29 |
| - ).with_content(event_data) |
30 |
| - |
31 |
| - with contract: |
32 |
| - pass |
33 |
| - |
34 |
| - with Path("pacts/my_contract_consumer-my_contract_provider.json").open() as f: |
35 |
| - data = json.load(f) |
36 |
| - assert data["messages"][0]["contents"]["created"] == "1991-02-20T06:35:26+00:00" |
| 23 | + # Check for warnings |
| 24 | + warnings = [str(warning.message) for warning in recwarn] |
| 25 | + assert any( |
| 26 | + "Consumer name should not contain spaces." in warning for warning in warnings |
| 27 | + ) |
| 28 | + assert any( |
| 29 | + "Provider name should not contain spaces." in warning for warning in warnings |
| 30 | + ) |
0 commit comments