-
-
Notifications
You must be signed in to change notification settings - Fork 430
/
Copy pathtest_connection_factory.py
60 lines (51 loc) · 1.72 KB
/
test_connection_factory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pytest
from django.core.exceptions import ImproperlyConfigured
from django_redis import pool
def test_connection_factory_redefine_from_opts():
cf = pool.get_connection_factory(
path="django_redis.pool.ConnectionFactory",
options={
"CONNECTION_FACTORY": "django_redis.pool.SentinelConnectionFactory",
"SENTINELS": [("127.0.0.1", "26739")],
},
)
assert cf.__class__.__name__ == "SentinelConnectionFactory"
@pytest.mark.parametrize(
"conn_factory,expected",
[
("django_redis.pool.SentinelConnectionFactory", pool.SentinelConnectionFactory),
("django_redis.pool.ConnectionFactory", pool.ConnectionFactory),
],
)
def test_connection_factory_opts(conn_factory: str, expected):
cf = pool.get_connection_factory(
path=None,
options={
"CONNECTION_FACTORY": conn_factory,
"SENTINELS": [("127.0.0.1", "26739")],
},
)
assert isinstance(cf, expected)
@pytest.mark.parametrize(
"conn_factory,expected",
[
("django_redis.pool.SentinelConnectionFactory", pool.SentinelConnectionFactory),
("django_redis.pool.ConnectionFactory", pool.ConnectionFactory),
],
)
def test_connection_factory_path(conn_factory: str, expected):
cf = pool.get_connection_factory(
path=conn_factory,
options={
"SENTINELS": [("127.0.0.1", "26739")],
},
)
assert isinstance(cf, expected)
def test_connection_factory_no_sentinels():
with pytest.raises(ImproperlyConfigured):
pool.get_connection_factory(
path=None,
options={
"CONNECTION_FACTORY": "django_redis.pool.SentinelConnectionFactory",
},
)