def test_generic_filter(): req_mock = RequestMock() resp_mock = ResponseMock() bridge = RequestBridge(req_mock, AdaptedInputStream(), AdaptedErrLog()) bridge_map = dict_builder(bridge.asMap)() req_wrapper = bridge.asWrapper() filter = WSGIFilter() filter.init( ServletConfigMock( #{ "wsgi.handler": "test_generic_middleware.AuthenticationMiddleware" })) {"wsgi.handler": "test_generic_middleware.Uppercaser"})) class UnitChain(FilterChain): def doFilter(self, req, resp): resp.addHeader("Content-Type", "text/plain") resp.outputStream.write("hi, ") resp.outputStream.write("there!\n") resp.outputStream.close() filter.doFilter(req_wrapper, resp_mock, UnitChain()) assert next(resp_mock.outputStream) == b"hi, " assert next(resp_mock.outputStream) == b"THERE!\n" assert resp_mock.getHeaders("Content-Type") == ["text/plain"] assert resp_mock.getStatus() == 200
def test_webob_filter(): req_mock = RequestMock() resp_mock = ResponseMock() bridge = RequestBridge(req_mock, AdaptedInputStream(), AdaptedErrLog()) bridge_map = dict_builder(bridge.asMap)() req_wrapper = bridge.asWrapper() filter = WSGIFilter() filter.init(ServletConfigMock( { "wsgi.handler": "test_webob_middleware.all_caps" })) class UnitChain(FilterChain): def doFilter(self, req, resp): resp.addHeader('Content-Type', 'text/plain') resp.outputStream.write("hi, ") resp.outputStream.write("there!\n") filter.doFilter(req_wrapper, resp_mock, UnitChain()) assert next(resp_mock.outputStream) == b"HI, THERE!\n" assert resp_mock.getHeader('Content-Type') == 'text/plain' assert resp_mock.getHeader('Content-Length') == '11' assert resp_mock.getStatus() == 200
def test_generic_filter(): req_mock = RequestMock() resp_mock = ResponseMock() bridge = RequestBridge(req_mock, AdaptedInputStream(), AdaptedErrLog()) bridge_map = dict_builder(bridge.asMap)() req_wrapper = bridge.asWrapper() filter = WSGIFilter() filter.init(ServletConfigMock( #{ "wsgi.handler": "test_generic_middleware.AuthenticationMiddleware" })) { "wsgi.handler": "test_generic_middleware.Uppercaser" })) class UnitChain(FilterChain): def doFilter(self, req, resp): resp.addHeader("Content-Type", "text/plain") resp.outputStream.write("hi, ") resp.outputStream.write("there!\n") resp.outputStream.close() filter.doFilter(req_wrapper, resp_mock, UnitChain()) assert next(resp_mock.outputStream) == b"hi, " assert next(resp_mock.outputStream) == b"THERE!\n" assert resp_mock.getHeaders("Content-Type") == ["text/plain"] assert resp_mock.getStatus() == 200
def test_webob_filter(): req_mock = RequestMock() resp_mock = ResponseMock() bridge = RequestBridge(req_mock, AdaptedInputStream(), AdaptedErrLog()) bridge_map = dict_builder(bridge.asMap)() req_wrapper = bridge.asWrapper() filter = WSGIFilter() filter.init( ServletConfigMock({"wsgi.handler": "test_webob_middleware.all_caps"})) class UnitChain(FilterChain): def doFilter(self, req, resp): resp.addHeader('Content-Type', 'text/plain') resp.outputStream.write("hi, ") resp.outputStream.write("there!\n") filter.doFilter(req_wrapper, resp_mock, UnitChain()) assert next(resp_mock.outputStream) == b"HI, THERE!\n" assert resp_mock.getHeader('Content-Type') == 'text/plain' assert resp_mock.getHeader('Content-Length') == '11' assert resp_mock.getStatus() == 200