Skip to content
Merged
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
23 changes: 16 additions & 7 deletions examples/message/tests/consumer/test_message_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def pact(request):
yield pact


@pytest.fixture(scope="session")
def pact_no_publish(request):
version = request.config.getoption("--publish-pact")
pact = MessageConsumer(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)

yield pact

def cleanup_json(file):
"""
Remove existing json file before test if any
Expand All @@ -62,7 +72,7 @@ def progressive_delay(file, time_to_wait=10, second_interval=0.5, verbose=False)
break


def test_throw_exception_handler(pact):
def test_throw_exception_handler(pact_no_publish):
cleanup_json(PACT_FILE)

wrong_event = {
Expand All @@ -72,7 +82,7 @@ def test_throw_exception_handler(pact):
"documentType": "microsoft-excel"
}

(pact
(pact_no_publish
.given("Document unsupported type")
.expects_to_receive("Description")
.with_content(wrong_event)
Expand All @@ -81,15 +91,15 @@ def test_throw_exception_handler(pact):
}))

with pytest.raises(CustomError):
with pact:
with pact_no_publish:
# handler needs "documentType" == "microsoft-word"
MessageHandler(wrong_event)

progressive_delay(f"{PACT_FILE}")
assert isfile(f"{PACT_FILE}") == 0


def test_put_file(pact):
def test_put_file(pact_no_publish):
cleanup_json(PACT_FILE)

expected_event = {
Expand All @@ -99,15 +109,15 @@ def test_put_file(pact):
"documentType": "microsoft-word"
}

(pact
(pact_no_publish
.given("A document created successfully")
.expects_to_receive("Description")
.with_content(expected_event)
.with_metadata({
"Content-Type": "application/json"
}))

with pact:
with pact_no_publish:
MessageHandler(expected_event)

progressive_delay(f"{PACT_FILE}")
Expand All @@ -123,7 +133,6 @@ def test_publish_to_broker(pact):

`pytest tests/consumer/test_message_consumer.py::test_publish_pact_to_broker --publish-pact 2`
"""
cleanup_json(PACT_FILE)

expected_event = {
"event": "ObjectCreated:Delete",
Expand Down