def test_it_handles_routing_redirects(self): self.mapper.add(b"/<int:year>/", view) request = Request(url=URL(path=b"/2013")) render = self.mapper.map(request, path=b"/2013") self.assertEqual( render(request), redirect(b"http:///2013/", code=301), )
def map(self, request, path): try: render, kwargs = self._adapter.match( path_info=request.url.path, method=request.method, ) except werkzeug.routing.RequestRedirect as redirect_exception: return lambda request : redirect( to=redirect_exception.new_url, code=redirect_exception.code, ) except werkzeug.routing.HTTPException: return None else: if kwargs: render = partial(render, **kwargs) return render
def map(self, request, path): try: render, kwargs = self._adapter.match( path_info=request.url.to_text(), method=request.method, ) except werkzeug.routing.RequestRedirect as redirect_exception: return lambda request: redirect( to=redirect_exception.new_url, code=redirect_exception.code, ) except werkzeug.routing.HTTPException: return None else: if kwargs: render = partial(render, **kwargs) return render
def test_it_allows_specifying_a_status_code(self): response = request.redirect(to="http://example.com", code=304) self.assertRedirected(response, "http://example.com", code=304)
def test_it_returns_redirect_responses(self): response = request.redirect(to="http://example.com") self.assertRedirected(response, "http://example.com")