test_configuration.py (504:e9ebde982898) test_configuration.py (507:fa714d76592b)
1import unittest
2import unit
3
4class TestUnitConfiguration(unit.TestUnitControl):
5
6 def setUpClass():
7 unit.TestUnit().check_modules('python')
8
9 def test_json_leading_zero(self):
10 self.assertIn('error', self.conf('00'), 'leading zero')
11
12 def test_json_unicode(self):
13 self.assertIn('success', self.conf(b"""
14 {
15 "ap\u0070": {
16 "type": "\u0070ython",
1import unittest
2import unit
3
4class TestUnitConfiguration(unit.TestUnitControl):
5
6 def setUpClass():
7 unit.TestUnit().check_modules('python')
8
9 def test_json_leading_zero(self):
10 self.assertIn('error', self.conf('00'), 'leading zero')
11
12 def test_json_unicode(self):
13 self.assertIn('success', self.conf(b"""
14 {
15 "ap\u0070": {
16 "type": "\u0070ython",
17 "workers": 1,
17 "processes": { "spare": 0 },
18 "path": "\u002Fapp",
19 "module": "wsgi"
20 }
21 }
22 """, '/applications'), 'unicode')
23
24 def test_json_unicode_2(self):
25 self.assertIn('success', self.conf({
26 "приложение": {
27 "type": "python",
18 "path": "\u002Fapp",
19 "module": "wsgi"
20 }
21 }
22 """, '/applications'), 'unicode')
23
24 def test_json_unicode_2(self):
25 self.assertIn('success', self.conf({
26 "приложение": {
27 "type": "python",
28 "workers": 1,
28 "processes": { "spare": 0 },
29 "path": "/app",
30 "module": "wsgi"
31 }
32 }, '/applications'), 'unicode 2')
33
34 def test_json_unicode_number(self):
35 self.assertIn('error', self.conf(b"""
36 {
37 "app": {
38 "type": "python",
29 "path": "/app",
30 "module": "wsgi"
31 }
32 }, '/applications'), 'unicode 2')
33
34 def test_json_unicode_number(self):
35 self.assertIn('error', self.conf(b"""
36 {
37 "app": {
38 "type": "python",
39 "workers": \u0031,
39 "processes": { "spare": \u0030 },
40 "path": "/app",
41 "module": "wsgi"
42 }
43 }
44 """, '/applications'), 'unicode number')
45
46 def test_applications_open_brace(self):
47 self.assertIn('error', self.conf('{', '/applications'), 'open brace')
48
49 def test_applications_string(self):
50 self.assertIn('error', self.conf('"{}"', '/applications'), 'string')
51
40 "path": "/app",
41 "module": "wsgi"
42 }
43 }
44 """, '/applications'), 'unicode number')
45
46 def test_applications_open_brace(self):
47 self.assertIn('error', self.conf('{', '/applications'), 'open brace')
48
49 def test_applications_string(self):
50 self.assertIn('error', self.conf('"{}"', '/applications'), 'string')
51
52 @unittest.expectedFailure
53 def test_negative_workers(self):
52 def test_negative_spare(self):
54 self.assertIn('error', self.conf({
55 "app": {
56 "type": "python",
53 self.assertIn('error', self.conf({
54 "app": {
55 "type": "python",
57 "workers": -1,
56 "processes": { "spare": -1 },
58 "path": "/app",
59 "module": "wsgi"
60 }
57 "path": "/app",
58 "module": "wsgi"
59 }
61 }, '/applications'), 'negative workers')
60 }, '/applications'), 'negative spare')
62
61
63 @unittest.expectedFailure
64 def test_applications_type_only(self):
65 self.assertIn('error', self.conf({
66 "app": {
67 "type": "python"
68 }
69 }, '/applications'), 'type only')
70
71 def test_applications_miss_quote(self):
72 self.assertIn('error', self.conf("""
73 {
74 app": {
75 "type": "python",
62 def test_applications_type_only(self):
63 self.assertIn('error', self.conf({
64 "app": {
65 "type": "python"
66 }
67 }, '/applications'), 'type only')
68
69 def test_applications_miss_quote(self):
70 self.assertIn('error', self.conf("""
71 {
72 app": {
73 "type": "python",
76 "workers": 1,
74 "processes": { "spare": 0 },
77 "path": "/app",
78 "module": "wsgi"
79 }
80 }
81 """, '/applications'), 'miss quote')
82
83 def test_applications_miss_colon(self):
84 self.assertIn('error', self.conf("""
85 {
86 "app" {
87 "type": "python",
75 "path": "/app",
76 "module": "wsgi"
77 }
78 }
79 """, '/applications'), 'miss quote')
80
81 def test_applications_miss_colon(self):
82 self.assertIn('error', self.conf("""
83 {
84 "app" {
85 "type": "python",
88 "workers": 1,
86 "processes": { "spare": 0 },
89 "path": "/app",
90 "module": "wsgi"
91 }
92 }
93 """, '/applications'), 'miss colon')
94
95 def test_applications_miss_comma(self):
96 self.assertIn('error', self.conf("""
97 {
98 "app": {
99 "type": "python"
87 "path": "/app",
88 "module": "wsgi"
89 }
90 }
91 """, '/applications'), 'miss colon')
92
93 def test_applications_miss_comma(self):
94 self.assertIn('error', self.conf("""
95 {
96 "app": {
97 "type": "python"
100 "workers": 1,
98 "processes": { "spare": 0 },
101 "path": "/app",
102 "module": "wsgi"
103 }
104 }
105 """, '/applications'), 'miss comma')
106
107 def test_applications_skip_spaces(self):
108 self.assertIn('success', self.conf(b'{ \n\r\t}', '/applications'),
109 'skip spaces')
110
111 def test_applications_relative_path(self):
112 self.assertIn('success', self.conf({
113 "app": {
114 "type": "python",
99 "path": "/app",
100 "module": "wsgi"
101 }
102 }
103 """, '/applications'), 'miss comma')
104
105 def test_applications_skip_spaces(self):
106 self.assertIn('success', self.conf(b'{ \n\r\t}', '/applications'),
107 'skip spaces')
108
109 def test_applications_relative_path(self):
110 self.assertIn('success', self.conf({
111 "app": {
112 "type": "python",
115 "workers": 1,
113 "processes": { "spare": 0 },
116 "path": "../app",
117 "module": "wsgi"
118 }
119 }, '/applications'), 'relative path')
120
121 @unittest.expectedFailure
122 def test_listeners_empty(self):
123 self.assertIn('error', self.conf({"*:7080":{}}, '/listeners'),

--- 8 unchanged lines hidden (view full) ---

132 "listeners": {
133 "*:7080": {
134 "application":"app"
135 }
136 },
137 "applications": {
138 "app": {
139 "type": "python",
114 "path": "../app",
115 "module": "wsgi"
116 }
117 }, '/applications'), 'relative path')
118
119 @unittest.expectedFailure
120 def test_listeners_empty(self):
121 self.assertIn('error', self.conf({"*:7080":{}}, '/listeners'),

--- 8 unchanged lines hidden (view full) ---

130 "listeners": {
131 "*:7080": {
132 "application":"app"
133 }
134 },
135 "applications": {
136 "app": {
137 "type": "python",
140 "workers": 1,
138 "processes": { "spare": 0 },
141 "path": "/app",
142 "module": "wsgi"
143 }
144 }
145 }), 'listeners wildcard')
146
147 def test_listeners_explicit(self):
148 self.assertIn('success', self.conf({
149 "listeners": {
150 "127.0.0.1:7080": {
151 "application":"app"
152 }
153 },
154 "applications": {
155 "app": {
156 "type": "python",
139 "path": "/app",
140 "module": "wsgi"
141 }
142 }
143 }), 'listeners wildcard')
144
145 def test_listeners_explicit(self):
146 self.assertIn('success', self.conf({
147 "listeners": {
148 "127.0.0.1:7080": {
149 "application":"app"
150 }
151 },
152 "applications": {
153 "app": {
154 "type": "python",
157 "workers": 1,
155 "processes": { "spare": 0 },
158 "path": "/app",
159 "module": "wsgi"
160 }
161 }
162 }), 'explicit')
163
164 def test_listeners_explicit_ipv6(self):
165 self.assertIn('success', self.conf({
166 "listeners": {
167 "[::1]:7080": {
168 "application":"app"
169 }
170 },
171 "applications": {
172 "app": {
173 "type": "python",
156 "path": "/app",
157 "module": "wsgi"
158 }
159 }
160 }), 'explicit')
161
162 def test_listeners_explicit_ipv6(self):
163 self.assertIn('success', self.conf({
164 "listeners": {
165 "[::1]:7080": {
166 "application":"app"
167 }
168 },
169 "applications": {
170 "app": {
171 "type": "python",
174 "workers": 1,
172 "processes": { "spare": 0 },
175 "path": "/app",
176 "module": "wsgi"
177 }
178 }
179 }), 'explicit ipv6')
180
181 def test_listeners_no_port(self):
182 self.assertIn('error', self.conf({
183 "listeners": {
184 "127.0.0.1": {
185 "application":"app"
186 }
187 },
188 "applications": {
189 "app": {
190 "type": "python",
173 "path": "/app",
174 "module": "wsgi"
175 }
176 }
177 }), 'explicit ipv6')
178
179 def test_listeners_no_port(self):
180 self.assertIn('error', self.conf({
181 "listeners": {
182 "127.0.0.1": {
183 "application":"app"
184 }
185 },
186 "applications": {
187 "app": {
188 "type": "python",
191 "workers": 1,
189 "processes": { "spare": 0 },
192 "path": "/app",
193 "module": "wsgi"
194 }
195 }
196 }), 'no port')
197
198if __name__ == '__main__':
199 unittest.main()
190 "path": "/app",
191 "module": "wsgi"
192 }
193 }
194 }), 'no port')
195
196if __name__ == '__main__':
197 unittest.main()