Skip to content
Draft
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ test: .env
test_native: .env
docker compose up pact_verifier_native --exit-code-from pact_verifier_native
docker compose logs pact_verifier_native
run_api:
docker compose up api
run_test_local:
python3 app/test/app_spec.py

## =====================
## Deploy tasks
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ make test

To run the "fake ci" task:
```
export PACT_BROKER_BASE_URL=https://test.pactflow.io
export PACT_BROKER_USERNAME=dXfltyFMgNOFZAxr8io9wJ37iUpY42M
export PACT_BROKER_PASSWORD=O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1
export PACT_BROKER_BASE_URL="https://test.pactflow.io"
export PACT_BROKER_TOKEN="129cCdfCWhMzcC9pFwb4bw"
make fake_ci
```
47 changes: 47 additions & 0 deletions app/test/app_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
from pact import Verifier
import pact_ffi

from typing import Literal, Any

def provider_state_handler(
state: str,
action: Literal["setup", "teardown"],
parameters: dict[str, Any] | None,
) -> None:
"""Handle all provider state changes."""
parameters = parameters or {}
if state == "a product with ID 10 exists":
if action == "setup":
return
if action == "teardown":
return
msg = f"Unknown state/action: {state}/{action}"
raise ValueError(msg)


def test_provider():
"""Test the provider against the consumer contract."""
pact_ffi.log_to_stderr("DEBUG")
verifier = (
Verifier("pactflow-example-provider-python") # Provider name
.add_transport(url="http://localhost:8000")
.state_handler(provider_state_handler, teardown=False)
.broker_source(
url=os.environ.get("PACT_BROKER_BASE_URL", "https://broker.pactflow.io/"),
token=os.environ.get("PACT_BROKER_TOKEN", "broker-token"),
selector=True
)
.consumer_versions('{"mainBranch": true}', '{"deployedOrReleased": true}')
.include_pending()
.include_wip_since("2025-11-10")
.build()
)
# verifier.set_publish_options(
# version="123",
# branch="foo",
# )
verifier.verify()

if __name__ == "__main__":
test_provider()
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ services:
context: .
volumes:
- ./app:/app
expose:
- "8000"
ports:
- 8000:8000
environment:
- PORT=8000

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fastapi==0.121.2
uvicorn==0.38.0
pact-python==3.1.0