xref: /unit/test/test_php_basic.py (revision 1775:4b4991514356)
11019Szelenkov@nginx.comfrom unit.control import TestControl
2484Szelenkov@nginx.com
31017Szelenkov@nginx.com
41019Szelenkov@nginx.comclass TestPHPBasic(TestControl):
51467Szelenkov@nginx.com    prerequisites = {'modules': {'php': 'any'}}
6484Szelenkov@nginx.com
7504Szelenkov@nginx.com    conf_app = {
8504Szelenkov@nginx.com        "app": {
9504Szelenkov@nginx.com            "type": "php",
101017Szelenkov@nginx.com            "processes": {"spare": 0},
11504Szelenkov@nginx.com            "root": "/app",
121017Szelenkov@nginx.com            "index": "index.php",
13495Szelenkov@nginx.com        }
14504Szelenkov@nginx.com    }
15484Szelenkov@nginx.com
16504Szelenkov@nginx.com    conf_basic = {
171041Svbart@nginx.com        "listeners": {"*:7080": {"pass": "applications/app"}},
181017Szelenkov@nginx.com        "applications": conf_app,
19504Szelenkov@nginx.com    }
20495Szelenkov@nginx.com
21495Szelenkov@nginx.com    def test_php_get_applications(self):
22*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_app, 'applications')
23484Szelenkov@nginx.com
24504Szelenkov@nginx.com        conf = self.conf_get()
25484Szelenkov@nginx.com
261596Szelenkov@nginx.com        assert conf['listeners'] == {}, 'listeners'
271596Szelenkov@nginx.com        assert conf['applications'] == {
281596Szelenkov@nginx.com            "app": {
291596Szelenkov@nginx.com                "type": "php",
301596Szelenkov@nginx.com                "processes": {"spare": 0},
311596Szelenkov@nginx.com                "root": "/app",
321596Szelenkov@nginx.com                "index": "index.php",
331596Szelenkov@nginx.com            }
341596Szelenkov@nginx.com        }, 'applications'
35495Szelenkov@nginx.com
361596Szelenkov@nginx.com        assert self.conf_get('applications') == {
371596Szelenkov@nginx.com            "app": {
38484Szelenkov@nginx.com                "type": "php",
391017Szelenkov@nginx.com                "processes": {"spare": 0},
40484Szelenkov@nginx.com                "root": "/app",
411017Szelenkov@nginx.com                "index": "index.php",
421596Szelenkov@nginx.com            }
431596Szelenkov@nginx.com        }, 'applications prefix'
44495Szelenkov@nginx.com
451596Szelenkov@nginx.com        assert self.conf_get('applications/app') == {
461596Szelenkov@nginx.com            "type": "php",
471596Szelenkov@nginx.com            "processes": {"spare": 0},
481596Szelenkov@nginx.com            "root": "/app",
491596Szelenkov@nginx.com            "index": "index.php",
501596Szelenkov@nginx.com        }, 'applications prefix 2'
511596Szelenkov@nginx.com
521596Szelenkov@nginx.com        assert self.conf_get('applications/app/type') == 'php', 'type'
531596Szelenkov@nginx.com        assert (
541596Szelenkov@nginx.com            self.conf_get('applications/app/processes/spare') == 0
551596Szelenkov@nginx.com        ), 'spare processes'
56484Szelenkov@nginx.com
57495Szelenkov@nginx.com    def test_php_get_listeners(self):
58*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
59484Szelenkov@nginx.com
601596Szelenkov@nginx.com        assert self.conf_get()['listeners'] == {
611596Szelenkov@nginx.com            "*:7080": {"pass": "applications/app"}
621596Szelenkov@nginx.com        }, 'listeners'
63495Szelenkov@nginx.com
641596Szelenkov@nginx.com        assert self.conf_get('listeners') == {
651596Szelenkov@nginx.com            "*:7080": {"pass": "applications/app"}
661596Szelenkov@nginx.com        }, 'listeners prefix'
67495Szelenkov@nginx.com
681596Szelenkov@nginx.com        assert self.conf_get('listeners/*:7080') == {
691596Szelenkov@nginx.com            "pass": "applications/app"
701596Szelenkov@nginx.com        }, 'listeners prefix 2'
71484Szelenkov@nginx.com
72495Szelenkov@nginx.com    def test_php_change_listener(self):
73*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
74*1775Szelenkov@nginx.com        assert 'success' in self.conf(
75*1775Szelenkov@nginx.com            {"*:7081": {"pass": "applications/app"}}, 'listeners'
76*1775Szelenkov@nginx.com        )
77484Szelenkov@nginx.com
781596Szelenkov@nginx.com        assert self.conf_get('listeners') == {
791596Szelenkov@nginx.com            "*:7081": {"pass": "applications/app"}
801596Szelenkov@nginx.com        }, 'change listener'
81484Szelenkov@nginx.com
82495Szelenkov@nginx.com    def test_php_add_listener(self):
83*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
84*1775Szelenkov@nginx.com        assert 'success' in self.conf(
85*1775Szelenkov@nginx.com            {"pass": "applications/app"}, 'listeners/*:7082'
86*1775Szelenkov@nginx.com        )
87484Szelenkov@nginx.com
881596Szelenkov@nginx.com        assert self.conf_get('listeners') == {
891596Szelenkov@nginx.com            "*:7080": {"pass": "applications/app"},
901596Szelenkov@nginx.com            "*:7082": {"pass": "applications/app"},
911596Szelenkov@nginx.com        }, 'add listener'
92495Szelenkov@nginx.com
93495Szelenkov@nginx.com    def test_php_change_application(self):
94*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
95484Szelenkov@nginx.com
96*1775Szelenkov@nginx.com        assert 'success' in self.conf('30', 'applications/app/processes/max')
971596Szelenkov@nginx.com        assert (
981596Szelenkov@nginx.com            self.conf_get('applications/app/processes/max') == 30
991596Szelenkov@nginx.com        ), 'change application max'
100484Szelenkov@nginx.com
101*1775Szelenkov@nginx.com        assert 'success' in self.conf('"/www"', 'applications/app/root')
1021596Szelenkov@nginx.com        assert (
1031596Szelenkov@nginx.com            self.conf_get('applications/app/root') == '/www'
1041596Szelenkov@nginx.com        ), 'change application root'
105484Szelenkov@nginx.com
106484Szelenkov@nginx.com    def test_php_delete(self):
107*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
108484Szelenkov@nginx.com
1091596Szelenkov@nginx.com        assert 'error' in self.conf_delete('applications/app')
1101596Szelenkov@nginx.com        assert 'success' in self.conf_delete('listeners/*:7080')
1111596Szelenkov@nginx.com        assert 'success' in self.conf_delete('applications/app')
1121596Szelenkov@nginx.com        assert 'error' in self.conf_delete('applications/app')
1131017Szelenkov@nginx.com
1141119Szelenkov@nginx.com    def test_php_delete_blocks(self):
115*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
1161119Szelenkov@nginx.com
1171596Szelenkov@nginx.com        assert 'success' in self.conf_delete('listeners')
1181596Szelenkov@nginx.com        assert 'success' in self.conf_delete('applications')
1191119Szelenkov@nginx.com
1201596Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_app, 'applications')
1211596Szelenkov@nginx.com        assert 'success' in self.conf(
1221596Szelenkov@nginx.com            {"*:7081": {"pass": "applications/app"}}, 'listeners'
1231596Szelenkov@nginx.com        ), 'applications restore'
124