Skip to content

Commit

Permalink
docs: some review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottmurray committed Apr 24, 2021
1 parent 9de486d commit b00aa0e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions examples/kafka/src/kafka_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}'
Expand Down
2 changes: 1 addition & 1 deletion examples/kafka/src/kafka_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
10 changes: 5 additions & 5 deletions examples/kafka/tests/test_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_assert_verify_message(pact):
.with_metadata({
'Content-Type': 'application/json'
})
.verify(send_dog_event)
.verify(receive_dog_event)
)


Expand All @@ -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):
Expand All @@ -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:
Expand All @@ -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'

0 comments on commit b00aa0e

Please sign in to comment.