Worker unit tests

This commit is contained in:
Andrew Melton 2013-01-25 18:17:18 -05:00
parent 9117fd408c
commit b788ebafa2
5 changed files with 39 additions and 1 deletions

BIN
.coverage

Binary file not shown.

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
*.pyc
local_settings.py
.coverage
worker.log

View File

@ -1,2 +1,2 @@
#!/bin/bash
nosetests tests --exclude-dir=stacktach --with-coverage --cover-package=stacktach
nosetests tests --exclude-dir=stacktach --with-coverage --cover-package=stacktach,worker

36
tests/unit/test_worker.py Normal file
View File

@ -0,0 +1,36 @@
import unittest
import kombu
import kombu.entity
import mox
import worker.worker as worker
class NovaConsumerTestCase(unittest.TestCase):
def setUp(self):
self.mox = mox.Mox()
def test_get_consumer(self):
created_queues = None
created_callback = None
created_consumers = []
def Consumer(queues=None, callbacks=None):
created_queues = queues
created_callback = callbacks
consumer = self.mox.CreateMockAnything()
created_consumers.append(consumer)
return consumer
self.mox.StubOutClassWithMocks(kombu.entity, 'Exchange')
self.mox.StubOutClassWithMocks(kombu, 'Queue')
kombu.entity.Exchange('nova', type='topic', exclusive=False,
durable=True, auto_delete=False)
kombu.Queue('monitor.info', kombu.entity.Exchange, auto_delete=False,
durable=True, exclusive=False, routing_key='monitor.info')
kombu.Queue('monitor.error', kombu.entity.Exchange, auto_delete=False,
durable=True, exclusive=False, routing_key='monitor.error')
consumer = worker.NovaConsumer('test', None, None, True)
self.mox.ReplayAll()
consumers = consumer.get_consumers(Consumer, None)
self.assertEqual(len(consumers), len(created_consumers))
self.assertEqual(consumers[0], created_consumers[0])
self.mox.VerifyAll()

0
worker/__init__.py Normal file
View File