diff options
author | Dana Powers <dana.powers@rd.io> | 2014-08-26 14:12:11 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@rd.io> | 2014-08-26 16:59:46 -0700 |
commit | be38e0e9a3c3bbd0462fdc2333b19e360567ccd4 (patch) | |
tree | 9c79be2a8b4689f2e6b2bda02dad3f5edb3b62af /test/test_producer.py | |
parent | a28120aa8bedc24540cd6269435b71c272b55386 (diff) | |
download | kafka-python-be38e0e9a3c3bbd0462fdc2333b19e360567ccd4.tar.gz |
Add producer unit test (test/test_producer.py); check supported types in send_messages
Diffstat (limited to 'test/test_producer.py')
-rw-r--r-- | test/test_producer.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_producer.py b/test/test_producer.py new file mode 100644 index 0000000..a84e20f --- /dev/null +++ b/test/test_producer.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +import logging +import os +import random +import struct +import unittest2 + +from mock import MagicMock, patch + +from kafka import KafkaClient +from kafka.producer import Producer + +class TestKafkaProducer(unittest2.TestCase): + def test_producer_message_types(self): + + producer = Producer(MagicMock()) + topic = "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 = ('a string!',) + for m in good_data_types: + # This should not raise an exception + producer.send_messages(topic, partition, m) + |