From 2b6101d110765eeea5e2fc8997c46743e8c7f534 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 21 Mar 2012 13:18:01 +0100 Subject: [PATCH] Move job from Worker to Job test suite. --- tests/test_job.py | 18 +++++++++++++++++- tests/test_worker.py | 18 ------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/tests/test_job.py b/tests/test_job.py index 7dc2c22..59ba922 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -1,7 +1,7 @@ import times from datetime import datetime from tests import RQTestCase -from tests.fixtures import some_calculation +from tests.fixtures import some_calculation, say_hello from tests.helpers import strip_milliseconds from cPickle import loads from rq import Job @@ -137,3 +137,19 @@ class TestJob(RQTestCase): self.testconn.hset(job.key, 'data', 'this is no pickle string') with self.assertRaises(UnpickleError): job.refresh() + + def test_job_is_unimportable(self): + """Jobs that cannot be imported throw exception on access.""" + job = Job.create(say_hello, 'Lionel') + job.save() + + # Now slightly modify the job to make it unimportable (this is + # equivalent to a worker not having the most up-to-date source code + # and unable to import the function) + data = self.testconn.hget(job.key, 'data') + unimportable_data = data.replace('say_hello', 'shut_up') + self.testconn.hset(job.key, 'data', unimportable_data) + + job.refresh() + with self.assertRaises(AttributeError): + job.func # accessing the func property should fail diff --git a/tests/test_worker.py b/tests/test_worker.py index 3eac3f4..8a46ae5 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -54,24 +54,6 @@ class TestWorker(RQTestCase): self.assertEquals(q.count, 0) self.assertEquals(failed_q.count, 1) - def test_work_is_unimportable(self): - """Jobs that cannot be imported are put on the failed queue.""" - q = Queue() - - job = q.enqueue(say_hello, 'Lionel') - job.save() - - # Now slightly modify the job to make it unimportable (this is - # equivalent to a worker not having the most up-to-date source code - # and unable to import the function) - data = self.testconn.hget(job.key, 'data') - unimportable_data = data.replace('say_hello', 'shut_up') - self.testconn.hset(job.key, 'data', unimportable_data) - - job.refresh() - with self.assertRaises((ImportError, AttributeError)): - job.func # accessing the func property should fail - def test_work_fails(self): """Failing jobs are put on the failed queue.""" q = Queue()