Deleted
Added
test_ruby_application.py (970:2f4376c8f358) | test_ruby_application.py (1017:887a4bbabf1e) |
---|---|
1import unittest 2import unit 3 | 1import unittest 2import unit 3 |
4class TestUnitRubyApplication(unit.TestUnitApplicationRuby): | |
5 | 4 |
5class TestUnitRubyApplication(unit.TestUnitApplicationRuby): |
|
6 def setUpClass(): 7 unit.TestUnit().check_modules('ruby') 8 9 def test_ruby_application(self): 10 self.load('variables') 11 12 body = 'Test body string.' 13 | 6 def setUpClass(): 7 unit.TestUnit().check_modules('ruby') 8 9 def test_ruby_application(self): 10 self.load('variables') 11 12 body = 'Test body string.' 13 |
14 resp = self.post(headers={ 15 'Host': 'localhost', 16 'Content-Type': 'text/html', 17 'Custom-Header': 'blah', 18 'Connection': 'close' 19 }, body=body) | 14 resp = self.post( 15 headers={ 16 'Host': 'localhost', 17 'Content-Type': 'text/html', 18 'Custom-Header': 'blah', 19 'Connection': 'close', 20 }, 21 body=body, 22 ) |
20 21 self.assertEqual(resp['status'], 200, 'status') 22 headers = resp['headers'] 23 header_server = headers.pop('Server') 24 self.assertRegex(header_server, r'Unit/[\d\.]+', 'server header') | 23 24 self.assertEqual(resp['status'], 200, 'status') 25 headers = resp['headers'] 26 header_server = headers.pop('Server') 27 self.assertRegex(header_server, r'Unit/[\d\.]+', 'server header') |
25 self.assertEqual(headers.pop('Server-Software'), header_server, 26 'server software header') | 28 self.assertEqual( 29 headers.pop('Server-Software'), 30 header_server, 31 'server software header', 32 ) |
27 28 date = headers.pop('Date') 29 self.assertEqual(date[-4:], ' GMT', 'date header timezone') | 33 34 date = headers.pop('Date') 35 self.assertEqual(date[-4:], ' GMT', 'date header timezone') |
30 self.assertLess(abs(self.date_to_sec_epoch(date) - self.sec_epoch()), 5, 31 'date header') | 36 self.assertLess( 37 abs(self.date_to_sec_epoch(date) - self.sec_epoch()), 38 5, 39 'date header', 40 ) |
32 | 41 |
33 self.assertDictEqual(headers, { 34 'Connection': 'close', 35 'Content-Length': str(len(body)), 36 'Content-Type': 'text/html', 37 'Request-Method': 'POST', 38 'Request-Uri': '/', 39 'Http-Host': 'localhost', 40 'Server-Protocol': 'HTTP/1.1', 41 'Custom-Header': 'blah', 42 'Rack-Version': '13', 43 'Rack-Url-Scheme': 'http', 44 'Rack-Multithread': 'false', 45 'Rack-Multiprocess': 'true', 46 'Rack-Run-Once': 'false', 47 'Rack-Hijack-Q': 'false', 48 'Rack-Hijack': '', 49 'Rack-Hijack-IO': '' 50 }, 'headers') | 42 self.assertDictEqual( 43 headers, 44 { 45 'Connection': 'close', 46 'Content-Length': str(len(body)), 47 'Content-Type': 'text/html', 48 'Request-Method': 'POST', 49 'Request-Uri': '/', 50 'Http-Host': 'localhost', 51 'Server-Protocol': 'HTTP/1.1', 52 'Custom-Header': 'blah', 53 'Rack-Version': '13', 54 'Rack-Url-Scheme': 'http', 55 'Rack-Multithread': 'false', 56 'Rack-Multiprocess': 'true', 57 'Rack-Run-Once': 'false', 58 'Rack-Hijack-Q': 'false', 59 'Rack-Hijack': '', 60 'Rack-Hijack-IO': '', 61 }, 62 'headers', 63 ) |
51 self.assertEqual(resp['body'], body, 'body') 52 53 def test_ruby_application_query_string(self): 54 self.load('query_string') 55 56 resp = self.get(url='/?var1=val1&var2=val2') 57 | 64 self.assertEqual(resp['body'], body, 'body') 65 66 def test_ruby_application_query_string(self): 67 self.load('query_string') 68 69 resp = self.get(url='/?var1=val1&var2=val2') 70 |
58 self.assertEqual(resp['headers']['Query-String'], 'var1=val1&var2=val2', 59 'Query-String header') | 71 self.assertEqual( 72 resp['headers']['Query-String'], 73 'var1=val1&var2=val2', 74 'Query-String header', 75 ) |
60 61 def test_ruby_application_query_string_empty(self): 62 self.load('query_string') 63 64 resp = self.get(url='/?') 65 66 self.assertEqual(resp['status'], 200, 'query string empty status') | 76 77 def test_ruby_application_query_string_empty(self): 78 self.load('query_string') 79 80 resp = self.get(url='/?') 81 82 self.assertEqual(resp['status'], 200, 'query string empty status') |
67 self.assertEqual(resp['headers']['Query-String'], '', 68 'query string empty') | 83 self.assertEqual( 84 resp['headers']['Query-String'], '', 'query string empty' 85 ) |
69 70 @unittest.expectedFailure 71 def test_ruby_application_query_string_absent(self): 72 self.load('query_string') 73 74 resp = self.get() 75 76 self.assertEqual(resp['status'], 200, 'query string absent status') | 86 87 @unittest.expectedFailure 88 def test_ruby_application_query_string_absent(self): 89 self.load('query_string') 90 91 resp = self.get() 92 93 self.assertEqual(resp['status'], 200, 'query string absent status') |
77 self.assertEqual(resp['headers']['Query-String'], '', 78 'query string absent') | 94 self.assertEqual( 95 resp['headers']['Query-String'], '', 'query string absent' 96 ) |
79 80 @unittest.expectedFailure 81 def test_ruby_application_server_port(self): 82 self.load('server_port') 83 | 97 98 @unittest.expectedFailure 99 def test_ruby_application_server_port(self): 100 self.load('server_port') 101 |
84 self.assertEqual(self.get()['headers']['Server-Port'], '7080', 85 'Server-Port header') | 102 self.assertEqual( 103 self.get()['headers']['Server-Port'], '7080', 'Server-Port header' 104 ) |
86 87 def test_ruby_application_status_int(self): 88 self.load('status_int') 89 90 self.assertEqual(self.get()['status'], 200, 'status int') 91 92 def test_ruby_application_input_read_empty(self): 93 self.load('input_read_empty') 94 95 self.assertEqual(self.get()['body'], '', 'read empty') 96 97 def test_ruby_application_input_read_parts(self): 98 self.load('input_read_parts') 99 | 105 106 def test_ruby_application_status_int(self): 107 self.load('status_int') 108 109 self.assertEqual(self.get()['status'], 200, 'status int') 110 111 def test_ruby_application_input_read_empty(self): 112 self.load('input_read_empty') 113 114 self.assertEqual(self.get()['body'], '', 'read empty') 115 116 def test_ruby_application_input_read_parts(self): 117 self.load('input_read_parts') 118 |
100 self.assertEqual(self.post(body='0123456789')['body'], '012345678', 101 'input read parts') | 119 self.assertEqual( 120 self.post(body='0123456789')['body'], 121 '012345678', 122 'input read parts', 123 ) |
102 103 def test_ruby_application_input_read_buffer(self): 104 self.load('input_read_buffer') 105 | 124 125 def test_ruby_application_input_read_buffer(self): 126 self.load('input_read_buffer') 127 |
106 self.assertEqual(self.post(body='0123456789')['body'], '0123456789', 107 'input read buffer') | 128 self.assertEqual( 129 self.post(body='0123456789')['body'], 130 '0123456789', 131 'input read buffer', 132 ) |
108 109 def test_ruby_application_input_read_buffer_not_empty(self): 110 self.load('input_read_buffer_not_empty') 111 | 133 134 def test_ruby_application_input_read_buffer_not_empty(self): 135 self.load('input_read_buffer_not_empty') 136 |
112 self.assertEqual(self.post(body='0123456789')['body'], '0123456789', 113 'input read buffer not empty') | 137 self.assertEqual( 138 self.post(body='0123456789')['body'], 139 '0123456789', 140 'input read buffer not empty', 141 ) |
114 115 def test_ruby_application_input_gets(self): 116 self.load('input_gets') 117 118 body = '0123456789' 119 120 self.assertEqual(self.post(body=body)['body'], body, 'input gets') 121 122 def test_ruby_application_input_gets_2(self): 123 self.load('input_gets') 124 | 142 143 def test_ruby_application_input_gets(self): 144 self.load('input_gets') 145 146 body = '0123456789' 147 148 self.assertEqual(self.post(body=body)['body'], body, 'input gets') 149 150 def test_ruby_application_input_gets_2(self): 151 self.load('input_gets') 152 |
125 self.assertEqual(self.post(body='01234\n56789\n')['body'], '01234\n', 126 'input gets 2') | 153 self.assertEqual( 154 self.post(body='01234\n56789\n')['body'], '01234\n', 'input gets 2' 155 ) |
127 128 def test_ruby_application_input_gets_all(self): 129 self.load('input_gets_all') 130 131 body = '\n01234\n56789\n\n' 132 133 self.assertEqual(self.post(body=body)['body'], body, 'input gets all') 134 --- 9 unchanged lines hidden (view full) --- 144 self.load('input_rewind') 145 146 body = '0123456789' 147 148 self.assertEqual(self.post(body=body)['body'], body, 'input rewind') 149 150 @unittest.expectedFailure 151 def test_ruby_application_syntax_error(self): | 156 157 def test_ruby_application_input_gets_all(self): 158 self.load('input_gets_all') 159 160 body = '\n01234\n56789\n\n' 161 162 self.assertEqual(self.post(body=body)['body'], body, 'input gets all') 163 --- 9 unchanged lines hidden (view full) --- 173 self.load('input_rewind') 174 175 body = '0123456789' 176 177 self.assertEqual(self.post(body=body)['body'], body, 'input rewind') 178 179 @unittest.expectedFailure 180 def test_ruby_application_syntax_error(self): |
152 self.skip_alerts.extend([ 153 r'Failed to parse rack script', 154 r'syntax error', 155 r'new_from_string', 156 r'parse_file' 157 ]) | 181 self.skip_alerts.extend( 182 [ 183 r'Failed to parse rack script', 184 r'syntax error', 185 r'new_from_string', 186 r'parse_file', 187 ] 188 ) |
158 self.load('syntax_error') 159 160 self.assertEqual(self.get()['status'], 500, 'syntax error') 161 162 def test_ruby_application_errors_puts(self): 163 self.load('errors_puts') 164 165 self.get() 166 167 self.stop() 168 169 self.assertIsNotNone( 170 self.search_in_log(r'\[error\].+Error in application'), | 189 self.load('syntax_error') 190 191 self.assertEqual(self.get()['status'], 500, 'syntax error') 192 193 def test_ruby_application_errors_puts(self): 194 self.load('errors_puts') 195 196 self.get() 197 198 self.stop() 199 200 self.assertIsNotNone( 201 self.search_in_log(r'\[error\].+Error in application'), |
171 'errors puts') | 202 'errors puts', 203 ) |
172 173 def test_ruby_application_errors_puts_int(self): 174 self.load('errors_puts_int') 175 176 self.get() 177 178 self.stop() 179 180 self.assertIsNotNone( | 204 205 def test_ruby_application_errors_puts_int(self): 206 self.load('errors_puts_int') 207 208 self.get() 209 210 self.stop() 211 212 self.assertIsNotNone( |
181 self.search_in_log(r'\[error\].+1234567890'), 182 'errors puts int') | 213 self.search_in_log(r'\[error\].+1234567890'), 'errors puts int' 214 ) |
183 184 def test_ruby_application_errors_write(self): 185 self.load('errors_write') 186 187 self.get() 188 189 self.stop() 190 191 self.assertIsNotNone( 192 self.search_in_log(r'\[error\].+Error in application'), | 215 216 def test_ruby_application_errors_write(self): 217 self.load('errors_write') 218 219 self.get() 220 221 self.stop() 222 223 self.assertIsNotNone( 224 self.search_in_log(r'\[error\].+Error in application'), |
193 'errors write') | 225 'errors write', 226 ) |
194 195 def test_ruby_application_errors_write_to_s_custom(self): 196 self.load('errors_write_to_s_custom') 197 | 227 228 def test_ruby_application_errors_write_to_s_custom(self): 229 self.load('errors_write_to_s_custom') 230 |
198 self.assertEqual(self.get()['status'], 200, 199 'errors write to_s custom') | 231 self.assertEqual(self.get()['status'], 200, 'errors write to_s custom') |
200 201 def test_ruby_application_errors_write_int(self): 202 self.load('errors_write_int') 203 204 self.get() 205 206 self.stop() 207 208 self.assertIsNotNone( | 232 233 def test_ruby_application_errors_write_int(self): 234 self.load('errors_write_int') 235 236 self.get() 237 238 self.stop() 239 240 self.assertIsNotNone( |
209 self.search_in_log(r'\[error\].+1234567890'), 210 'errors write int') | 241 self.search_in_log(r'\[error\].+1234567890'), 'errors write int' 242 ) |
211 212 def test_ruby_application_at_exit(self): 213 self.load('at_exit') 214 215 self.get() 216 | 243 244 def test_ruby_application_at_exit(self): 245 self.load('at_exit') 246 247 self.get() 248 |
217 self.conf({ 218 "listeners": {}, 219 "applications": {} 220 }) | 249 self.conf({"listeners": {}, "applications": {}}) |
221 222 self.stop() 223 224 self.assertIsNotNone( | 250 251 self.stop() 252 253 self.assertIsNotNone( |
225 self.search_in_log(r'\[error\].+At exit called\.'), 'at exit') | 254 self.search_in_log(r'\[error\].+At exit called\.'), 'at exit' 255 ) |
226 227 def test_ruby_application_header_custom(self): 228 self.load('header_custom') 229 230 resp = self.post(body="\ntc=one,two\ntc=three,four,\n\n") 231 | 256 257 def test_ruby_application_header_custom(self): 258 self.load('header_custom') 259 260 resp = self.post(body="\ntc=one,two\ntc=three,four,\n\n") 261 |
232 self.assertEqual(resp['headers']['Custom-Header'], 233 ['', 'tc=one,two', 'tc=three,four,', '', ''], 'header custom') | 262 self.assertEqual( 263 resp['headers']['Custom-Header'], 264 ['', 'tc=one,two', 'tc=three,four,', '', ''], 265 'header custom', 266 ) |
234 235 @unittest.expectedFailure 236 def test_ruby_application_header_custom_non_printable(self): 237 self.load('header_custom') 238 | 267 268 @unittest.expectedFailure 269 def test_ruby_application_header_custom_non_printable(self): 270 self.load('header_custom') 271 |
239 self.assertEqual(self.post(body='\b')['status'], 500, 240 'header custom non printable') | 272 self.assertEqual( 273 self.post(body='\b')['status'], 500, 'header custom non printable' 274 ) |
241 242 def test_ruby_application_header_status(self): 243 self.load('header_status') 244 245 self.assertEqual(self.get()['status'], 200, 'header status') 246 247 @unittest.expectedFailure 248 def test_ruby_application_header_rack(self): --- 23 unchanged lines hidden (view full) --- 272 self.load('body_each_error') 273 274 self.assertEqual(self.get()['status'], 500, 'body each error status') 275 276 self.stop() 277 278 self.assertIsNotNone( 279 self.search_in_log(r'\[error\].+Failed to run ruby script'), | 275 276 def test_ruby_application_header_status(self): 277 self.load('header_status') 278 279 self.assertEqual(self.get()['status'], 200, 'header status') 280 281 @unittest.expectedFailure 282 def test_ruby_application_header_rack(self): --- 23 unchanged lines hidden (view full) --- 306 self.load('body_each_error') 307 308 self.assertEqual(self.get()['status'], 500, 'body each error status') 309 310 self.stop() 311 312 self.assertIsNotNone( 313 self.search_in_log(r'\[error\].+Failed to run ruby script'), |
280 'body each error') | 314 'body each error', 315 ) |
281 282 def test_ruby_application_body_file(self): 283 self.load('body_file') 284 285 self.assertEqual(self.get()['body'], 'body\n', 'body file') 286 287 def test_ruby_keepalive_body(self): 288 self.load('mirror') 289 | 316 317 def test_ruby_application_body_file(self): 318 self.load('body_file') 319 320 self.assertEqual(self.get()['body'], 'body\n', 'body file') 321 322 def test_ruby_keepalive_body(self): 323 self.load('mirror') 324 |
290 (resp, sock) = self.post(headers={ 291 'Host': 'localhost', 292 'Connection': 'keep-alive', 293 'Content-Type': 'text/html' 294 }, start=True, body='0123456789' * 500) | 325 (resp, sock) = self.post( 326 headers={ 327 'Host': 'localhost', 328 'Connection': 'keep-alive', 329 'Content-Type': 'text/html', 330 }, 331 start=True, 332 body='0123456789' * 500, 333 ) |
295 296 self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') 297 | 334 335 self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') 336 |
298 resp = self.post(headers={ 299 'Host': 'localhost', 300 'Connection': 'close', 301 'Content-Type': 'text/html' 302 }, sock=sock, body='0123456789') | 337 resp = self.post( 338 headers={ 339 'Host': 'localhost', 340 'Connection': 'close', 341 'Content-Type': 'text/html', 342 }, 343 sock=sock, 344 body='0123456789', 345 ) |
303 304 self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') 305 | 346 347 self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') 348 |
349 |
|
306if __name__ == '__main__': 307 TestUnitRubyApplication.main() | 350if __name__ == '__main__': 351 TestUnitRubyApplication.main() |