Improve coverage of test_queues and fix bug

This commit is contained in:
Clint Byrum 2015-10-28 12:41:08 +09:00
parent 5d8c1b97a0
commit 34f6eec42c
2 changed files with 5 additions and 3 deletions

View File

@ -53,7 +53,7 @@ def collect():
for q in content:
if not isinstance(q, dict):
continue
if "name" not in q or "messages" not in q:
if "name" not in q:
continue
qname = q["name"]
if qname.startswith('reply_'):

View File

@ -19,6 +19,7 @@ test_collectors
Tests for `openstack_qa_tools.collectors`
"""
import json
import mock
from openstack_qa_tools.collectors import queues
@ -30,8 +31,9 @@ class TestOpenStackQaTols(base.TestCase):
@mock.patch('six.moves.http_client.HTTPConnection')
def test_queues(self, httplib_mock):
reader = mock.MagicMock(name='getresponse_reader')
reader.read.return_value = '[]'
rval = json.dumps([{'name': 'foo', 'message_stats': {'publish': 1}}])
reader.read.return_value = rval
conn = httplib_mock.return_value
conn.getresponse.return_value = reader
data = queues.collect()
self.assertEqual({}, data)
self.assertEqual({'foo_publish': 1}, data)