Added tests and updated requirements with mock lib.

main
msoedov 11 years ago
parent b4bccb2d31
commit dd994142b3

@ -1 +1,2 @@
redis
mock

@ -1,4 +1,5 @@
import logging
import mock
from rq.compat import is_python_version
if is_python_version((2, 7), (3, 2)):
import unittest

@ -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)

Loading…
Cancel
Save