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