def test_ForwardRequest_factory():

    from paste.errordocument import StatusKeeper

    class TestForwardRequestMiddleware(Middleware):
        def __call__(self, environ, start_response):
            if environ['PATH_INFO'] != '/not_found':
                return self.app(environ, start_response)
            environ['PATH_INFO'] = self.url
            def factory(app):
                return StatusKeeper(app, status='404 Not Found', url='/error', headers=[])
            raise ForwardRequestException(factory=factory)

    app = TestForwardRequestMiddleware(error_docs_app)
    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' # Different status
    assert 'Page not found' in res
    try:
        res = app.get('/recurse')
    except __HOLE__ as e:
        if str(e).startswith('Forwarding loop detected'):
            pass
        else:
            raise AssertionError('Failed to detect forwarding loop')

# Test Deprecated Code
dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/Paste-2.0.1/tests/test_recursive.py/test_ForwardRequest_factory