xref: /unit/test/test_python_basic.py (revision 2592:e079c44a8340)
1from unit.control import Control
2
3prerequisites = {'modules': {'python': 'any'}}
4
5client = Control()
6
7conf_app = {
8    "app": {
9        "type": "python",
10        "processes": {"spare": 0},
11        "path": "/app",
12        "module": "wsgi",
13    }
14}
15
16conf_basic = {
17    "listeners": {"*:8080": {"pass": "applications/app"}},
18    "applications": conf_app,
19}
20
21
22def test_python_get_empty():
23    assert client.conf_get() == {'listeners': {}, 'applications': {}}
24    assert client.conf_get('listeners') == {}
25    assert client.conf_get('applications') == {}
26
27
28def test_python_get_applications():
29    client.conf(conf_app, 'applications')
30
31    conf = client.conf_get()
32
33    assert conf['listeners'] == {}, 'listeners'
34    assert conf['applications'] == {
35        "app": {
36            "type": "python",
37            "processes": {"spare": 0},
38            "path": "/app",
39            "module": "wsgi",
40        }
41    }, 'applications'
42
43    assert client.conf_get('applications') == {
44        "app": {
45            "type": "python",
46            "processes": {"spare": 0},
47            "path": "/app",
48            "module": "wsgi",
49        }
50    }, 'applications prefix'
51
52    assert client.conf_get('applications/app') == {
53        "type": "python",
54        "processes": {"spare": 0},
55        "path": "/app",
56        "module": "wsgi",
57    }, 'applications prefix 2'
58
59    assert client.conf_get('applications/app/type') == 'python', 'type'
60    assert client.conf_get('applications/app/processes/spare') == 0, 'spare'
61
62
63def test_python_get_listeners():
64    assert 'success' in client.conf(conf_basic)
65
66    assert client.conf_get()['listeners'] == {
67        "*:8080": {"pass": "applications/app"}
68    }, 'listeners'
69
70    assert client.conf_get('listeners') == {
71        "*:8080": {"pass": "applications/app"}
72    }, 'listeners prefix'
73
74    assert client.conf_get('listeners/*:8080') == {
75        "pass": "applications/app"
76    }, 'listeners prefix 2'
77
78
79def test_python_change_listener():
80    assert 'success' in client.conf(conf_basic)
81    assert 'success' in client.conf(
82        {"*:8081": {"pass": "applications/app"}}, 'listeners'
83    )
84
85    assert client.conf_get('listeners') == {
86        "*:8081": {"pass": "applications/app"}
87    }, 'change listener'
88
89
90def test_python_add_listener():
91    assert 'success' in client.conf(conf_basic)
92    assert 'success' in client.conf(
93        {"pass": "applications/app"}, 'listeners/*:8082'
94    )
95
96    assert client.conf_get('listeners') == {
97        "*:8080": {"pass": "applications/app"},
98        "*:8082": {"pass": "applications/app"},
99    }, 'add listener'
100
101
102def test_python_change_application():
103    assert 'success' in client.conf(conf_basic)
104
105    assert 'success' in client.conf('30', 'applications/app/processes/max')
106    assert (
107        client.conf_get('applications/app/processes/max') == 30
108    ), 'change application max'
109
110    assert 'success' in client.conf('"/www"', 'applications/app/path')
111    assert (
112        client.conf_get('applications/app/path') == '/www'
113    ), 'change application path'
114
115
116def test_python_delete():
117    assert 'success' in client.conf(conf_basic)
118
119    assert 'error' in client.conf_delete('applications/app')
120    assert 'success' in client.conf_delete('listeners/*:8080')
121    assert 'success' in client.conf_delete('applications/app')
122    assert 'error' in client.conf_delete('applications/app')
123
124
125def test_python_delete_blocks():
126    assert 'success' in client.conf(conf_basic)
127
128    assert 'success' in client.conf_delete('listeners')
129    assert 'success' in client.conf_delete('applications')
130
131    assert 'success' in client.conf(conf_app, 'applications')
132    assert 'success' in client.conf(
133        {"*:8081": {"pass": "applications/app"}}, 'listeners'
134    ), 'applications restore'
135