-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathtest_config.py
73 lines (51 loc) · 1.99 KB
/
test_config.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
61
62
63
64
65
66
67
68
69
70
71
72
73
from __future__ import annotations
from unittest.mock import MagicMock
import pytest
from flask import Flask
from redis import Redis
from flask_rq import RQ
def test_no_testing_yes_async() -> None:
"""Queue.is_async is True if app.testing is False."""
app = Flask(__name__)
rq = RQ(app)
with app.app_context():
assert rq.queue.is_async
def test_yes_testing_no_async() -> None:
"""Queue.is_async is False if app.testing is True."""
app = Flask(__name__)
app.testing = True
rq = RQ(app)
with app.app_context():
assert not rq.queue.is_async
def test_config_async() -> None:
"""Queue.is_async is set by config instead of app.testing."""
app = Flask(__name__)
app.testing = True
app.config["RQ_ASYNC"] = True
rq = RQ(app)
with app.app_context():
assert rq.queue.is_async
def test_default(app: Flask) -> None:
"""Default queue uses config instead of default values."""
app.config["RQ_CONNECTION"] = {"port": 24242}
rq = RQ(app)
with app.app_context():
assert rq.queue.connection.get_connection_kwargs()["port"] == 24242
@pytest.mark.usefixtures("app_ctx")
def test_connections(rq: RQ) -> None:
assert rq.queue.connection is not rq.queues["low"].connection
assert rq.queue.connection is not rq.queues["high"].connection
assert rq.queue.connection is rq.queues["plain"].connection
assert rq.queues["low"].connection is not rq.queues["high"].connection
assert rq.queues["low"].connection is rq.queues["share_low"].connection
def test_bad_forward_ref(app: Flask) -> None:
app.config["RQ_QUEUES"].append("bad")
app.config["RQ_QUEUE_CONNECTIONS"]["bad"] = "nothing"
with pytest.raises(RuntimeError, match=r'\'RQ_QUEUE_CONNECTIONS\["nothing"\]'):
RQ(app)
def test_connection_class(app: Flask) -> None:
conn_cls = MagicMock(spec=Redis)
app.config["RQ_CONNECTION_CLASS"] = conn_cls
RQ(app)
assert conn_cls.call_count == 2
assert conn_cls.from_url.call_count == 1