xref: /unit/test/test_python_environment.py (revision 1596:b7e2d4d92624)
11019Szelenkov@nginx.comfrom unit.applications.lang.python import TestApplicationPython
2679Szelenkov@nginx.com
31017Szelenkov@nginx.com
41019Szelenkov@nginx.comclass TestPythonEnvironment(TestApplicationPython):
51467Szelenkov@nginx.com    prerequisites = {'modules': {'python': 'any'}}
6679Szelenkov@nginx.com
7679Szelenkov@nginx.com    def test_python_environment_name_null(self):
8679Szelenkov@nginx.com        self.load('environment')
9679Szelenkov@nginx.com
10*1596Szelenkov@nginx.com        assert 'error' in self.conf(
11*1596Szelenkov@nginx.com            {"va\0r": "val1"}, 'applications/environment/environment'
12*1596Szelenkov@nginx.com        ), 'name null'
13679Szelenkov@nginx.com
14679Szelenkov@nginx.com    def test_python_environment_name_equals(self):
15679Szelenkov@nginx.com        self.load('environment')
16679Szelenkov@nginx.com
17*1596Szelenkov@nginx.com        assert 'error' in self.conf(
18*1596Szelenkov@nginx.com            {"var=": "val1"}, 'applications/environment/environment'
19*1596Szelenkov@nginx.com        ), 'name equals'
20679Szelenkov@nginx.com
21679Szelenkov@nginx.com    def test_python_environment_value_null(self):
22679Szelenkov@nginx.com        self.load('environment')
23679Szelenkov@nginx.com
24*1596Szelenkov@nginx.com        assert 'error' in self.conf(
25*1596Szelenkov@nginx.com            {"var": "\0val"}, 'applications/environment/environment'
26*1596Szelenkov@nginx.com        ), 'value null'
27679Szelenkov@nginx.com
28679Szelenkov@nginx.com    def test_python_environment_update(self):
29679Szelenkov@nginx.com        self.load('environment')
30679Szelenkov@nginx.com
311017Szelenkov@nginx.com        self.conf({"var": "val1"}, 'applications/environment/environment')
32679Szelenkov@nginx.com
33*1596Szelenkov@nginx.com        assert (
341017Szelenkov@nginx.com            self.get(
351017Szelenkov@nginx.com                headers={
361017Szelenkov@nginx.com                    'Host': 'localhost',
371017Szelenkov@nginx.com                    'X-Variables': 'var',
381017Szelenkov@nginx.com                    'Connection': 'close',
391017Szelenkov@nginx.com                }
40*1596Szelenkov@nginx.com            )['body']
41*1596Szelenkov@nginx.com            == 'val1,'
42*1596Szelenkov@nginx.com        ), 'set'
43679Szelenkov@nginx.com
441017Szelenkov@nginx.com        self.conf({"var": "val2"}, 'applications/environment/environment')
45679Szelenkov@nginx.com
46*1596Szelenkov@nginx.com        assert (
471017Szelenkov@nginx.com            self.get(
481017Szelenkov@nginx.com                headers={
491017Szelenkov@nginx.com                    'Host': 'localhost',
501017Szelenkov@nginx.com                    'X-Variables': 'var',
511017Szelenkov@nginx.com                    'Connection': 'close',
521017Szelenkov@nginx.com                }
53*1596Szelenkov@nginx.com            )['body']
54*1596Szelenkov@nginx.com            == 'val2,'
55*1596Szelenkov@nginx.com        ), 'update'
56679Szelenkov@nginx.com
57679Szelenkov@nginx.com    def test_python_environment_replace(self):
58679Szelenkov@nginx.com        self.load('environment')
59679Szelenkov@nginx.com
601017Szelenkov@nginx.com        self.conf({"var1": "val1"}, 'applications/environment/environment')
61679Szelenkov@nginx.com
62*1596Szelenkov@nginx.com        assert (
631017Szelenkov@nginx.com            self.get(
641017Szelenkov@nginx.com                headers={
651017Szelenkov@nginx.com                    'Host': 'localhost',
661017Szelenkov@nginx.com                    'X-Variables': 'var1',
671017Szelenkov@nginx.com                    'Connection': 'close',
681017Szelenkov@nginx.com                }
69*1596Szelenkov@nginx.com            )['body']
70*1596Szelenkov@nginx.com            == 'val1,'
71*1596Szelenkov@nginx.com        ), 'set'
72679Szelenkov@nginx.com
731017Szelenkov@nginx.com        self.conf({"var2": "val2"}, 'applications/environment/environment')
74679Szelenkov@nginx.com
75*1596Szelenkov@nginx.com        assert (
761017Szelenkov@nginx.com            self.get(
771017Szelenkov@nginx.com                headers={
781017Szelenkov@nginx.com                    'Host': 'localhost',
791017Szelenkov@nginx.com                    'X-Variables': 'var1,var2',
801017Szelenkov@nginx.com                    'Connection': 'close',
811017Szelenkov@nginx.com                }
82*1596Szelenkov@nginx.com            )['body']
83*1596Szelenkov@nginx.com            == 'val2,'
84*1596Szelenkov@nginx.com        ), 'replace'
85679Szelenkov@nginx.com
86679Szelenkov@nginx.com    def test_python_environment_clear(self):
87679Szelenkov@nginx.com        self.load('environment')
88679Szelenkov@nginx.com
891017Szelenkov@nginx.com        self.conf(
901017Szelenkov@nginx.com            {"var1": "val1", "var2": "val2"},
911017Szelenkov@nginx.com            'applications/environment/environment',
921017Szelenkov@nginx.com        )
93679Szelenkov@nginx.com
94*1596Szelenkov@nginx.com        assert (
951017Szelenkov@nginx.com            self.get(
961017Szelenkov@nginx.com                headers={
971017Szelenkov@nginx.com                    'Host': 'localhost',
981017Szelenkov@nginx.com                    'X-Variables': 'var1,var2',
991017Szelenkov@nginx.com                    'Connection': 'close',
1001017Szelenkov@nginx.com                }
101*1596Szelenkov@nginx.com            )['body']
102*1596Szelenkov@nginx.com            == 'val1,val2,'
103*1596Szelenkov@nginx.com        ), 'set'
104679Szelenkov@nginx.com
105760Szelenkov@nginx.com        self.conf({}, 'applications/environment/environment')
106679Szelenkov@nginx.com
107*1596Szelenkov@nginx.com        assert (
1081017Szelenkov@nginx.com            self.get(
1091017Szelenkov@nginx.com                headers={
1101017Szelenkov@nginx.com                    'Host': 'localhost',
1111017Szelenkov@nginx.com                    'X-Variables': 'var1,var2',
1121017Szelenkov@nginx.com                    'Connection': 'close',
1131017Szelenkov@nginx.com                }
114*1596Szelenkov@nginx.com            )['body']
115*1596Szelenkov@nginx.com            == ''
116*1596Szelenkov@nginx.com        ), 'clear'
117679Szelenkov@nginx.com
118679Szelenkov@nginx.com    def test_python_environment_replace_default(self):
119679Szelenkov@nginx.com        self.load('environment')
120679Szelenkov@nginx.com
1211293St.nateldemoura@f5.com        home_default = self.get(
1221017Szelenkov@nginx.com            headers={
1231017Szelenkov@nginx.com                'Host': 'localhost',
1241293St.nateldemoura@f5.com                'X-Variables': 'HOME',
1251017Szelenkov@nginx.com                'Connection': 'close',
1261017Szelenkov@nginx.com            }
1271017Szelenkov@nginx.com        )['body']
128679Szelenkov@nginx.com
129*1596Szelenkov@nginx.com        assert len(home_default) > 1, 'get default'
130679Szelenkov@nginx.com
1311293St.nateldemoura@f5.com        self.conf({"HOME": "/"}, 'applications/environment/environment')
132679Szelenkov@nginx.com
133*1596Szelenkov@nginx.com        assert (
1341017Szelenkov@nginx.com            self.get(
1351017Szelenkov@nginx.com                headers={
1361017Szelenkov@nginx.com                    'Host': 'localhost',
1371293St.nateldemoura@f5.com                    'X-Variables': 'HOME',
1381017Szelenkov@nginx.com                    'Connection': 'close',
1391017Szelenkov@nginx.com                }
140*1596Szelenkov@nginx.com            )['body']
141*1596Szelenkov@nginx.com            == '/,'
142*1596Szelenkov@nginx.com        ), 'replace default'
143679Szelenkov@nginx.com
144760Szelenkov@nginx.com        self.conf({}, 'applications/environment/environment')
145679Szelenkov@nginx.com
146*1596Szelenkov@nginx.com        assert (
1471017Szelenkov@nginx.com            self.get(
1481017Szelenkov@nginx.com                headers={
1491017Szelenkov@nginx.com                    'Host': 'localhost',
1501293St.nateldemoura@f5.com                    'X-Variables': 'HOME',
1511017Szelenkov@nginx.com                    'Connection': 'close',
1521017Szelenkov@nginx.com                }
153*1596Szelenkov@nginx.com            )['body']
154*1596Szelenkov@nginx.com            == home_default
155*1596Szelenkov@nginx.com        ), 'restore default'
156