Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    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())
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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())
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    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)