From 01f9a98ad96988cbb9aa6c4f97abbe885799360a Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Sat, 21 Sep 2013 13:19:12 +0200 Subject: [PATCH] Make test more readable by using constants. --- tests/test_queue.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/test_queue.py b/tests/test_queue.py index cb3193d..081af75 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -307,24 +307,36 @@ class TestQueue(RQTestCase): self.assertEqual(q.job_ids, [job_1.id, job_2.id]) self.assertFalse(self.testconn.exists(parent_job.waitlist_key)) - def test_enqueue_job_with_dependency(self, timeout=None): - """Jobs are enqueued only when their dependencies are finished""" + def test_enqueue_job_with_dependency(self): + """Jobs are enqueued only when their dependencies are finished.""" # Job with unfinished dependency is not immediately enqueued parent_job = Job.create(func=say_hello) q = Queue() - job = q.enqueue_call(say_hello, after=parent_job, timeout=timeout) + q.enqueue_call(say_hello, after=parent_job) self.assertEqual(q.job_ids, []) - self.assertEqual(job.timeout, timeout) # Jobs dependent on finished jobs are immediately enqueued parent_job.status = 'finished' parent_job.save() - job = q.enqueue_call(say_hello, after=parent_job, timeout=timeout) + job = q.enqueue_call(say_hello, after=parent_job) self.assertEqual(q.job_ids, [job.id]) - self.assertEqual(job.timeout, Queue.DEFAULT_TIMEOUT if timeout is None else timeout) + self.assertEqual(job.timeout, Queue.DEFAULT_TIMEOUT) def test_enqueue_job_with_dependency_and_timeout(self): - self.test_enqueue_job_with_dependency(123) + """Jobs still know their specified timeout after being scheduled as a dependency.""" + # Job with unfinished dependency is not immediately enqueued + parent_job = Job.create(func=say_hello) + q = Queue() + job = q.enqueue_call(say_hello, after=parent_job, timeout=123) + self.assertEqual(q.job_ids, []) + self.assertEqual(job.timeout, 123) + + # Jobs dependent on finished jobs are immediately enqueued + parent_job.status = 'finished' + parent_job.save() + job = q.enqueue_call(say_hello, after=parent_job, timeout=123) + self.assertEqual(q.job_ids, [job.id]) + self.assertEqual(job.timeout, 123) class TestFailedQueue(RQTestCase):