Skip to content

Commit

Permalink
Merge pull request dpkp#1 from wizzat/pr109
Browse files Browse the repository at this point in the history
Fix py26 compatibility issue, add mock to tox
  • Loading branch information
mrtheb committed Mar 20, 2014
2 parents 19646b1 + 017f484 commit 51246fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 15 additions & 17 deletions test/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,18 +465,17 @@ def mock_get_conn(host, port):
return mocked_conns[(host, port)]

# patch to avoid making requests before we want it
with patch.object(KafkaClient, 'load_metadata_for_topics'), \
patch.object(KafkaClient, '_get_conn', side_effect=mock_get_conn):

client = KafkaClient(hosts=['kafka01:9092', 'kafka02:9092'])
with patch.object(KafkaClient, 'load_metadata_for_topics'):
with patch.object(KafkaClient, '_get_conn', side_effect=mock_get_conn):
client = KafkaClient(hosts=['kafka01:9092', 'kafka02:9092'])

self.assertRaises(
KafkaUnavailableError,
client._send_broker_unaware_request,
1, 'fake request')
self.assertRaises(
KafkaUnavailableError,
client._send_broker_unaware_request,
1, 'fake request')

for key, conn in mocked_conns.iteritems():
conn.send.assert_called_with(1, 'fake request')
for key, conn in mocked_conns.iteritems():
conn.send.assert_called_with(1, 'fake request')

def test_send_broker_unaware_request(self):
'Tests that call works when at least one of the host is available'
Expand All @@ -495,15 +494,14 @@ def mock_get_conn(host, port):
return mocked_conns[(host, port)]

# patch to avoid making requests before we want it
with patch.object(KafkaClient, 'load_metadata_for_topics'), \
patch.object(KafkaClient, '_get_conn', side_effect=mock_get_conn):

client = KafkaClient(hosts='kafka01:9092,kafka02:9092')
with patch.object(KafkaClient, 'load_metadata_for_topics'):
with patch.object(KafkaClient, '_get_conn', side_effect=mock_get_conn):
client = KafkaClient(hosts='kafka01:9092,kafka02:9092')

resp = client._send_broker_unaware_request(1, 'fake request')
resp = client._send_broker_unaware_request(1, 'fake request')

self.assertEqual('valid response', resp)
mocked_conns[('kafka02', 9092)].recv.assert_called_with(1)
self.assertEqual('valid response', resp)
mocked_conns[('kafka02', 9092)].recv.assert_called_with(1)

@patch('kafka.client.KafkaConnection')
@patch('kafka.client.KafkaProtocol')
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[tox]
envlist = py26, py27
[testenv]
deps = pytest
deps =
pytest
mock
commands = py.test --basetemp={envtmpdir} []
setenv =
PROJECT_ROOT = {toxinidir}
Expand Down

0 comments on commit 51246fb

Please sign in to comment.