def test_bad_error(): def app(environ, start_response): start_response('404 Not Found', [('content-type', 'text/plain')]) return ['not found'] app = forward(app, {404: '/404.html'}) app = TestApp(app) resp = app.get('/test', expect_errors=True) print resp
def test_bad_error(): def app(environ, start_response): start_response('404 Not Found', [('content-type', 'text/plain')]) return ['not found'] app = forward(app, {404: '/404.html'}) app = TestApp(app) resp = app.get('/test', expect_errors=True) print(resp)
def test_auth_docs_app(): wsgi_app = forward(auth_docs_app, codes={401: '/auth_doc'}) app = TestApp(wsgi_app) res = app.get('/auth_doc') assert res.header('content-type') == 'text/html' res = app.get('/auth', status=401) assert res.header('content-type') == 'text/html' assert res.header('www-authenticate') == 'Basic realm="Foo"' assert res.body == '<html>Login!</html>'
def test_auth_docs_app(): wsgi_app = forward(auth_docs_app, codes={401: '/auth_doc'}) app = TestApp(wsgi_app) res = app.get('/auth_doc') assert res.header('content-type') == 'text/html' res = app.get('/auth', status=401) assert res.header('content-type') == 'text/html' assert res.header('www-authenticate') == 'Basic realm="Foo"' assert res.body == b'<html>Login!</html>'
def test_forward(): app = forward(error_docs_app, codes={404:'/error'}) app = TestApp(RecursiveMiddleware(app)) res = app.get('') assert res.header('content-type') == 'text/plain' assert res.full_status == '200 OK' assert 'requested page returned' in res res = app.get('/error') assert res.header('content-type') == 'text/plain' assert res.full_status == '200 OK' assert 'Page not found' in res res = app.get('/not_found', status=404) assert res.header('content-type') == 'text/plain' assert res.full_status == '404 Not found' # Note changed response assert 'Page not found' in res
def test_forward(): app = forward(error_docs_app, codes={404: '/error'}) app = TestApp(RecursiveMiddleware(app)) res = app.get('') assert res.header('content-type') == 'text/plain' assert res.full_status == '200 OK' assert 'requested page returned' in res res = app.get('/error') assert res.header('content-type') == 'text/plain' assert res.full_status == '200 OK' assert 'Page not found' in res res = app.get('/not_found', status=404) assert res.header('content-type') == 'text/plain' assert res.full_status == '404 Not found' # Note changed response assert 'Page not found' in res
def foo_app(environ, start_response): """ Foo app, shows some content only if 'foo' found in path, err 404 otherwise """ if 'foo' in environ['PATH_INFO']: start_response('200 OK', [('Content-type', 'text/html')]) content = ['<html><body><h1>Foo app</h1>'] + \ ['<p>We\'ve found <code>foo</code> in path</p>'] else: start_response('404 Not found', [('Content-type', 'text/html')]) content = ['<html><body><h1>404: Not found</h1>'] + \ ['<p>Foo not found in path</p>'] return content def err404_app(environ, start_response): """ Simple WSGI app that shows message '404 error'. Notice that this app must return '200 OK' response """ start_response('200 OK', [('Content-type', 'text/html')]) return ["<html><body><h1>Err 404: Object not found in %s</h1></body></html>" % environ['paste.recursive.old_path_info']] mapping = urlmap.URLMap() mapping['/foo'] = foo_app mapping['/err404'] = err404_app # handle 404 errors by /err404 error_handled = errordocument.forward(mapping, codes={404:'/err404'}) httpserver.serve(error_handled, host="127.0.0.1", port=5000)