def view_with_context(self, view: View): return view.render( "welcome", { "count": 1, "users": ["John", "Joe"], "other_key": { "nested": 1 } }, )
def show(self, view: View): return view.render("auth.home")
def setUp(self): self.view = View(Application(os.getcwd())) self.view.add("tests/integrations/templates")
class TestView(TestCase): def setUp(self): self.view = View(Application(os.getcwd())) self.view.add("tests/integrations/templates") def test_can_render_view(self): self.assertTrue("Welcome" in self.view.render("welcome").get_content()) def test_can_pass_dict(self): self.assertTrue("test" in self.view.render("test", { "test": "test" }).get_content()) def test_view_exists(self): self.assertTrue(self.view.exists("welcome")) self.assertFalse(self.view.exists("not_available")) def test_view_render_does_not_keep_previous_variables(self): self.view.render("test", {"var1": "var1"}) self.view.render("test", {"var2": "var2"}) self.assertNotIn("var1", self.view.dictionary) self.assertIn("var2", self.view.dictionary) def test_global_view_exists(self): self.assertTrue( self.view.exists("/tests/integrations/templates/welcome")) self.assertFalse( self.view.exists("/tests/integrations/templates/not_available")) def test_view_gets_global_template(self): self.assertEqual( self.view.render("/tests/integrations/templates/test", { "test": "test" }).get_content(), "test", ) def test_view_extends_without_dictionary_parameters(self): self.view.share({"test": "test"}) self.assertEqual(self.view.render("test").get_content(), "test") def test_composers(self): view = self.view.composer("test", {"test": "test"}) self.assertEqual(view.composers, {"test": {"test": "test"}}) self.assertEqual(view.render("test").rendered_template, "test") def test_composers_load_all_views_with_astericks(self): self.view.composer("*", {"test": "test"}) self.assertEqual(self.view.composers, {"*": {"test": "test"}}) self.assertEqual(self.view.render("test").get_content(), "test") def test_composers_with_wildcard_base_view(self): self.view.composer("mail*", {"to": "test_user"}) self.assertEqual(self.view.composers, {"mail*": {"to": "test_user"}}) self.assertIn("test_user", self.view.render("mail/welcome").get_content()) def test_composers_with_wildcard_base_view_route(self): self.view.composer("mail*", {"to": "test_user"}) self.assertEqual(self.view.composers, {"mail*": {"to": "test_user"}}) self.assertIn("test_user", self.view.render("mail/welcome").get_content()) def test_composers_with_wildcard_lower_directory_view_and_incorrect_shortend_wildcard( self, ): self.view.composer("mail/wel*", {"to": "test_user"}) self.assertEqual(self.view.composers, {"mail/wel*": { "to": "test_user" }}) assert "test_user" not in self.view.render( "mail/welcome").get_content() def test_composers_load_all_views_with_list(self): self.view.composer(["home", "test"], {"test": "test"}) self.assertEqual(self.view.composers, { "home": { "test": "test" }, "test": { "test": "test" } }) self.assertEqual(self.view.render("test").rendered_template, "test") def test_view_share_updates_dictionary_not_overwrite(self): self.view.share({"test1": "test1"}) self.view.share({"test2": "test2"}) self.assertEqual(self.view._shared, { "test1": "test1", "test2": "test2" }) self.view.render("test", {"var1": "var1"}) self.assertEqual(self.view.dictionary, { "test1": "test1", "test2": "test2", "var1": "var1" })
def view_with_context(self, view: View): return view.render("welcome", {"count": 1, "users": ["John", "Joe"]})
def view(self, view: View): return view.render("welcome")
def show(self, view: View): return view.render("auth.login")
def show(self, view: View): return view.render("")
def show(self, view: View): # Show register page return view.render("auth.register")
def show(self, view: View): # Show password_reset page return view.render("auth.password_reset")
def change_password(self, view: View): # store password_reset record return view.render("auth.change_password")
def show(self, request: Request, view: View): request.app.make("session").flash("test", "value") return view.render("welcome")
def play_with_session(self, request: Request, view: View): # Session.flash("test", "hello flashed") # Session.set("test_persisted", "hello persisted in session") # request.app.make("session").set("test_persisted", "hello persisted") return view.render("welcome")
def authorizations(self, view: View): return view.render("authorizations")