Merge branch 'SanyerMyasoedov-master'

This commit is contained in:
Vincent Driessen 2014-05-06 15:53:19 +02:00
commit fba11aac91
4 changed files with 28 additions and 4 deletions

1
dev-requirements.txt Normal file
View File

@ -0,0 +1 @@
mock

View File

@ -6,7 +6,6 @@ from functools import wraps
from rq.compat import string_types
from .connections import resolve_connection
from .queue import Queue
from .worker import DEFAULT_RESULT_TTL
@ -26,7 +25,7 @@ class job(object):
simple_add.delay(1, 2) # Puts simple_add function into queue
"""
self.queue = queue
self.connection = resolve_connection(connection)
self.connection = connection
self.timeout = timeout
self.result_ttl = result_ttl

View File

@ -2,11 +2,12 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from redis import StrictRedis
from rq.decorators import job
from rq.job import Job
from rq.worker import DEFAULT_RESULT_TTL
from tests import RQTestCase
from tests import mock, RQTestCase
from tests.fixtures import decorated_job
@ -75,3 +76,23 @@ class TestDecorator(RQTestCase):
self.assertEqual(bar_job.dependency, foo_job)
self.assertEqual(bar_job._dependency_id, foo_job.id)
@mock.patch('rq.queue.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)

View File

@ -3,9 +3,12 @@ envlist=py26,py27,py33,py34,pypy
[testenv]
commands=py.test []
deps=pytest
deps=
pytest
mock
[testenv:py26]
deps=
pytest
unittest2
mock