Skip to content

Commit 94b920c

Browse files
committed
Merge pull request #103 from singingwolfboy/from_url
Add support for `from_url` constructors
2 parents 5f106f2 + 0d21068 commit 94b920c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mockredis/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def __init__(self,
5858
# Dictionary from script to sha ''Script''
5959
self.shas = dict()
6060

61+
@classmethod
62+
def from_url(cls, url, db=None, **kwargs):
63+
return cls(**kwargs)
64+
6165
# Connection Functions #
6266

6367
def echo(self, msg):
@@ -1509,6 +1513,8 @@ def mock_redis_client(**kwargs):
15091513
"""
15101514
return MockRedis()
15111515

1516+
mock_redis_client.from_url = mock_redis_client
1517+
15121518

15131519
def mock_strict_redis_client(**kwargs):
15141520
"""
@@ -1517,3 +1523,5 @@ def mock_strict_redis_client(**kwargs):
15171523
instead of a StrictRedis object.
15181524
"""
15191525
return MockRedis(strict=True)
1526+
1527+
mock_strict_redis_client.from_url = mock_strict_redis_client

mockredis/tests/test_factories.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,22 @@ def test_mock_redis_client():
1313
ok_(not mock_redis_client(host="localhost", port=6379).strict)
1414

1515

16+
def test_mock_redis_client_from_url():
17+
"""
18+
Test that we can pass kwargs to the Redis from_url mock/patch target.
19+
"""
20+
ok_(not mock_redis_client.from_url(host="localhost", port=6379).strict)
21+
22+
1623
def test_mock_strict_redis_client():
1724
"""
1825
Test that we can pass kwargs to the StrictRedis mock/patch target.
1926
"""
2027
ok_(mock_strict_redis_client(host="localhost", port=6379).strict)
28+
29+
30+
def test_mock_strict_redis_client_from_url():
31+
"""
32+
Test that we can pass kwargs to the StrictRedis from_url mock/patch target.
33+
"""
34+
ok_(mock_strict_redis_client.from_url(host="localhost", port=6379).strict)

0 commit comments

Comments
 (0)