diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/test_environ.py | 36 | ||||
-rwxr-xr-x | test/test_outputfilter.py | 18 | ||||
-rwxr-xr-x | test/test_sendfile.py | 18 | ||||
-rwxr-xr-x | test/test_wsgi.py | 6 |
4 files changed, 39 insertions, 39 deletions
diff --git a/test/test_environ.py b/test/test_environ.py index b761f48..434d168 100755 --- a/test/test_environ.py +++ b/test/test_environ.py @@ -74,7 +74,7 @@ class TestRequest(unittest.TestCase): self.assertEqual(['/', '/a/b/c/d/'], test_shift('/a/b/c/d', '/', -4)) self.assertRaises(AssertionError, test_shift, '/a/b', '/c/d', 3) self.assertRaises(AssertionError, test_shift, '/a/b', '/c/d', -3) - + def test_url(self): """ Environ: URL building """ request = BaseRequest({'HTTP_HOST':'example.com'}) @@ -122,7 +122,7 @@ class TestRequest(unittest.TestCase): self.assertTrue('Some-Header' in request.headers) self.assertTrue(request.headers['Some-Header'] == 'some value') self.assertTrue(request.headers['Some-Other-Header'] == 'some other value') - + def test_header_access_special(self): e = {} wsgiref.util.setup_testing_defaults(e) @@ -133,7 +133,7 @@ class TestRequest(unittest.TestCase): self.assertEqual(request.headers['Content-Length'], '123') def test_cookie_dict(self): - """ Environ: Cookie dict """ + """ Environ: Cookie dict """ t = dict() t['a=a'] = {'a': 'a'} t['a=a; b=b'] = {'a': 'a', 'b':'b'} @@ -145,7 +145,7 @@ class TestRequest(unittest.TestCase): self.assertEqual(v[n], request.get_cookie(n)) def test_get(self): - """ Environ: GET data """ + """ Environ: GET data """ qs = tonat(tob('a=a&a=1&b=b&c=c&cn=%e7%93%b6'), 'latin1') request = BaseRequest({'QUERY_STRING':qs}) self.assertTrue('a' in request.query) @@ -156,9 +156,9 @@ class TestRequest(unittest.TestCase): self.assertEqual('b', request.query['b']) self.assertEqual(tonat(tob('瓶'), 'latin1'), request.query['cn']) self.assertEqual(touni('瓶'), request.query.cn) - + def test_post(self): - """ Environ: POST data """ + """ Environ: POST data """ sq = tob('a=a&a=1&b=b&c=&d&cn=%e7%93%b6') e = {} wsgiref.util.setup_testing_defaults(e) @@ -204,7 +204,7 @@ class TestRequest(unittest.TestCase): self.assertEqual(sq, request.body.read()) def test_params(self): - """ Environ: GET and POST are combined in request.param """ + """ Environ: GET and POST are combined in request.param """ e = {} wsgiref.util.setup_testing_defaults(e) e['wsgi.input'].write(tob('b=b&c=p')) @@ -217,7 +217,7 @@ class TestRequest(unittest.TestCase): self.assertEqual('p', request.params['c']) def test_getpostleak(self): - """ Environ: GET and POST should not leak into each other """ + """ Environ: GET and POST should not leak into each other """ e = {} wsgiref.util.setup_testing_defaults(e) e['wsgi.input'].write(tob('b=b')) @@ -230,7 +230,7 @@ class TestRequest(unittest.TestCase): self.assertEqual(['b'], list(request.POST.keys())) def test_body(self): - """ Environ: Request.body should behave like a file object factory """ + """ Environ: Request.body should behave like a file object factory """ e = {} wsgiref.util.setup_testing_defaults(e) e['wsgi.input'].write(tob('abc')) @@ -250,7 +250,7 @@ class TestRequest(unittest.TestCase): e['wsgi.input'].seek(0) e['CONTENT_LENGTH'] = str(1024*1000) request = BaseRequest(e) - self.assertTrue(hasattr(request.body, 'fileno')) + self.assertTrue(hasattr(request.body, 'fileno')) self.assertEqual(1024*1000, len(request.body.read())) self.assertEqual(1024, len(request.body.read(1024))) self.assertEqual(1024*1000, len(request.body.readline())) @@ -492,7 +492,7 @@ class TestResponse(unittest.TestCase): def test_content_type(self): rs = BaseResponse() rs.content_type = 'test/some' - self.assertEquals('test/some', rs.headers.get('Content-Type')) + self.assertEquals('test/some', rs.headers.get('Content-Type')) def test_charset(self): rs = BaseResponse() @@ -553,7 +553,7 @@ class TestResponse(unittest.TestCase): if name.title() == 'X-Test'] self.assertEqual(['bar'], headers) self.assertEqual('bar', response['x-test']) - + def test_append_header(self): response = BaseResponse() response.set_header('x-test', 'foo') @@ -562,7 +562,7 @@ class TestResponse(unittest.TestCase): self.assertEqual(['foo'], headers) self.assertEqual('foo', response['x-test']) - response.set_header('X-Test', 'bar', True) + response.add_header('X-Test', 'bar') headers = [value for name, value in response.headerlist if name.title() == 'X-Test'] self.assertEqual(['foo', 'bar'], headers) @@ -585,10 +585,10 @@ class TestResponse(unittest.TestCase): class TestRedirect(unittest.TestCase): - + def assertRedirect(self, target, result, query=None, status=303, **args): env = {'SERVER_PROTOCOL':'HTTP/1.1'} - for key in args: + for key in list(args): if key.startswith('wsgi'): args[key.replace('_', '.', 1)] = args[key] del args[key] @@ -598,7 +598,7 @@ class TestRedirect(unittest.TestCase): bottle.redirect(target, **(query or {})) except bottle.HTTPResponse: r = _e() - self.assertEqual(status, r.status) + self.assertEqual(status, r.status_code) self.assertTrue(r.headers) self.assertEqual(result, r.headers['Location']) @@ -641,7 +641,7 @@ class TestRedirect(unittest.TestCase): SCRIPT_NAME='/foo/', PATH_INFO='/bar/baz.html') self.assertRedirect('../baz/../test.html', 'http://127.0.0.1/foo/test.html', PATH_INFO='/foo/bar/') - + def test_sheme(self): self.assertRedirect('./test.html', 'https://127.0.0.1/test.html', wsgi_url_scheme='https') @@ -679,7 +679,7 @@ class TestRedirect(unittest.TestCase): self.assertRedirect('./te st.html', 'http://example.com/a%20a/b%20b/te st.html', HTTP_HOST='example.com', SCRIPT_NAME='/a a/', PATH_INFO='/b b/') - + class TestWSGIHeaderDict(unittest.TestCase): def setUp(self): self.env = {} diff --git a/test/test_outputfilter.py b/test/test_outputfilter.py index fb282cf..48b15f0 100755 --- a/test/test_outputfilter.py +++ b/test/test_outputfilter.py @@ -94,7 +94,7 @@ class TestOutputFilter(ServerTestBase): yield 'foo' self.assertBody('foo') self.assertHeader('Test-Header', 'test') - + def test_empty_generator_callback(self): @self.app.route('/') def test(): @@ -102,7 +102,7 @@ class TestOutputFilter(ServerTestBase): bottle.response.headers['Test-Header'] = 'test' self.assertBody('') self.assertHeader('Test-Header', 'test') - + def test_error_in_generator_callback(self): @self.app.route('/') def test(): @@ -113,7 +113,7 @@ class TestOutputFilter(ServerTestBase): def test_fatal_error_in_generator_callback(self): @self.app.route('/') def test(): - yield + yield raise KeyboardInterrupt() self.assertRaises(KeyboardInterrupt, self.assertStatus, 500) @@ -123,28 +123,28 @@ class TestOutputFilter(ServerTestBase): yield bottle.abort(404, 'teststring') self.assertInBody('teststring') - self.assertInBody('Error 404: Not Found') + self.assertInBody('404 Not Found') self.assertStatus(404) def test_httpresponse_in_generator_callback(self): @self.app.route('/') def test(): yield bottle.HTTPResponse('test') - self.assertBody('test') - + self.assertBody('test') + def test_unicode_generator_callback(self): @self.app.route('/') def test(): yield touni('äöüß') - self.assertBody(touni('äöüß').encode('utf8')) - + self.assertBody(touni('äöüß').encode('utf8')) + def test_invalid_generator_callback(self): @self.app.route('/') def test(): yield 1234 self.assertStatus(500) self.assertInBody('Unsupported response type') - + def test_cookie(self): """ WSGI: Cookies """ @bottle.route('/cookie') diff --git a/test/test_sendfile.py b/test/test_sendfile.py index bf951f5..9d708e4 100755 --- a/test/test_sendfile.py +++ b/test/test_sendfile.py @@ -42,17 +42,17 @@ class TestSendFile(unittest.TestCase): def test_valid(self): """ SendFile: Valid requests""" out = static_file(os.path.basename(__file__), root='./') - self.assertEqual(open(__file__,'rb').read(), out.output.read()) + self.assertEqual(open(__file__,'rb').read(), out.body.read()) def test_invalid(self): """ SendFile: Invalid requests""" - self.assertEqual(404, static_file('not/a/file', root='./').status) + self.assertEqual(404, static_file('not/a/file', root='./').status_code) f = static_file(os.path.join('./../', os.path.basename(__file__)), root='./views/') - self.assertEqual(403, f.status) + self.assertEqual(403, f.status_code) try: fp, fn = tempfile.mkstemp() os.chmod(fn, 0) - self.assertEqual(403, static_file(fn, root='/').status) + self.assertEqual(403, static_file(fn, root='/').status_code) finally: os.close(fp) os.unlink(fn) @@ -70,7 +70,7 @@ class TestSendFile(unittest.TestCase): request.environ['HTTP_IF_MODIFIED_SINCE'] = \ time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()) res = static_file(os.path.basename(__file__), root='./') - self.assertEqual(304, res.status) + self.assertEqual(304, res.status_code) self.assertEqual(int(os.stat(__file__).st_mtime), parse_date(res.headers['Last-Modified'])) self.assertAlmostEqual(int(time.time()), @@ -78,7 +78,7 @@ class TestSendFile(unittest.TestCase): with self.context: request.environ['HTTP_IF_MODIFIED_SINCE'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(100)) res = static_file(os.path.basename(__file__), root='./') - self.assertEqual(open(__file__,'rb').read(), res.output.read()) + self.assertEqual(open(__file__,'rb').read(), res.body.read()) def test_download(self): """ SendFile: Download as attachment """ @@ -89,7 +89,7 @@ class TestSendFile(unittest.TestCase): request.environ['HTTP_IF_MODIFIED_SINCE'] =\ time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(100)) f = static_file(os.path.basename(__file__), root='./') - self.assertEqual(open(__file__,'rb').read(), f.output.read()) + self.assertEqual(open(__file__,'rb').read(), f.body.read()) def test_range(self): basename = os.path.basename(__file__) @@ -97,11 +97,11 @@ class TestSendFile(unittest.TestCase): request.environ['HTTP_RANGE'] = 'bytes=10-25,-80' f = static_file(basename, root='./') c = open(basename, 'rb'); c.seek(10) - self.assertEqual(c.read(16), tob('').join(f.output)) + self.assertEqual(c.read(16), tob('').join(f.body)) self.assertEqual('bytes 10-25/%d' % len(open(basename, 'rb').read()), f.headers['Content-Range']) self.assertEqual('bytes', f.headers['Accept-Ranges']) - + def test_range_parser(self): r = lambda rs: list(parse_range_header(rs, 100)) self.assertEqual([(90, 100)], r('bytes=-10')) diff --git a/test/test_wsgi.py b/test/test_wsgi.py index 318e0ca..8c451b8 100755 --- a/test/test_wsgi.py +++ b/test/test_wsgi.py @@ -92,12 +92,12 @@ class TestWsgi(ServerTestBase): """ WSGI: abort(401, '') (HTTP 401) """ @bottle.route('/') def test(): bottle.abort(401) - self.assertStatus(401,'/') + self.assertStatus(401, '/') @bottle.error(401) def err(e): bottle.response.status = 200 return str(type(e)) - self.assertStatus(200,'/') + self.assertStatus(200, '/') self.assertBody("<class 'bottle.HTTPError'>",'/') def test_303(self): @@ -281,7 +281,7 @@ class TestDecorators(ServerTestBase): def test(): return bottle.HTTPError(401, 'The cake is a lie!') self.assertInBody('The cake is a lie!', '/tpl') - self.assertInBody('401: Unauthorized', '/tpl') + self.assertInBody('401 Unauthorized', '/tpl') self.assertStatus(401, '/tpl') def test_truncate_body(self): |