From 0e4112da7a6a18cccbf1069306a6704d407b9b24 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Tue, 22 Sep 2015 18:17:02 +0700 Subject: [PATCH] Modified patch_connection to allow Redis connection to be easily mocked. --- rq/compat/connections.py | 5 ++++- tests/test_job.py | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/rq/compat/connections.py b/rq/compat/connections.py index ac22af3..221e653 100644 --- a/rq/compat/connections.py +++ b/rq/compat/connections.py @@ -18,12 +18,14 @@ def fix_return_type(func): return _inner +PATCHED_METHODS = ['_setex', '_lrem', '_zadd', '_pipeline', '_ttl'] + + def patch_connection(connection): if not isinstance(connection, StrictRedis): raise ValueError('A StrictRedis or Redis connection is required.') # Don't patch already patches objects - PATCHED_METHODS = ['_setex', '_lrem', '_zadd', '_pipeline', '_ttl'] if all([hasattr(connection, attr) for attr in PATCHED_METHODS]): return connection @@ -35,6 +37,7 @@ def patch_connection(connection): connection._ttl = fix_return_type(partial(StrictRedis.ttl, connection)) if hasattr(connection, 'pttl'): connection._pttl = fix_return_type(partial(StrictRedis.pttl, connection)) + elif isinstance(connection, StrictRedis): connection._setex = connection.setex connection._lrem = connection.lrem diff --git a/tests/test_job.py b/tests/test_job.py index 6971d7b..4a57e6e 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -5,7 +5,7 @@ from __future__ import (absolute_import, division, print_function, from datetime import datetime import time -from tests import RQTestCase +from tests import fixtures, RQTestCase from tests.helpers import strip_microseconds from rq.compat import PY2, as_text @@ -16,8 +16,6 @@ from rq.registry import DeferredJobRegistry from rq.utils import utcformat from rq.worker import Worker -from . import fixtures - try: from cPickle import loads, dumps except ImportError: