summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Petrello <lists@ryanpetrello.com>2014-06-25 12:39:23 -0400
committerRyan Petrello <lists@ryanpetrello.com>2014-06-25 12:40:55 -0400
commit6276bb093b3cfa40d949e6a29081c68bd4422956 (patch)
treede93e3e85890a2028eb01a9c19634d6ba40c38b6
parent6c7a8b3ee9658c4bb2a2d72f241720861d1da56f (diff)
downloadpecan-6276bb093b3cfa40d949e6a29081c68bd4422956.tar.gz
Fix a bug that broke `default_renderer = json`.
Change-Id: Ie57feadb6efe664c1bc3c39debcb21c3355f210c Fixes bug 1332501
-rw-r--r--pecan/core.py4
-rw-r--r--pecan/tests/test_base.py13
2 files changed, 16 insertions, 1 deletions
diff --git a/pecan/core.py b/pecan/core.py
index 44bad0e..eb3fe69 100644
--- a/pecan/core.py
+++ b/pecan/core.py
@@ -526,7 +526,9 @@ class PecanBase(object):
template = content_types.get(pecan_state['content_type'])
# check if for controller override of template
- template = pecan_state.get('override_template', template)
+ template = pecan_state.get('override_template', template) or (
+ 'json' if self.default_renderer == 'json' else None
+ )
pecan_state['content_type'] = pecan_state.get(
'override_content_type',
pecan_state['content_type']
diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py
index 81471ec..c076139 100644
--- a/pecan/tests/test_base.py
+++ b/pecan/tests/test_base.py
@@ -1520,6 +1520,19 @@ class TestEngines(PecanTestCase):
assert r.status_int == 200
assert b_("<h1>Hello, Jonathan!</h1>") in r.body
+ def test_default_json_renderer(self):
+
+ class RootController(object):
+ @expose()
+ def index(self, name='Bill'):
+ return dict(name=name)
+
+ app = TestApp(Pecan(RootController(), default_renderer='json'))
+ r = app.get('/')
+ assert r.status_int == 200
+ result = dict(json.loads(r.body.decode()))
+ assert result == {'name': 'Bill'}
+
class TestDeprecatedRouteMethod(PecanTestCase):