Add test.

This commit is contained in:
Vincent Driessen 2012-07-18 14:03:28 +02:00
parent 84988bdf94
commit 3a8f30a53e
2 changed files with 19 additions and 1 deletions

View File

@ -58,6 +58,15 @@ class TestJob(RQTestCase):
self.assertEquals(job.instance, c)
self.assertEquals(job.args, (3, 4))
def test_create_job_from_string_function(self):
"""Creation of jobs using string specifier."""
job = Job.create('tests.fixtures.say_hello', 'World')
# Job data is set
self.assertEquals(job.func, say_hello)
self.assertIsNone(job.instance)
self.assertEquals(job.args, ('World',))
def test_save(self): # noqa
"""Storing jobs."""
job = Job.create(some_calculation, 3, 4, z=2)
@ -176,7 +185,7 @@ class TestJob(RQTestCase):
job.foo = 'bar'
job.save()
self.assertEqual(self.testconn.hget(job.key, 'foo'), 'bar')
job2 = Job.fetch(job.id)
job2.refresh()
self.assertEqual(job2.foo, 'bar')

View File

@ -25,6 +25,15 @@ class TestWorker(RQTestCase):
self.assertEquals(w.work(burst=True), True,
'Expected at least some work done.')
def test_work_via_string_argument(self):
"""Worker processes work fed via string arguments."""
q = Queue('foo')
w = Worker([q])
result = q.enqueue('tests.fixtures.say_hello', name='Frank')
self.assertEquals(w.work(burst=True), True,
'Expected at least some work done.')
self.assertEquals(result.return_value, 'Hi there, Frank!')
def test_work_is_unreadable(self):
"""Unreadable jobs are put on the failed queue."""
q = Queue()