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