Skip to content

Commit f89b9da

Browse files
author
Dana Powers
committed
Mock client.ensure_topic_exists in test_producer_sync_fail_on_error
1 parent 178a1dc commit f89b9da

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

test/test_producer.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,20 @@ def test_producer_async_queue_overfilled(self, mock):
9797
def test_producer_sync_fail_on_error(self):
9898
error = FailedPayloadsError('failure')
9999
with patch.object(KafkaClient, 'load_metadata_for_topics'):
100-
with patch.object(KafkaClient, 'get_partition_ids_for_topic', return_value=[0, 1]):
101-
with patch.object(KafkaClient, '_send_broker_aware_request', return_value = [error]):
100+
with patch.object(KafkaClient, 'ensure_topic_exists'):
101+
with patch.object(KafkaClient, 'get_partition_ids_for_topic', return_value=[0, 1]):
102+
with patch.object(KafkaClient, '_send_broker_aware_request', return_value = [error]):
102103

103-
client = KafkaClient(MagicMock())
104-
producer = SimpleProducer(client, async=False, sync_fail_on_error=False)
104+
client = KafkaClient(MagicMock())
105+
producer = SimpleProducer(client, async=False, sync_fail_on_error=False)
105106

106-
# This should not raise
107-
(response,) = producer.send_messages('foobar', b'test message')
108-
self.assertEqual(response, error)
107+
# This should not raise
108+
(response,) = producer.send_messages('foobar', b'test message')
109+
self.assertEqual(response, error)
109110

110-
producer = SimpleProducer(client, async=False, sync_fail_on_error=True)
111-
with self.assertRaises(FailedPayloadsError):
112-
producer.send_messages('foobar', b'test message')
111+
producer = SimpleProducer(client, async=False, sync_fail_on_error=True)
112+
with self.assertRaises(FailedPayloadsError):
113+
producer.send_messages('foobar', b'test message')
113114

114115
def test_cleanup_is_not_called_on_stopped_producer(self):
115116
producer = Producer(MagicMock(), async=True)

0 commit comments

Comments
 (0)