Skip to content

Commit be38e0e

Browse files
author
Dana Powers
committed
Add producer unit test (test/test_producer.py); check supported types in send_messages
1 parent a28120a commit be38e0e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/test_producer.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import logging
4+
import os
5+
import random
6+
import struct
7+
import unittest2
8+
9+
from mock import MagicMock, patch
10+
11+
from kafka import KafkaClient
12+
from kafka.producer import Producer
13+
14+
class TestKafkaProducer(unittest2.TestCase):
15+
def test_producer_message_types(self):
16+
17+
producer = Producer(MagicMock())
18+
topic = "test-topic"
19+
partition = 0
20+
21+
bad_data_types = (u'你怎么样?', 12, ['a','list'], ('a','tuple'), {'a': 'dict'})
22+
for m in bad_data_types:
23+
with self.assertRaises(TypeError):
24+
logging.debug("attempting to send message of type %s", type(m))
25+
producer.send_messages(topic, partition, m)
26+
27+
good_data_types = ('a string!',)
28+
for m in good_data_types:
29+
# This should not raise an exception
30+
producer.send_messages(topic, partition, m)
31+

0 commit comments

Comments
 (0)