Deleted
Added
test_python_application.py (497:27ae0b003f82) | test_python_application.py (503:d7eb78307759) |
---|---|
1import unittest 2import unit 3 4class TestUnitApplication(unit.TestUnitControl): 5 6 def setUpClass(): 7 u = unit.TestUnit() 8 --- 21 unchanged lines hidden (view full) --- 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)) 37 | 1import unittest 2import unit 3 4class TestUnitApplication(unit.TestUnitControl): 5 6 def setUpClass(): 7 u = unit.TestUnit() 8 --- 21 unchanged lines hidden (view full) --- 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)) 37 |
38 start_response('200 OK', [ | 38 start_response('200', [ |
39 ('Content-Type', environ.get('CONTENT_TYPE')), 40 ('Content-Length', str(len(body))), 41 ('Request-Method', environ.get('REQUEST_METHOD')), 42 ('Request-Uri', environ.get('REQUEST_URI')), | 39 ('Content-Type', environ.get('CONTENT_TYPE')), 40 ('Content-Length', str(len(body))), 41 ('Request-Method', environ.get('REQUEST_METHOD')), 42 ('Request-Uri', environ.get('REQUEST_URI')), |
43 ('Path-Info', environ.get('PATH_INFO')), | |
44 ('Http-Host', environ.get('HTTP_HOST')), | 43 ('Http-Host', environ.get('HTTP_HOST')), |
45 ('Remote-Addr', environ.get('REMOTE_ADDR')), 46 ('Server-Name', environ.get('SERVER_NAME')), | |
47 ('Server-Protocol', environ.get('SERVER_PROTOCOL')), 48 ('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')) 49 ]) 50 return [body] 51 52""", 'py_app' 53 54 self.python_application(name, code) --- 11 unchanged lines hidden (view full) --- 66 headers = dict(r.headers) 67 self.assertRegex(headers.pop('Server'), r'unit/[\d\.]+', 68 'server header') 69 self.assertDictEqual(headers, { 70 'Content-Length': str(len(body)), 71 'Content-Type': 'text/html', 72 'Request-Method': 'POST', 73 'Request-Uri': '/', | 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) --- 11 unchanged lines hidden (view full) --- 63 headers = dict(r.headers) 64 self.assertRegex(headers.pop('Server'), r'unit/[\d\.]+', 65 'server header') 66 self.assertDictEqual(headers, { 67 'Content-Length': str(len(body)), 68 'Content-Type': 'text/html', 69 'Request-Method': 'POST', 70 'Request-Uri': '/', |
74 'Path-Info': '/', | |
75 'Http-Host': 'localhost', | 71 'Http-Host': 'localhost', |
76 'Server-Name': 'localhost', 77 'Remote-Addr': '127.0.0.1', | |
78 'Server-Protocol': 'HTTP/1.1', 79 'Custom-Header': 'blah' 80 }, 'headers') | 72 'Server-Protocol': 'HTTP/1.1', 73 'Custom-Header': 'blah' 74 }, 'headers') |
81 self.assertEqual(r.content, str.encode(body), 'body') | 75 self.assertEqual(r.content, body.encode(), 'body') |
82 83 def test_python_application_query_string(self): 84 code, name = """ 85 86def application(environ, start_response): 87 | 76 77 def test_python_application_query_string(self): 78 code, name = """ 79 80def application(environ, start_response): 81 |
88 start_response('200 OK', [ | 82 start_response('200', [ |
89 ('Content-Length', '0'), | 83 ('Content-Length', '0'), |
90 ('Request-Method', environ.get('REQUEST_METHOD')), 91 ('Request-Uri', environ.get('REQUEST_URI')), 92 ('Path-Info', environ.get('PATH_INFO')), | |
93 ('Query-String', environ.get('QUERY_STRING')) 94 ]) 95 return [] 96 97""", 'py_app' 98 99 self.python_application(name, code) 100 self.put('/', self.conf % (self.testdir + '/' + name)) 101 102 r = unit.TestUnitHTTP.get(uri='/?var1=val1&var2=val2', headers={ 103 'Host': 'localhost' 104 }) 105 106 self.assertEqual(r.status_code, 200, 'status') 107 headers = dict(r.headers) 108 headers.pop('Server') 109 self.assertDictEqual(headers, { 110 'Content-Length': '0', | 84 ('Query-String', environ.get('QUERY_STRING')) 85 ]) 86 return [] 87 88""", 'py_app' 89 90 self.python_application(name, code) 91 self.put('/', self.conf % (self.testdir + '/' + 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') 100 self.assertDictEqual(headers, { 101 'Content-Length': '0', |
111 'Request-Method': 'GET', 112 'Query-String': 'var1=val1&var2=val2', 113 'Request-Uri': '/?var1=val1&var2=val2', 114 'Path-Info': '/' | 102 'Query-String': 'var1=val1&var2=val2' |
115 }, 'headers') 116 117 @unittest.expectedFailure 118 def test_python_application_server_port(self): 119 code, name = """ 120 121def application(environ, start_response): 122 | 103 }, 'headers') 104 105 @unittest.expectedFailure 106 def test_python_application_server_port(self): 107 code, name = """ 108 109def application(environ, start_response): 110 |
123 start_response('200 OK', [ 124 ('Content-Type', 'text/html'), | 111 start_response('200', [ 112 ('Content-Length', '0'), |
125 ('Server-Port', environ.get('SERVER_PORT')) 126 ]) 127 return [] 128 129""", 'py_app' 130 131 self.python_application(name, code) 132 self.put('/', self.conf % (self.testdir + '/' + name)) --- 26 unchanged lines hidden --- | 113 ('Server-Port', environ.get('SERVER_PORT')) 114 ]) 115 return [] 116 117""", 'py_app' 118 119 self.python_application(name, code) 120 self.put('/', self.conf % (self.testdir + '/' + name)) --- 26 unchanged lines hidden --- |