def test_multiline(self): result = parse(['/foo exact http://giraffe.com/bar', '/bar prefix http://elephant.org/', '/baz/bat internal-exact tapir', '/qux internal-prefix donkey']) assert result == [ Redirect(src='/foo', dst='http://giraffe.com/bar', internal=False, prefix=False), Redirect(src='/bar', dst='http://elephant.org/', internal=False, prefix=True), Redirect(src='/baz/bat', dst='tapir', internal=True, prefix=False), Redirect(src='/qux', dst='donkey', internal=True, prefix=True), ]
def test_ordering_indicates_priority(self, pyramid_request): """ Earlier matching redirect specifications should be chosen over later ones. """ pyramid_request.path = '/foo/bar' redirects = [ Redirect(src='/foo', dst='http://giraffe.com', internal=False, prefix=True), Redirect(src='/foo/bar', dst='http://elephant.com', internal=False, prefix=False), ] result = lookup(redirects, pyramid_request) assert result == 'http://giraffe.com/bar'
def test_internal_prefix(self, pyramid_request): pyramid_request.path = "/foo/bar" redirects = [Redirect(src="/foo", dst="donkey", internal=True, prefix=True)] result = lookup(redirects, pyramid_request) assert result == "http://example.com/donkey/bar"
def test_basic(self): result = parse(["/foo exact http://giraffe.com/bar"]) assert result == [ Redirect( src="/foo", dst="http://giraffe.com/bar", internal=False, prefix=False ) ]
def test_internal_prefix(self, pyramid_request): pyramid_request.path = '/foo/bar' redirects = [ Redirect(src='/foo', dst='donkey', internal=True, prefix=True), ] result = lookup(redirects, pyramid_request) assert result == 'http://example.com/donkey/bar'
def test_basic(self): result = parse(['/foo exact http://giraffe.com/bar']) assert result == [ Redirect(src='/foo', dst='http://giraffe.com/bar', internal=False, prefix=False), ]
def test_prefix(self, pyramid_request): pyramid_request.path = '/foo/bar' redirects = [ Redirect(src='/foo', dst='http://giraffe.com', internal=False, prefix=True), ] result = lookup(redirects, pyramid_request) assert result == 'http://giraffe.com/bar'
def test_none_when_no_match(self, pyramid_request): pyramid_request.path = '/bar' redirects = [ Redirect(src='/foo', dst='http://giraffe.com/bar', internal=False, prefix=False), ] result = lookup(redirects, pyramid_request) assert result is None
def test_prefix(self, pyramid_request): pyramid_request.path = "/foo/bar" redirects = [ Redirect(src="/foo", dst="http://giraffe.com", internal=False, prefix=True) ] result = lookup(redirects, pyramid_request) assert result == "http://giraffe.com/bar"
def test_multiline(self): result = parse([ "/foo exact http://giraffe.com/bar", "/bar prefix http://elephant.org/", "/baz/bat internal-exact tapir", "/qux internal-prefix donkey", ]) assert result == [ Redirect(src="/foo", dst="http://giraffe.com/bar", internal=False, prefix=False), Redirect(src="/bar", dst="http://elephant.org/", internal=False, prefix=True), Redirect(src="/baz/bat", dst="tapir", internal=True, prefix=False), Redirect(src="/qux", dst="donkey", internal=True, prefix=True), ]
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_ignores_whitespace(self, data): line = [ data.draw(st.text(alphabet=WHITESPACE)), '/foo', data.draw(st.text(alphabet=WHITESPACE, min_size=1)), 'exact', data.draw(st.text(alphabet=WHITESPACE, min_size=1)), 'http://giraffe.com/bar', data.draw(st.text(alphabet=WHITESPACE)), ] result = parse([''.join(line)]) assert result == [ Redirect(src='/foo', dst='http://giraffe.com/bar', internal=False, prefix=False), ]
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