Python 3 Support Conflicts: kafka/producer.py test/test_client.py test/test_client_integration.py test/test_codec.py test/test_consumer.py test/test_consumer_integration.py test/test_failover_integration.py test/test_producer.py test/test_producer_integration.py test/test_protocol.py test/test_util.py
28 lines
808 B
Python
28 lines
808 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
import logging
|
|
|
|
from mock import MagicMock
|
|
from . import unittest
|
|
|
|
from kafka.producer import Producer
|
|
|
|
class TestKafkaProducer(unittest.TestCase):
|
|
def test_producer_message_types(self):
|
|
|
|
producer = Producer(MagicMock())
|
|
topic = b"test-topic"
|
|
partition = 0
|
|
|
|
bad_data_types = (u'你怎么样?', 12, ['a', 'list'], ('a', 'tuple'), {'a': 'dict'})
|
|
for m in bad_data_types:
|
|
with self.assertRaises(TypeError):
|
|
logging.debug("attempting to send message of type %s", type(m))
|
|
producer.send_messages(topic, partition, m)
|
|
|
|
good_data_types = (b'a string!',)
|
|
for m in good_data_types:
|
|
# This should not raise an exception
|
|
producer.send_messages(topic, partition, m)
|
|
|