From f98cf87edd0c7c5866495f04d8ad57586e58b173 Mon Sep 17 00:00:00 2001 From: B3nnyL <13126965+B3nnyL@users.noreply.github.com> Date: Tue, 23 Aug 2022 10:50:24 +1000 Subject: [PATCH 1/4] chore: test message only --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 160b84665..3ce8eef4d 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ messaging: .PHONY: examples -examples: consumer flask fastapi messaging +examples: messaging .PHONY: package From 8768808c0c6f06ab1ee4977ef4a5f7f8eae1a452 Mon Sep 17 00:00:00 2001 From: B3nnyL <13126965+B3nnyL@users.noreply.github.com> Date: Tue, 23 Aug 2022 11:48:28 +1000 Subject: [PATCH 2/4] chore: publish message consumer pact only once --- .../tests/consumer/test_message_consumer.py | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/message/tests/consumer/test_message_consumer.py b/examples/message/tests/consumer/test_message_consumer.py index d8376a4e6..7a4ff873f 100644 --- a/examples/message/tests/consumer/test_message_consumer.py +++ b/examples/message/tests/consumer/test_message_consumer.py @@ -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 @@ -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 = { @@ -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) @@ -81,7 +91,7 @@ def test_throw_exception_handler(pact): })) with pytest.raises(CustomError): - with pact: + with pact_no_publish: # handler needs "documentType" == "microsoft-word" MessageHandler(wrong_event) @@ -89,7 +99,7 @@ def test_throw_exception_handler(pact): assert isfile(f"{PACT_FILE}") == 0 -def test_put_file(pact): +def test_put_file(pact_no_publish): cleanup_json(PACT_FILE) expected_event = { @@ -99,7 +109,7 @@ 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) @@ -107,7 +117,7 @@ def test_put_file(pact): "Content-Type": "application/json" })) - with pact: + with pact_no_publish: MessageHandler(expected_event) progressive_delay(f"{PACT_FILE}") From 6c5db50205ef7671d3dfd8a7257edda75022f853 Mon Sep 17 00:00:00 2001 From: B3nnyL <13126965+B3nnyL@users.noreply.github.com> Date: Tue, 23 Aug 2022 11:48:58 +1000 Subject: [PATCH 3/4] Revert "chore: test message only" This reverts commit f98cf87edd0c7c5866495f04d8ad57586e58b173. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3ce8eef4d..160b84665 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ messaging: .PHONY: examples -examples: messaging +examples: consumer flask fastapi messaging .PHONY: package From 8be1458db71b091a61761131fee5dfc003b8fd2e Mon Sep 17 00:00:00 2001 From: B3nnyL <13126965+B3nnyL@users.noreply.github.com> Date: Tue, 23 Aug 2022 12:26:28 +1000 Subject: [PATCH 4/4] chore: remove clean file command --- examples/message/tests/consumer/test_message_consumer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/message/tests/consumer/test_message_consumer.py b/examples/message/tests/consumer/test_message_consumer.py index 7a4ff873f..3c7de4c1a 100644 --- a/examples/message/tests/consumer/test_message_consumer.py +++ b/examples/message/tests/consumer/test_message_consumer.py @@ -133,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",