From b00aa0e66bdd7d816d627e70105f06506e178e8d Mon Sep 17 00:00:00 2001 From: Elliott Murray Date: Mon, 12 Apr 2021 08:43:45 +0100 Subject: [PATCH] docs: some review comments --- examples/kafka/src/kafka_consumer.py | 11 ++++++----- examples/kafka/src/kafka_producer.py | 2 +- examples/kafka/tests/test_consumer.py | 10 +++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/kafka/src/kafka_consumer.py b/examples/kafka/src/kafka_consumer.py index 8751d6b844..310cbaa1a2 100644 --- a/examples/kafka/src/kafka_consumer.py +++ b/examples/kafka/src/kafka_consumer.py @@ -36,12 +36,13 @@ def message_decoder(obj): raise CustomError('type unknown') -def send_dog_event_foo(foo, payload): - # ignoring foo here - return send_dog_event(payload) +def receive_dog_event_foo(foo, payload): + # ignoring foo here - a more complicated interface. An example of + # not using the pact interface and testing events + return receive_dog_event(payload) -def send_dog_event(payload): +def receive_dog_event(payload): dog = json.loads(payload, object_hook=message_decoder) print(dog) return dog @@ -56,7 +57,7 @@ def start_consumer(kafka_consumer, topic): if msg is None: continue elif not msg.error(): - send_dog_event(msg.value()) + receive_dog_event(msg.value()) elif msg.error().code() == KafkaError._PARTITION_EOF: print('End of partition reached {0}/{1}' diff --git a/examples/kafka/src/kafka_producer.py b/examples/kafka/src/kafka_producer.py index 4f27473b96..62a5fd9c7a 100644 --- a/examples/kafka/src/kafka_producer.py +++ b/examples/kafka/src/kafka_producer.py @@ -19,7 +19,7 @@ class Dog(): def __init__(self): i = random.randint(0, len(NAMES)-1) j = random.randint(0, len(BREEDS)-1) - self.__type__ = 'dog' + self.type = 'dog' self.name = NAMES[i] self.breed = BREEDS[j] diff --git a/examples/kafka/tests/test_consumer.py b/examples/kafka/tests/test_consumer.py index a022b91a28..4882051840 100644 --- a/examples/kafka/tests/test_consumer.py +++ b/examples/kafka/tests/test_consumer.py @@ -5,7 +5,7 @@ import json from pact import MessageConsumer, Provider -from src.kafka_consumer import send_dog_event, send_dog_event_foo, CustomError +from src.kafka_consumer import receive_dog_event, receive_dog_event_foo, CustomError log = logging.getLogger(__name__) logging.basicConfig(level=logging.INFO) @@ -45,7 +45,7 @@ def test_assert_verify_message(pact): .with_metadata({ 'Content-Type': 'application/json' }) - .verify(send_dog_event) + .verify(receive_dog_event) ) @@ -59,7 +59,7 @@ def test_throw_exception_handler(pact): .with_metadata({ 'Content-Type': 'application/json' }) - .verify(send_dog_event)) + .verify(receive_dog_event)) def test_assert_dog_returned(pact): @@ -71,7 +71,7 @@ def test_assert_dog_returned(pact): .with_metadata({ 'Content-Type': 'application/json' }) - .verify(send_dog_event) + .verify(receive_dog_event) ) with pact: @@ -92,6 +92,6 @@ def test_assert_calling_dog(pact): ) with pact: - dog = send_dog_event_foo({}, str(json.dumps(EXPECTED_DOG))) + dog = receive_dog_event_foo({}, str(json.dumps(EXPECTED_DOG))) assert dog.name == 'spot' assert dog.breed == 'poodle'