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