test_python_application.py (503:d7eb78307759) test_python_application.py (504:e9ebde982898)
1import unittest
2import unit
3
4class TestUnitApplication(unit.TestUnitControl):
5
6 def setUpClass():
7 u = unit.TestUnit()
8
9 u.check_modules('python')
10 u.check_version('0.4')
11
1import unittest
2import unit
3
4class TestUnitApplication(unit.TestUnitControl):
5
6 def setUpClass():
7 u = unit.TestUnit()
8
9 u.check_modules('python')
10 u.check_version('0.4')
11
12 conf = """
13 {
12 def conf_with_name(self, name):
13 self.conf({
14 "listeners": {
15 "*:7080": {
16 "application": "app"
17 }
18 },
19 "applications": {
20 "app": {
21 "type": "python",
22 "workers": 1,
14 "listeners": {
15 "*:7080": {
16 "application": "app"
17 }
18 },
19 "applications": {
20 "app": {
21 "type": "python",
22 "workers": 1,
23 "path": "%s",
23 "path": self.testdir + '/' + name,
24 "module": "wsgi"
25 }
26 }
24 "module": "wsgi"
25 }
26 }
27 }
28 """
27 })
29
30 def test_python_application_simple(self):
31 code, name = """
32
33def application(environ, start_response):
34
35 content_length = int(environ.get('CONTENT_LENGTH', 0))
36 body = bytes(environ['wsgi.input'].read(content_length))

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

44 ('Server-Protocol', environ.get('SERVER_PROTOCOL')),
45 ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER'))
46 ])
47 return [body]
48
49""", 'py_app'
50
51 self.python_application(name, code)
28
29 def test_python_application_simple(self):
30 code, name = """
31
32def application(environ, start_response):
33
34 content_length = int(environ.get('CONTENT_LENGTH', 0))
35 body = bytes(environ['wsgi.input'].read(content_length))

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

43 ('Server-Protocol', environ.get('SERVER_PROTOCOL')),
44 ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER'))
45 ])
46 return [body]
47
48""", 'py_app'
49
50 self.python_application(name, code)
52 self.put('/', self.conf % (self.testdir + '/' + name))
51 self.conf_with_name(name)
53
54 body = 'Test body string.'
55
56 r = unit.TestUnitHTTP.post(headers={
57 'Host': 'localhost',
58 'Content-Type': 'text/html',
59 'Custom-Header': 'blah'
60 }, data=body)

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

83 ('Content-Length', '0'),
84 ('Query-String', environ.get('QUERY_STRING'))
85 ])
86 return []
87
88""", 'py_app'
89
90 self.python_application(name, code)
52
53 body = 'Test body string.'
54
55 r = unit.TestUnitHTTP.post(headers={
56 'Host': 'localhost',
57 'Content-Type': 'text/html',
58 'Custom-Header': 'blah'
59 }, data=body)

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

82 ('Content-Length', '0'),
83 ('Query-String', environ.get('QUERY_STRING'))
84 ])
85 return []
86
87""", 'py_app'
88
89 self.python_application(name, code)
91 self.put('/', self.conf % (self.testdir + '/' + name))
90 self.conf_with_name(name)
92
93 r = unit.TestUnitHTTP.get(uri='/?var1=val1&var2=val2', headers={
94 'Host': 'localhost'
95 })
96
97 self.assertEqual(r.status_code, 200, 'status')
98 headers = dict(r.headers)
99 headers.pop('Server')

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

112 ('Content-Length', '0'),
113 ('Server-Port', environ.get('SERVER_PORT'))
114 ])
115 return []
116
117""", 'py_app'
118
119 self.python_application(name, code)
91
92 r = unit.TestUnitHTTP.get(uri='/?var1=val1&var2=val2', headers={
93 'Host': 'localhost'
94 })
95
96 self.assertEqual(r.status_code, 200, 'status')
97 headers = dict(r.headers)
98 headers.pop('Server')

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

111 ('Content-Length', '0'),
112 ('Server-Port', environ.get('SERVER_PORT'))
113 ])
114 return []
115
116""", 'py_app'
117
118 self.python_application(name, code)
120 self.put('/', self.conf % (self.testdir + '/' + name))
119 self.conf_with_name(name)
121
122 r = unit.TestUnitHTTP.get(headers={'Host': 'localhost'})
123
124 self.assertEqual(r.headers.pop('Server-Port'), '7080',
125 'Server-Port header')
126
127 @unittest.expectedFailure
128 def test_python_application_204_transfer_encoding(self):
129 code, name = """
130
131def application(environ, start_response):
132
133 start_response('204 No Content', [])
134 return []
135
136""", 'py_app'
137
138 self.python_application(name, code)
120
121 r = unit.TestUnitHTTP.get(headers={'Host': 'localhost'})
122
123 self.assertEqual(r.headers.pop('Server-Port'), '7080',
124 'Server-Port header')
125
126 @unittest.expectedFailure
127 def test_python_application_204_transfer_encoding(self):
128 code, name = """
129
130def application(environ, start_response):
131
132 start_response('204 No Content', [])
133 return []
134
135""", 'py_app'
136
137 self.python_application(name, code)
139 self.put('/', self.conf % (self.testdir + '/' + name))
138 self.conf_with_name(name)
140
141 r = unit.TestUnitHTTP.get(headers={'Host': 'localhost'})
142 self.assertNotIn('Transfer-Encoding', r.headers,
143 '204 header transfer encoding')
144
145if __name__ == '__main__':
146 unittest.main()
139
140 r = unit.TestUnitHTTP.get(headers={'Host': 'localhost'})
141 self.assertNotIn('Transfer-Encoding', r.headers,
142 '204 header transfer encoding')
143
144if __name__ == '__main__':
145 unittest.main()