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