Skip to content

Commit

Permalink
feat: 3.0.0b0
Browse files Browse the repository at this point in the history
allows for remote testing of fork via
git install.

tests both ruby and rust impls
  • Loading branch information
YOU54F committed Aug 9, 2023
1 parent 2df16b0 commit 41e42ef
Show file tree
Hide file tree
Showing 30 changed files with 501 additions and 103 deletions.
6 changes: 4 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ BUILD_TEST_TASK_TEMPLATE: &BUILD_TEST_TASK_TEMPLATE
- python -m flake8 --exclude '*pb2*',.git,__pycache__,build,dist,.tox --show-source
- python -m pydocstyle pact
- python -m tox -e test
- make todo
- make examples
- make examples_v3
- make examples_v4

env:
RUN_BROKER: 0
Expand All @@ -18,7 +20,7 @@ env:

PYTHON_VERSION_MATRIX: &PYTHON_VERSION_MATRIX
- VERSION: 3.11
# - VERSION: 3.6
- VERSION: 3.6
# - VERSION: 3.7
# - VERSION: 3.8
# - VERSION: 3.9
Expand Down
5 changes: 2 additions & 3 deletions examples/common/sharedfixtures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from os.path import join, dirname
from os import getenv
import platform
import pathlib
import subprocess

import docker
Expand Down Expand Up @@ -64,7 +63,7 @@ def publish_existing_pact(broker):
if int(getenv('SKIP_PUBLISH', '1')) == 0:
return

source = join(dirname(__file__),"..", "pacts")
source = join(dirname(__file__), "..", "pacts")
pacts = [f"{source}:/pacts"]

use_hosted_pact_broker = int(getenv('USE_HOSTED_PACT_BROKER', '0'))
Expand Down Expand Up @@ -97,7 +96,7 @@ def publish_existing_pact(broker):
envs["PACT_BROKER_BASE_URL"] = "http://localhost"
result = subprocess.run([join(dirname(__file__), '..', '..', 'pact', 'bin', 'pact', 'bin', executable),
'publish',
join(dirname(__file__),'..', 'pacts'),
join(dirname(__file__), '..', 'pacts'),
'--consumer-app-version', '1',
'--broker-base-url', envs["PACT_BROKER_BASE_URL"],
'--broker-username', envs["PACT_BROKER_USERNAME"],
Expand Down
6 changes: 5 additions & 1 deletion examples/consumer/run_pytest.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
set -o pipefail

pytest tests --run-broker True --publish-pact 1
if [ "$RUN_BROKER" = '0' ]; then
pytest tests --publish-pact 1
else
pytest tests --run-broker True --publish-pact 1
fi
12 changes: 9 additions & 3 deletions examples/consumer/tests/consumer/test_user_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
# If publishing the Pact(s), they will be submitted to the Pact Broker here.
# For the purposes of this example, the broker is started up as a fixture defined
# in conftest.py. For normal usage this would be self-hosted or using PactFlow.
PACT_BROKER_URL = "http://localhost"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"
use_pactflow = int(os.getenv('USE_HOSTED_PACT_BROKER', '0'))
if use_pactflow == 1:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "https://test.pactflow.io")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "dXfltyFMgNOFZAxr8io9wJ37iUpY42M")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")
else:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "http://localhost")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "pactbroker")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "pactbroker")

# Define where to run the mock server, for the consumer to connect to. These
# are the defaults so may be omitted
Expand Down
6 changes: 5 additions & 1 deletion examples/fastapi_provider/run_pytest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ set -o pipefail

# Unlike in the Flask example, here the FastAPI service is started up as a pytest fixture. This is then including the
# main and pact routes via fastapi_provider.py to run the tests against
pytest --run-broker True --publish-pact 1\
if [ "$RUN_BROKER" = '0' ]; then
pytest tests --publish-pact 1
else
pytest tests --run-broker True --publish-pact 1
fi
13 changes: 10 additions & 3 deletions examples/fastapi_provider/tests/provider/test_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""pact test for user service client"""
import logging
import os

import pytest

Expand All @@ -11,9 +12,15 @@

# For the purposes of this example, the broker is started up as a fixture defined
# in conftest.py. For normal usage this would be self-hosted or using PactFlow.
PACT_BROKER_URL = "http://localhost"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"
use_pactflow = int(os.getenv('USE_HOSTED_PACT_BROKER', '0'))
if use_pactflow == 1:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "https://test.pactflow.io")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "dXfltyFMgNOFZAxr8io9wJ37iUpY42M")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")
else:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "http://localhost")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "pactbroker")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "pactbroker")

# For the purposes of this example, the FastAPI provider will be started up as
# a fixture in conftest.py ("server"). Alternatives could be, for example
Expand Down
7 changes: 5 additions & 2 deletions examples/flask_provider/run_pytest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ trap teardown EXIT
# Wait a little in case Flask isn't quite ready
sleep 1

# Now run the tests
pytest tests --run-broker True --publish-pact 1
if [ "$RUN_BROKER" = '0' ]; then
pytest tests --publish-pact 1
else
pytest tests --run-broker True --publish-pact 1
fi
16 changes: 11 additions & 5 deletions examples/flask_provider/tests/provider/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from collections import OrderedDict
import os

import pytest

Expand All @@ -12,10 +13,15 @@

# For the purposes of this example, the broker is started up as a fixture defined
# in conftest.py. For normal usage this would be self-hosted or using PactFlow.
PACT_BROKER_URL = "http://localhost"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"

use_pactflow = int(os.getenv('USE_HOSTED_PACT_BROKER', '0'))
if use_pactflow == 1:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "https://test.pactflow.io")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "dXfltyFMgNOFZAxr8io9wJ37iUpY42M")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")
else:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "http://localhost")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "pactbroker")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "pactbroker")
# For the purposes of this example, the Flask provider will be started up as part
# of run_pytest.sh when running the tests. Alternatives could be, for example
# running a Docker container with a database of test data configured.
Expand Down Expand Up @@ -92,7 +98,7 @@ def test_user_service_provider_against_pact_url(broker_opts):
verifier = Verifier(provider="UserService", provider_base_url=PROVIDER_URL)

success, _ = verifier.verify_pacts(
"http://localhost/pacts/provider/UserService/consumer/UserServiceClient/latest",
f"{PACT_BROKER_URL}/pacts/provider/UserService/consumer/UserServiceClient/latest",
**broker_opts,
provider_states_setup_url="{}/_pact/provider_states".format(PROVIDER_URL),
)
Expand Down
7 changes: 5 additions & 2 deletions examples/message/run_pytest.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash
set -o pipefail

pytest --run-broker True --publish-pact 2

if [ "$RUN_BROKER" = '0' ]; then
pytest tests --publish-pact 2
else
pytest tests --run-broker True --publish-pact 2
fi
# publish to broker assuming broker is active
# pytest tests/consumer/test_message_consumer.py::test_publish_to_broker --publish-pact 2
13 changes: 10 additions & 3 deletions examples/message/tests/consumer/test_message_consumer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""pact test for a message consumer"""

import logging
import os
import pytest
import time

Expand All @@ -15,9 +16,15 @@
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

PACT_BROKER_URL = "http://localhost"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"
use_pactflow = int(os.getenv('USE_HOSTED_PACT_BROKER', '0'))
if use_pactflow == 1:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "https://test.pactflow.io")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "dXfltyFMgNOFZAxr8io9wJ37iUpY42M")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")
else:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "http://localhost")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "pactbroker")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "pactbroker")
PACT_DIR = "pacts"

CONSUMER_NAME = "DetectContentLambda"
Expand Down
33 changes: 20 additions & 13 deletions examples/message/tests/provider/test_message_provider.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from collections import OrderedDict
import os
import pytest
from pact import MessageProvider

PACT_BROKER_URL = "http://localhost"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"
use_pactflow = int(os.getenv('USE_HOSTED_PACT_BROKER', '0'))
if use_pactflow == 1:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "https://test.pactflow.io")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "dXfltyFMgNOFZAxr8io9wJ37iUpY42M")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")
else:
PACT_BROKER_URL = os.getenv("PACT_BROKER_URL", "http://localhost")
PACT_BROKER_USERNAME = os.getenv("PACT_BROKER_USERNAME", "pactbroker")
PACT_BROKER_PASSWORD = os.getenv("PACT_BROKER_PASSWORD", "pactbroker")
PACT_DIR = "pacts"


Expand Down Expand Up @@ -78,7 +85,7 @@ def test_verify_from_pact_url(default_opts):

with provider:
provider.verify(
"http://localhost/pacts/provider/ContentProvider/consumer/DetectContentLambda/latest",
f"{PACT_BROKER_URL}/pacts/provider/ContentProvider/consumer/DetectContentLambda/latest",
**default_opts
)

Expand All @@ -95,12 +102,12 @@ def test_verify_from_broker(default_opts):

with provider:
provider.verify_with_broker(broker_url=PACT_BROKER_URL,
**default_opts,
enable_pending=True,
include_wip_pacts_since='2018-01-01',
consumer_version_selectors=[
OrderedDict([("mainBranch", True)]),
OrderedDict([("deployedOrReleased", True)]
),
],
)
**default_opts,
enable_pending=True,
include_wip_pacts_since='2018-01-01',
consumer_version_selectors=[
OrderedDict([("mainBranch", True)]),
OrderedDict([("deployedOrReleased", True)]
),
],
)
2 changes: 1 addition & 1 deletion examples/v3/consumer/run_pytest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -o pipefail

if [ "$RUN_BROKER" = '0' ]; then
pytest tests --publish-pact 1 -rP
pytest tests --publish-pact 1
else
pytest tests --run-broker True --publish-pact 1
fi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"consumer": {
"name": "DetectContentLambda"
"name": "DetectContentLambdaV3"
},
"provider": {
"name": "ContentProvider"
"name": "ContentProviderV3"
},
"messages": [
{
Expand Down
10 changes: 5 additions & 5 deletions examples/v3/message/tests/consumer/test_message_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from os import remove
from os.path import isfile

from pact import MessageConsumer, Provider
from pact import MessageConsumerV3, Provider
from src.message_handler import MessageHandler, CustomError

log = logging.getLogger(__name__)
Expand All @@ -26,8 +26,8 @@

PACT_DIR = "pacts"

CONSUMER_NAME = "DetectContentLambda"
PROVIDER_NAME = "ContentProvider"
CONSUMER_NAME = "DetectContentLambdaV3"
PROVIDER_NAME = "ContentProviderV3"
PACT_FILE = (f"{PACT_DIR}/{CONSUMER_NAME.lower().replace(' ', '_')}-"
+ f"{PROVIDER_NAME.lower().replace(' ', '_')}.json")

Expand All @@ -37,7 +37,7 @@ def pact(request):
version = request.config.getoption("--publish-pact")
publish = True if version else False

pact = MessageConsumer(CONSUMER_NAME, version=version).has_pact_with(
pact = MessageConsumerV3(CONSUMER_NAME, version=version).has_pact_with(
Provider(PROVIDER_NAME),
publish_to_broker=publish, broker_base_url=PACT_BROKER_URL,
broker_username=PACT_BROKER_USERNAME, broker_password=PACT_BROKER_PASSWORD, pact_dir=PACT_DIR)
Expand All @@ -48,7 +48,7 @@ def pact(request):
@pytest.fixture(scope="session")
def pact_no_publish(request):
version = request.config.getoption("--publish-pact")
pact = MessageConsumer(CONSUMER_NAME, version=version).has_pact_with(
pact = MessageConsumerV3(CONSUMER_NAME, version=version).has_pact_with(
Provider(PROVIDER_NAME),
publish_to_broker=False, broker_base_url=PACT_BROKER_URL,
broker_username=PACT_BROKER_USERNAME, broker_password=PACT_BROKER_PASSWORD, pact_dir=PACT_DIR)
Expand Down
18 changes: 9 additions & 9 deletions examples/v3/message/tests/provider/test_message_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def test_verify_success():
'A document created successfully': document_created_handler,
'A document deleted successfully': document_deleted_handler
},
provider='ContentProvider',
consumer='DetectContentLambda',
provider='ContentProviderV3',
consumer='DetectContentLambdaV3',
pact_dir='pacts'

)
Expand All @@ -63,8 +63,8 @@ def test_verify_failure_when_a_handler_missing():
message_providers={
'A document created successfully': document_created_handler,
},
provider='ContentProvider',
consumer='DetectContentLambda',
provider='ContentProviderV3',
consumer='DetectContentLambdaV3',
pact_dir='pacts'

)
Expand All @@ -79,13 +79,13 @@ def test_verify_from_pact_url(default_opts):
'A document created successfully': document_created_handler,
'A document deleted successfully': document_deleted_handler
},
provider='ContentProvider',
consumer='DetectContentLambda',
provider='ContentProviderV3',
consumer='DetectContentLambdaV3',
)

with provider:
success, logs = provider.verify(
"http://localhost/pacts/provider/ContentProvider/consumer/DetectContentLambda/latest",
f"{PACT_BROKER_URL}/pacts/provider/ContentProviderV3/consumer/DetectContentLambdaV3/latest",
**default_opts
)
assert success == 0
Expand All @@ -96,8 +96,8 @@ def test_verify_from_broker(default_opts):
'A document created successfully': document_created_handler,
'A document deleted successfully': document_deleted_handler
},
provider='ContentProvider',
consumer='DetectContentLambda',
provider='ContentProviderV3',
consumer='DetectContentLambdaV3',
)

with provider:
Expand Down
Loading

0 comments on commit 41e42ef

Please sign in to comment.