|
1
|
|
|
"""Test cases fake-uwsgi package""" |
|
2
|
|
|
import os |
|
3
|
|
|
|
|
4
|
|
|
import fake_uwsgi |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
def test_environ(): |
|
8
|
|
|
"""Test the environment values fake_uwsgi should set.""" |
|
9
|
|
|
assert os.environ.get("INSTALL_PATH") == os.path.abspath( |
|
10
|
|
|
os.path.join(fake_uwsgi.__file__, os.pardir) |
|
11
|
|
|
) |
|
12
|
|
|
assert os.environ.get("APP_RUN_MODE") == "development" |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
def test_global_variables(): |
|
16
|
|
|
"""Test the global variables set by fake_uwsgi module""" |
|
17
|
|
|
assert fake_uwsgi.opt == {"mode": b"development", "vassal-name": b"fake-uwsgi"} |
|
18
|
|
|
|
|
19
|
|
|
assert fake_uwsgi.numproc == 4 |
|
20
|
|
|
|
|
21
|
|
|
assert fake_uwsgi.LOGVAR == {} |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def test_log(capfd): |
|
25
|
|
|
"""Test the log function of fake_uwsgi""" |
|
26
|
|
|
fake_uwsgi.log("This is a test string being printed.") |
|
27
|
|
|
out = capfd.readouterr()[0] |
|
28
|
|
|
assert out == "This is a test string being printed.\n" |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
def test_log_var(): |
|
32
|
|
|
"""Test the set and get log variable functions.""" |
|
33
|
|
|
|
|
34
|
|
|
# When the key is not set, get_logvar should return None |
|
35
|
|
|
assert "test" not in fake_uwsgi.LOGVAR |
|
36
|
|
|
assert fake_uwsgi.get_logvar("test") is None |
|
37
|
|
|
|
|
38
|
|
|
# Set the value and get it |
|
39
|
|
|
fake_uwsgi.set_logvar("test", "yahoo") |
|
40
|
|
|
assert fake_uwsgi.get_logvar("test") == "yahoo" |
|
41
|
|
|
|
|
42
|
|
|
# Providing the key only should set the value to None |
|
43
|
|
|
fake_uwsgi.set_logvar("test") |
|
44
|
|
|
assert fake_uwsgi.get_logvar("test") is None |
|
45
|
|
|
|
|
46
|
|
|
# Add the same key with a different value |
|
47
|
|
|
fake_uwsgi.set_logvar(test="montreal") |
|
48
|
|
|
assert fake_uwsgi.get_logvar("test") == "montreal" |
|
49
|
|
|
|
|
50
|
|
|
# Add multiple keys and update an existing one |
|
51
|
|
|
fake_uwsgi.set_logvar(test="ottawa", another_test="toronto") |
|
52
|
|
|
|
|
53
|
|
|
assert fake_uwsgi.get_logvar("test") == "ottawa" |
|
54
|
|
|
assert fake_uwsgi.get_logvar("another_test") == "toronto" |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
def test_worker_id(): |
|
58
|
|
|
"""Test the worker_id function in fake_uwsgi""" |
|
59
|
|
|
assert fake_uwsgi.worker_id() == 123 |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
def test_workers(): |
|
63
|
|
|
"""Test the workers function in fake_uwsgi""" |
|
64
|
|
|
assert isinstance(fake_uwsgi.workers(), list) |
|
65
|
|
|
|
|
66
|
|
|
# Each element of the list should be a dict |
|
67
|
|
|
for item in fake_uwsgi.workers(): |
|
68
|
|
|
assert isinstance(item, dict) |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
def test_total_requests(): |
|
72
|
|
|
"""Test the total_requests function in fake_uwsgi""" |
|
73
|
|
|
assert fake_uwsgi.total_requests() == 564 |
|
74
|
|
|
|