mirror of https://github.com/peter4431/rq.git
Clarified responsibility of the Job class.
The Job itself has nothing to do with queueing and dequeueing, so the DequeueError wasn't appropriate here, either.main
parent
db5753b0d6
commit
0503eb2829
@ -1,5 +1,9 @@
|
||||
class NoQueueError(Exception):
|
||||
pass
|
||||
|
||||
class UnpickleError(Exception):
|
||||
pass
|
||||
|
||||
class DequeueError(Exception):
|
||||
pass
|
||||
|
||||
|
@ -1,11 +1,43 @@
|
||||
from tests import RQTestCase
|
||||
#from pickle import loads, dumps
|
||||
from pickle import dumps, loads
|
||||
from rq.job import Job
|
||||
#from rq import Queue, Worker
|
||||
#from rq.exceptions import DequeueError
|
||||
from rq.exceptions import UnpickleError
|
||||
|
||||
|
||||
def arbitrary_function(x, y, z=1):
|
||||
return x * y / z
|
||||
|
||||
|
||||
class TestJob(RQTestCase):
|
||||
def test_create_job(self):
|
||||
"""Creation of jobs."""
|
||||
pass
|
||||
job = Job(arbitrary_function, 3, 4, z=2)
|
||||
self.assertEquals(job.func, arbitrary_function)
|
||||
self.assertEquals(job.args, (3, 4))
|
||||
self.assertEquals(job.kwargs, {'z': 2})
|
||||
self.assertIsNone(job.origin)
|
||||
self.assertIsNone(job.timestamp)
|
||||
self.assertIsNone(job.rv_key)
|
||||
|
||||
def test_pickle_job(self):
|
||||
"""Pickling of jobs."""
|
||||
job = Job(arbitrary_function, 3, 4, z=2)
|
||||
job2 = loads(dumps(job))
|
||||
self.assertEquals(job.func, job2.func)
|
||||
self.assertEquals(job.args, job2.args)
|
||||
self.assertEquals(job.kwargs, job2.kwargs)
|
||||
|
||||
def test_unpickle_errors(self):
|
||||
"""Handling of unpickl'ing errors."""
|
||||
with self.assertRaises(UnpickleError):
|
||||
Job.unpickle('this is no pickle data')
|
||||
|
||||
with self.assertRaises(UnpickleError):
|
||||
Job.unpickle(13)
|
||||
|
||||
pickle_data = dumps(Job(arbitrary_function, 2, 3))
|
||||
corrupt_data = pickle_data.replace('arbitrary', 'b0rken')
|
||||
with self.assertRaises(UnpickleError):
|
||||
Job.unpickle(corrupt_data)
|
||||
|
||||
|
Loading…
Reference in New Issue