def test_decorate(self): self.assertEqual("Hello World", string_view(self.get_req)) post_view = decorate(require_POST, string_view) get_view = decorate(require_GET, string_view) self.assertIsInstance(get_view(self.post_req), HttpResponseNotAllowed) self.assertIsInstance(post_view(self.get_req), HttpResponseNotAllowed) self.assertEqual("Hello World", get_view(self.get_req)) self.assertEqual("Hello World", post_view(self.post_req))
def test_logging(self): output = StringIO() logging_view = decorate(log("Got a request", out=output), string_view) self.assertEqual("Hello World", logging_view(self.get_req)) output.seek(0) self.assertEqual("Got a request\n", output.read())
def test_view_returns_reponse(self): templating_view = decorate(render_template("home.html"), redirect_view) resp = templating_view(self.get_req) self.assertEqual(b"", resp.content) if django.VERSION[1] > 5: self.assertEqual("http://lmgtfy.com", resp.url)
def test_callable(self): templating_view = decorate(render_template("home.html"), dict_view) resp = templating_view(self.get_req) self.assertEqual(b"I said hello to World\n", resp.content)
def test_dict(self): templating_view = decorate(render_template("home.html"), {"Hello": "Joe"}) resp = templating_view(self.get_req) self.assertEqual(b"I said hello to Joe\n", resp.content)