xref: /unit/test/test_python_environment.py (revision 1019:61d90b4da691)
1from unit.applications.lang.python import TestApplicationPython
2
3
4class TestPythonEnvironment(TestApplicationPython):
5    def setUpClass():
6        TestApplicationPython().check_modules('python')
7
8    def test_python_environment_name_null(self):
9        self.load('environment')
10
11        self.assertIn(
12            'error',
13            self.conf(
14                {"va\0r": "val1"}, 'applications/environment/environment'
15            ),
16            'name null',
17        )
18
19    def test_python_environment_name_equals(self):
20        self.load('environment')
21
22        self.assertIn(
23            'error',
24            self.conf(
25                {"var=": "val1"}, 'applications/environment/environment'
26            ),
27            'name equals',
28        )
29
30    def test_python_environment_value_null(self):
31        self.load('environment')
32
33        self.assertIn(
34            'error',
35            self.conf(
36                {"var": "\0val"}, 'applications/environment/environment'
37            ),
38            'value null',
39        )
40
41    def test_python_environment_update(self):
42        self.load('environment')
43
44        self.conf({"var": "val1"}, 'applications/environment/environment')
45
46        self.assertEqual(
47            self.get(
48                headers={
49                    'Host': 'localhost',
50                    'X-Variables': 'var',
51                    'Connection': 'close',
52                }
53            )['body'],
54            'val1,',
55            'set',
56        )
57
58        self.conf({"var": "val2"}, 'applications/environment/environment')
59
60        self.assertEqual(
61            self.get(
62                headers={
63                    'Host': 'localhost',
64                    'X-Variables': 'var',
65                    'Connection': 'close',
66                }
67            )['body'],
68            'val2,',
69            'update',
70        )
71
72    def test_python_environment_replace(self):
73        self.load('environment')
74
75        self.conf({"var1": "val1"}, 'applications/environment/environment')
76
77        self.assertEqual(
78            self.get(
79                headers={
80                    'Host': 'localhost',
81                    'X-Variables': 'var1',
82                    'Connection': 'close',
83                }
84            )['body'],
85            'val1,',
86            'set',
87        )
88
89        self.conf({"var2": "val2"}, 'applications/environment/environment')
90
91        self.assertEqual(
92            self.get(
93                headers={
94                    'Host': 'localhost',
95                    'X-Variables': 'var1,var2',
96                    'Connection': 'close',
97                }
98            )['body'],
99            'val2,',
100            'replace',
101        )
102
103    def test_python_environment_clear(self):
104        self.load('environment')
105
106        self.conf(
107            {"var1": "val1", "var2": "val2"},
108            'applications/environment/environment',
109        )
110
111        self.assertEqual(
112            self.get(
113                headers={
114                    'Host': 'localhost',
115                    'X-Variables': 'var1,var2',
116                    'Connection': 'close',
117                }
118            )['body'],
119            'val1,val2,',
120            'set',
121        )
122
123        self.conf({}, 'applications/environment/environment')
124
125        self.assertEqual(
126            self.get(
127                headers={
128                    'Host': 'localhost',
129                    'X-Variables': 'var1,var2',
130                    'Connection': 'close',
131                }
132            )['body'],
133            '',
134            'clear',
135        )
136
137    def test_python_environment_replace_default(self):
138        self.load('environment')
139
140        pwd_default = self.get(
141            headers={
142                'Host': 'localhost',
143                'X-Variables': 'PWD',
144                'Connection': 'close',
145            }
146        )['body']
147
148        self.assertGreater(len(pwd_default), 1, 'get default')
149
150        self.conf({"PWD": "new/pwd"}, 'applications/environment/environment')
151
152        self.assertEqual(
153            self.get(
154                headers={
155                    'Host': 'localhost',
156                    'X-Variables': 'PWD',
157                    'Connection': 'close',
158                }
159            )['body'],
160            'new/pwd,',
161            'replace default',
162        )
163
164        self.conf({}, 'applications/environment/environment')
165
166        self.assertEqual(
167            self.get(
168                headers={
169                    'Host': 'localhost',
170                    'X-Variables': 'PWD',
171                    'Connection': 'close',
172                }
173            )['body'],
174            pwd_default,
175            'restore default',
176        )
177
178
179if __name__ == '__main__':
180    TestPythonEnvironment.main()
181