-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathtest_config.py
More file actions
71 lines (44 loc) · 2 KB
/
Copy pathtest_config.py
File metadata and controls
71 lines (44 loc) · 2 KB
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
import json
def test_config(worker):
""" Test different config passing options. """
# Default config values
worker.start()
cfg = json.loads(
worker.send_task("tests.tasks.general.GetConfig", {}, block=True))
assert cfg["mongodb_jobs"] == "mongodb://127.0.0.1:27017/mrq"
assert cfg.get("additional_unexpected_config") is None
worker.stop()
# Values from config file
worker.start(flags="--config tests/fixtures/config2.py")
cfg = json.loads(
worker.send_task("tests.tasks.general.GetConfig", {}, block=True))
assert cfg["mongodb_jobs"] == "mongodb://127.0.0.1:27017/mrq?connectTimeoutMS=4242"
assert cfg["name"] == "testworker"
assert cfg.get("additional_unexpected_config") == "1"
worker.stop()
# CLI > Config file && CLI > ENV
worker.start(flags="--config tests/fixtures/config2.py --name xxx", env={"MRQ_NAME": "yyy"})
cfg = json.loads(
worker.send_task("tests.tasks.general.GetConfig", {}, block=True))
assert cfg["name"] == "xxx"
assert cfg.get("additional_unexpected_config") == "1"
worker.stop()
# ENV > Config file
worker.start(flags="--config tests/fixtures/config2.py", env={"MRQ_NAME": "yyy"})
cfg = json.loads(
worker.send_task("tests.tasks.general.GetConfig", {}, block=True))
assert cfg["name"] == "yyy"
assert cfg.get("additional_unexpected_config") == "1"
worker.stop()
# Command line flags with default values should be able to overwrite file config
# Here we have LOG_LEVEL="INFO" in the file, and DEBUG is default
worker.start(flags="--config tests/fixtures/config2.py")
cfg = json.loads(
worker.send_task("tests.tasks.general.GetConfig", {}, block=True))
assert cfg["log_level"] == "INFO"
worker.stop()
worker.start(flags="--config tests/fixtures/config2.py --log_level DEBUG")
cfg = json.loads(
worker.send_task("tests.tasks.general.GetConfig", {}, block=True))
assert cfg["log_level"] == "DEBUG"
worker.stop()