|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
from tests import RQTestCase
|
|
|
|
|
from redis import StrictRedis
|
|
|
|
|
|
|
|
|
|
from tests import RQTestCase, mock
|
|
|
|
|
from tests.fixtures import decorated_job
|
|
|
|
|
|
|
|
|
|
from rq.decorators import job
|
|
|
|
@ -70,3 +72,23 @@ class TestDecorator(RQTestCase):
|
|
|
|
|
self.assertEqual(bar_job.dependency, foo_job)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(bar_job._dependency_id, foo_job.id)
|
|
|
|
|
|
|
|
|
|
@mock.patch('rq.decorators.resolve_connection')
|
|
|
|
|
def test_decorator_connection_laziness(self, resolve_connection):
|
|
|
|
|
"""Ensure that job decorator resolve connection in `lazy` way """
|
|
|
|
|
|
|
|
|
|
resolve_connection.return_value = StrictRedis()
|
|
|
|
|
|
|
|
|
|
@job(queue='queue_name')
|
|
|
|
|
def foo():
|
|
|
|
|
return 'do something'
|
|
|
|
|
|
|
|
|
|
self.assertEqual(resolve_connection.call_count, 0)
|
|
|
|
|
|
|
|
|
|
foo()
|
|
|
|
|
|
|
|
|
|
self.assertEqual(resolve_connection.call_count, 0)
|
|
|
|
|
|
|
|
|
|
foo.delay()
|
|
|
|
|
|
|
|
|
|
self.assertEqual(resolve_connection.call_count, 1)
|
|
|
|
|