Skip to content

Commit ac1a719

Browse files
committed
chore: set reproducer based on pact-foundation/pact-python#1333
1 parent 3d7b74b commit ac1a719

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

app/test/app_spec.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,45 @@
22
from pact import Verifier
33
import pact_ffi
44

5+
from typing import Literal, Any
6+
7+
def provider_state_handler(
8+
state: str,
9+
action: Literal["setup", "teardown"],
10+
parameters: dict[str, Any] | None,
11+
) -> None:
12+
"""Handle all provider state changes."""
13+
parameters = parameters or {}
14+
if state == "a product with ID 10 exists":
15+
if action == "setup":
16+
return
17+
if action == "teardown":
18+
return
19+
msg = f"Unknown state/action: {state}/{action}"
20+
raise ValueError(msg)
21+
22+
523
def test_provider():
624
"""Test the provider against the consumer contract."""
725
pact_ffi.log_to_stderr("DEBUG")
826
verifier = (
927
Verifier("pactflow-example-provider-python") # Provider name
1028
.add_transport(url="http://localhost:8000")
29+
.state_handler(provider_state_handler, teardown=False)
1130
.broker_source(
12-
os.environ.get("PACT_BROKER_BASE_URL", "https://broker.pactflow.io/"),
13-
token=os.environ.get("PACT_BROKER_TOKEN", "broker-token"), # or use token="bearer-token"
31+
url=os.environ.get("PACT_BROKER_BASE_URL", "https://broker.pactflow.io/"),
32+
token=os.environ.get("PACT_BROKER_TOKEN", "broker-token"),
33+
selector=True
1434
)
35+
.consumer_versions('{"mainBranch": true}', '{"deployedOrReleased": true}')
36+
.include_pending()
37+
.include_wip_since("2025-11-10")
38+
.build()
1539
)
16-
40+
# verifier.set_publish_options(
41+
# version="123",
42+
# branch="foo",
43+
# )
1744
verifier.verify()
1845

1946
if __name__ == "__main__":

0 commit comments

Comments
 (0)