def store(self, auth: Auth, request: Request, response: Response): # store register user user = auth.register(request.only("name", "email", "password")) if not user: return response.redirect("/register") return response.redirect("/home")
def store(self, view: View, request: Request, auth: Auth, response: Response): login = auth.attempt(request.input("username"), request.input("password")) if login: return response.redirect(name="home") # Go back to login page return response.redirect(name="login")
class TestResponseRedirect(TestCase): def setUp(self): application = Application(os.getcwd()) self.response = Response(application) def test_download(self): self.response.download("invoice", "tests/integrations/storage/invoice.pdf", force=True) self.assertTrue(self.response.header("Content-Disposition")) self.assertEqual( self.response.header("Content-Disposition"), 'attachment; filename="invoice.pdf"', )
def setUp(self): self.app = App() self.request = Request(wsgi_request.copy()).key( 'NCTpkICMlTXie5te9nJniMj9aVbPM6lsjeq5iDZ0dqY=').load_app(self.app) self.app.bind('Request', self.request) self.response = Response(self.app) self.app.simple(Response)
def store_changed_password( self, auth: Auth, request: Request, response: Response ): # store password_reset record auth.reset_password(request.input("password"), request.input("token")) # Need to validate?? # Redirect back? return response.back()
class TestResponseRedirect(TestCase): def setUp(self): super().setUp() self.addRoutes(Route.get("/", None).name("home-redirect")) self.response = Response(self.application) def test_redirect(self): self.response.redirect("/") self.assertEqual(self.response.get_status(), 302) self.assertEqual(self.response.header_bag.get("Location").value, "/") def test_redirect_to_route_named_route(self): self.response.redirect(name="home-redirect") self.assertEqual(self.response.get_status(), 302) self.assertEqual(self.response.header_bag.get("Location").value, "/") def test_redirect_to_url(self): self.response.redirect(url="/login") self.assertEqual(self.response.get_status(), 302) self.assertEqual(self.response.header_bag.get("Location").value, "/login")
class TestResponseRedirect(TestCase): def setUp(self): application = Application(os.getcwd()) application.bind("router", RouteCapsule(Route.get("/", None).name("home"))) self.response = Response(application) def test_redirect(self): self.response.redirect("/") self.assertEqual(self.response.get_status(), 302) self.assertEqual(self.response.header_bag.get("Location").value, "/") def test_redirect_to_route_named_route(self): self.response.redirect(name="home") self.assertEqual(self.response.get_status(), 302) self.assertEqual(self.response.header_bag.get("Location").value, "/") def test_redirect_to_url(self): self.response.redirect(url="/login") self.assertEqual(self.response.get_status(), 302) self.assertEqual( self.response.header_bag.get("Location").value, "/login")
def setUp(self): application = Application(os.getcwd()) self.response = Response(application)
def setUp(self): application = Application(os.getcwd()) application.bind("router", RouteCapsule(Route.get("/", None).name("home"))) self.response = Response(application)
def setUp(self): super().setUp() self.addRoutes(Route.get("/", None).name("home-redirect")) self.response = Response(self.application)
def response_int(self, response: Response): return response.view(1)
def redirect(self, response: Response): return response.redirect('/some/test')
def test_json(self, response: Response): return response.json({'test': 'value'})