mirror of https://github.com/rq/rq.git
Add test for putting work on queues.
This commit is contained in:
parent
8dfdd452ef
commit
1b8da4a861
|
@ -19,5 +19,9 @@ class Queue(object):
|
|||
def empty(self):
|
||||
return conn.llen(self.key) == 0
|
||||
|
||||
@property
|
||||
def messages(self):
|
||||
return conn.lrange(self.key, 0, -1)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import unittest
|
||||
from pickle import loads
|
||||
from blinker import signal
|
||||
from redis import Redis
|
||||
from rq import conn, Queue
|
||||
from rq import conn, Queue, job
|
||||
|
||||
@job('my-queue')
|
||||
def testjob():
|
||||
return 'hi there'
|
||||
|
||||
|
||||
class RQTestCase(unittest.TestCase):
|
||||
|
@ -32,6 +37,16 @@ class RQTestCase(unittest.TestCase):
|
|||
super(RQTestCase, self).tearDown()
|
||||
|
||||
|
||||
def assertQueueContains(self, queue, that_func):
|
||||
# Do a queue scan (this is O(n), but we're in a test, so hey)
|
||||
for message in queue.messages:
|
||||
f, _, args, kwargs = loads(message)
|
||||
if f == that_func:
|
||||
return
|
||||
self.fail('Queue %s does not contain message for function %s' %
|
||||
(queue.key, that_func))
|
||||
|
||||
|
||||
class TestQueue(RQTestCase):
|
||||
def test_create_queue(self):
|
||||
"""Creating queues."""
|
||||
|
@ -46,6 +61,15 @@ class TestQueue(RQTestCase):
|
|||
conn.rpush('rq:my-queue', 'some val')
|
||||
self.assertEquals(q.empty, False)
|
||||
|
||||
def test_put_work_on_queue(self):
|
||||
"""Putting work on queues."""
|
||||
q = Queue('my-queue')
|
||||
self.assertEquals(q.empty, True)
|
||||
|
||||
testjob.delay()
|
||||
self.assertEquals(q.empty, False)
|
||||
self.assertQueueContains(q, testjob)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue