xref: /unit/test/test_python_basic.py (revision 1775:4b4991514356)
11019Szelenkov@nginx.comfrom unit.control import TestControl
2484Szelenkov@nginx.com
31017Szelenkov@nginx.com
41019Szelenkov@nginx.comclass TestPythonBasic(TestControl):
51467Szelenkov@nginx.com    prerequisites = {'modules': {'python': 'any'}}
6484Szelenkov@nginx.com
7504Szelenkov@nginx.com    conf_app = {
8504Szelenkov@nginx.com        "app": {
9504Szelenkov@nginx.com            "type": "python",
101017Szelenkov@nginx.com            "processes": {"spare": 0},
11504Szelenkov@nginx.com            "path": "/app",
121017Szelenkov@nginx.com            "module": "wsgi",
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_python_get_empty(self):
221596Szelenkov@nginx.com        assert self.conf_get() == {'listeners': {}, 'applications': {}}
231596Szelenkov@nginx.com        assert self.conf_get('listeners') == {}
241596Szelenkov@nginx.com        assert self.conf_get('applications') == {}
25495Szelenkov@nginx.com
26495Szelenkov@nginx.com    def test_python_get_applications(self):
27760Szelenkov@nginx.com        self.conf(self.conf_app, 'applications')
28484Szelenkov@nginx.com
29504Szelenkov@nginx.com        conf = self.conf_get()
30484Szelenkov@nginx.com
311596Szelenkov@nginx.com        assert conf['listeners'] == {}, 'listeners'
321596Szelenkov@nginx.com        assert conf['applications'] == {
331596Szelenkov@nginx.com            "app": {
341596Szelenkov@nginx.com                "type": "python",
351596Szelenkov@nginx.com                "processes": {"spare": 0},
361596Szelenkov@nginx.com                "path": "/app",
371596Szelenkov@nginx.com                "module": "wsgi",
381596Szelenkov@nginx.com            }
391596Szelenkov@nginx.com        }, 'applications'
40495Szelenkov@nginx.com
411596Szelenkov@nginx.com        assert self.conf_get('applications') == {
421596Szelenkov@nginx.com            "app": {
43484Szelenkov@nginx.com                "type": "python",
441017Szelenkov@nginx.com                "processes": {"spare": 0},
45484Szelenkov@nginx.com                "path": "/app",
461017Szelenkov@nginx.com                "module": "wsgi",
471596Szelenkov@nginx.com            }
481596Szelenkov@nginx.com        }, 'applications prefix'
49495Szelenkov@nginx.com
501596Szelenkov@nginx.com        assert self.conf_get('applications/app') == {
511596Szelenkov@nginx.com            "type": "python",
521596Szelenkov@nginx.com            "processes": {"spare": 0},
531596Szelenkov@nginx.com            "path": "/app",
541596Szelenkov@nginx.com            "module": "wsgi",
551596Szelenkov@nginx.com        }, 'applications prefix 2'
561596Szelenkov@nginx.com
571596Szelenkov@nginx.com        assert self.conf_get('applications/app/type') == 'python', 'type'
581596Szelenkov@nginx.com        assert self.conf_get('applications/app/processes/spare') == 0, 'spare'
59484Szelenkov@nginx.com
60495Szelenkov@nginx.com    def test_python_get_listeners(self):
61*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
62484Szelenkov@nginx.com
631596Szelenkov@nginx.com        assert self.conf_get()['listeners'] == {
641596Szelenkov@nginx.com            "*:7080": {"pass": "applications/app"}
651596Szelenkov@nginx.com        }, 'listeners'
66495Szelenkov@nginx.com
671596Szelenkov@nginx.com        assert self.conf_get('listeners') == {
681596Szelenkov@nginx.com            "*:7080": {"pass": "applications/app"}
691596Szelenkov@nginx.com        }, 'listeners prefix'
70495Szelenkov@nginx.com
711596Szelenkov@nginx.com        assert self.conf_get('listeners/*:7080') == {
721596Szelenkov@nginx.com            "pass": "applications/app"
731596Szelenkov@nginx.com        }, 'listeners prefix 2'
74484Szelenkov@nginx.com
75495Szelenkov@nginx.com    def test_python_change_listener(self):
76*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
77*1775Szelenkov@nginx.com        assert 'success' in self.conf(
78*1775Szelenkov@nginx.com            {"*:7081": {"pass": "applications/app"}}, 'listeners'
79*1775Szelenkov@nginx.com        )
80484Szelenkov@nginx.com
811596Szelenkov@nginx.com        assert self.conf_get('listeners') == {
821596Szelenkov@nginx.com            "*:7081": {"pass": "applications/app"}
831596Szelenkov@nginx.com        }, 'change listener'
84484Szelenkov@nginx.com
85495Szelenkov@nginx.com    def test_python_add_listener(self):
86*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
87*1775Szelenkov@nginx.com        assert 'success' in self.conf(
88*1775Szelenkov@nginx.com            {"pass": "applications/app"}, 'listeners/*:7082'
89*1775Szelenkov@nginx.com        )
90484Szelenkov@nginx.com
911596Szelenkov@nginx.com        assert self.conf_get('listeners') == {
921596Szelenkov@nginx.com            "*:7080": {"pass": "applications/app"},
931596Szelenkov@nginx.com            "*:7082": {"pass": "applications/app"},
941596Szelenkov@nginx.com        }, 'add listener'
95495Szelenkov@nginx.com
96495Szelenkov@nginx.com    def test_python_change_application(self):
97*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
98484Szelenkov@nginx.com
99*1775Szelenkov@nginx.com        assert 'success' in self.conf('30', 'applications/app/processes/max')
1001596Szelenkov@nginx.com        assert (
1011596Szelenkov@nginx.com            self.conf_get('applications/app/processes/max') == 30
1021596Szelenkov@nginx.com        ), 'change application max'
103484Szelenkov@nginx.com
104*1775Szelenkov@nginx.com        assert 'success' in self.conf('"/www"', 'applications/app/path')
1051596Szelenkov@nginx.com        assert (
1061596Szelenkov@nginx.com            self.conf_get('applications/app/path') == '/www'
1071596Szelenkov@nginx.com        ), 'change application path'
108484Szelenkov@nginx.com
109484Szelenkov@nginx.com    def test_python_delete(self):
110*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
111484Szelenkov@nginx.com
1121596Szelenkov@nginx.com        assert 'error' in self.conf_delete('applications/app')
1131596Szelenkov@nginx.com        assert 'success' in self.conf_delete('listeners/*:7080')
1141596Szelenkov@nginx.com        assert 'success' in self.conf_delete('applications/app')
1151596Szelenkov@nginx.com        assert 'error' in self.conf_delete('applications/app')
1161017Szelenkov@nginx.com
1171119Szelenkov@nginx.com    def test_python_delete_blocks(self):
118*1775Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_basic)
1191119Szelenkov@nginx.com
1201596Szelenkov@nginx.com        assert 'success' in self.conf_delete('listeners')
1211596Szelenkov@nginx.com        assert 'success' in self.conf_delete('applications')
1221119Szelenkov@nginx.com
1231596Szelenkov@nginx.com        assert 'success' in self.conf(self.conf_app, 'applications')
1241596Szelenkov@nginx.com        assert 'success' in self.conf(
1251596Szelenkov@nginx.com            {"*:7081": {"pass": "applications/app"}}, 'listeners'
1261596Szelenkov@nginx.com        ), 'applications restore'
127