def test_it_loads_redirects(self, patch): parse_redirects = patch("h.tweens.parse_redirects") tweens.redirect_tween_factory(handler=None, registry=None) parse_redirects.assert_called_once_with( # Check parse_redirects is called with a file like object Any.object.with_attrs({"readlines": Any.callable()}))
def test_tween_redirect_loads_redirects(patch): open_ = patch('h.tweens.open') parse_redirects = patch('h.tweens.parse_redirects') tweens.redirect_tween_factory(handler=None, registry=None) open_.assert_called_once_with('h/redirects', encoding='utf-8') # Parse redirects is called with the value returned by the context manager parse_redirects.assert_called_once_with(open_.return_value.__enter__.return_value)
def test_tween_redirect_loads_redirects(patch): open_ = patch('h.tweens.open') parse_redirects = patch('h.tweens.parse_redirects') tweens.redirect_tween_factory(handler=None, registry=None) open_.assert_called_once_with('h/redirects', encoding='utf-8') # Parse redirects is called with the value returned by the context manager parse_redirects.assert_called_once_with(open_.return_value.__enter__.return_value)
def test_it_loads_redirects(self, patch): open_ = patch("h.tweens.open") parse_redirects = patch("h.tweens.parse_redirects") tweens.redirect_tween_factory(handler=None, registry=None) open_.assert_called_once_with(Any.string.matching("^.*h/redirects$"), encoding="utf-8") # Parse redirects is called with the value returned by the context manager parse_redirects.assert_called_once_with( open_.return_value.__enter__.return_value)
def test_tween_redirect_non_redirected_route(pyramid_request): redirects = [('/foo', 'bar')] pyramid_request.path = '/quux' tween = tweens.redirect_tween_factory(lambda req: req.response, pyramid_request.registry, redirects) response = tween(pyramid_request) assert response.status_code == 200
def test_tween_redirect_non_redirected_route(pyramid_request): redirects = [('/foo', 'bar')] pyramid_request.path = '/quux' tween = tweens.redirect_tween_factory( lambda req: req.response, pyramid_request.registry, redirects) response = tween(pyramid_request) assert response.status_code == 200
def test_tween_redirect_non_redirected_route(pyramid_request): redirects = [ Redirect(src='/foo', dst='http://bar', internal=False, prefix=False) ] pyramid_request.path = '/quux' tween = tweens.redirect_tween_factory(lambda req: req.response, pyramid_request.registry, redirects) response = tween(pyramid_request) assert response.status_code == 200
def test_tween_redirect_redirected_route(pyramid_request, pyramid_config): redirects = [('/foo', 'bar')] pyramid_config.add_route('bar', '/bar') pyramid_request.path = '/foo' tween = tweens.redirect_tween_factory(lambda req: req.response, pyramid_request.registry, redirects) response = tween(pyramid_request) assert response.status_code == 301 assert response.location == 'http://example.com/bar'
def test_it_does_not_redirect_for_non_redirected_routes(self, pyramid_request): redirects = [ Redirect(src="/foo", dst="http://bar", internal=False, prefix=False) ] pyramid_request.path = "/quux" tween = tweens.redirect_tween_factory( lambda req: req.response, pyramid_request.registry, redirects ) response = tween(pyramid_request) assert response.status_code == 200
def test_it_redirects_for_redirected_routes(self, pyramid_request, pyramid_config): redirects = [ Redirect(src="/foo", dst="http://bar", internal=False, prefix=False) ] pyramid_request.path = "/foo" tween = tweens.redirect_tween_factory( lambda req: req.response, pyramid_request.registry, redirects ) response = tween(pyramid_request) assert response.status_code == 301 assert response.location == "http://bar"
def test_tween_redirect_non_redirected_route(pyramid_request): redirects = [ Redirect(src='/foo', dst='http://bar', internal=False, prefix=False) ] pyramid_request.path = '/quux' tween = tweens.redirect_tween_factory( lambda req: req.response, pyramid_request.registry, redirects) response = tween(pyramid_request) assert response.status_code == 200
def test_tween_redirect_redirected_route(pyramid_request, pyramid_config): redirects = [('/foo', 'bar')] pyramid_config.add_route('bar', '/bar') pyramid_request.path = '/foo' tween = tweens.redirect_tween_factory( lambda req: req.response, pyramid_request.registry, redirects) response = tween(pyramid_request) assert response.status_code == 301 assert response.location == 'http://example.com/bar'
def test_it_redirects_for_redirected_routes(self, pyramid_request, pyramid_config): redirects = [ Redirect(src='/foo', dst='http://bar', internal=False, prefix=False) ] pyramid_request.path = '/foo' tween = tweens.redirect_tween_factory( lambda req: req.response, pyramid_request.registry, redirects) response = tween(pyramid_request) assert response.status_code == 301 assert response.location == 'http://bar'
def test_it_does_not_redirect_for_non_redirected_routes( self, pyramid_request): redirects = [ Redirect(src="/foo", dst="http://bar", internal=False, prefix=False) ] pyramid_request.path = "/quux" tween = tweens.redirect_tween_factory(lambda req: req.response, pyramid_request.registry, redirects) response = tween(pyramid_request) assert response.status_code == 200
def test_it_loads_successfully(self): # Don't mock parse_redirects out to check the file actually parses tweens.redirect_tween_factory(handler=None, registry=None)