From fbcc2c27f7fbe773359bc4872ad4704aa91699a0 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Fri, 22 Jul 2016 16:12:42 -0400 Subject: [PATCH] Controllers that return `None` should be an HTTP 204. --- pecan/core.py | 2 ++ pecan/tests/test_base.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pecan/core.py b/pecan/core.py index 6937080..f02b3a3 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -417,6 +417,8 @@ class PecanBase(object): self.default_renderer, self.template_path ) + if namespace is None: + return None return renderer.render(template, namespace) def find_controller(self, state): diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index 37c2235..435e8b5 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -2001,6 +2001,29 @@ class TestEngines(PecanTestCase): assert r.status_int == 200 assert r.body == b_("Bill") + def test_template_with_no_namespace(self): + class RootController(object): + @expose('mako:mako.html') + def index(self): + return None + + app = TestApp(Pecan( + RootController(), + template_path=self.template_path + )) + r = app.get('/') + self.assertEqual(r.status_int, 204) + + def test_json_with_no_namespace(self): + class RootController(object): + @expose('json') + def index(self): + return None + + app = TestApp(Pecan(RootController())) + r = app.get('/') + self.assertEqual(r.status_int, 204) + class TestDeprecatedRouteMethod(PecanTestCase):