summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pecan/core.py8
-rw-r--r--pecan/decorators.py7
-rw-r--r--pecan/tests/test_base.py12
-rw-r--r--tox.ini7
4 files changed, 26 insertions, 8 deletions
diff --git a/pecan/core.py b/pecan/core.py
index 567f8e5..854d948 100644
--- a/pecan/core.py
+++ b/pecan/core.py
@@ -585,9 +585,11 @@ 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) or (
- 'json' if self.default_renderer == 'json' else None
- )
+ template = pecan_state.get('override_template', template)
+ if template is None and cfg['explicit_content_type'] is False:
+ if self.default_renderer == 'json':
+ template = 'json'
+
pecan_state['content_type'] = pecan_state.get(
'override_content_type',
pecan_state['content_type']
diff --git a/pecan/decorators.py b/pecan/decorators.py
index 68195a9..15808d4 100644
--- a/pecan/decorators.py
+++ b/pecan/decorators.py
@@ -23,9 +23,9 @@ def when_for(controller):
def expose(template=None,
- content_type='text/html',
generic=False,
- route=None):
+ route=None,
+ **kw):
'''
Decorator used to flag controller methods as being "exposed" for
@@ -46,6 +46,8 @@ def expose(template=None,
wanted to route a function to `some-special-path'.
'''
+ content_type = kw.get('content_type', 'text/html')
+
if template == 'json':
content_type = 'application/json'
@@ -54,6 +56,7 @@ def expose(template=None,
f.exposed = True
cfg = _cfg(f)
+ cfg['explicit_content_type'] = 'content_type' in kw
if route:
# This import is here to avoid a circular import issue
diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py
index e953d90..e42f1da 100644
--- a/pecan/tests/test_base.py
+++ b/pecan/tests/test_base.py
@@ -1922,6 +1922,18 @@ class TestEngines(PecanTestCase):
result = dict(json.loads(r.body.decode()))
assert result == {'name': 'Bill'}
+ def test_default_json_renderer_with_explicit_content_type(self):
+
+ class RootController(object):
+ @expose(content_type='text/plain')
+ def index(self, name='Bill'):
+ return name
+
+ app = TestApp(Pecan(RootController(), default_renderer='json'))
+ r = app.get('/')
+ assert r.status_int == 200
+ assert r.body == b_("Bill")
+
class TestDeprecatedRouteMethod(PecanTestCase):
diff --git a/tox.ini b/tox.ini
index a9bfc81..593f2ad 100644
--- a/tox.ini
+++ b/tox.ini
@@ -96,10 +96,11 @@ basepython = python2.7
deps = nose
ipaddr
simplegeneric
-changedir = {envdir}/build/wsme
-commands = pip install --build {envdir}/build --pre --no-clean --no-use-wheel wsme
- {envdir}/bin/python setup.py develop
+changedir = {envdir}/src
+commands = pip install --download {envdir}/src --pre --no-deps --no-clean --no-use-wheel wsme
+ sh -c "find -iname 'wsme*.tar.gz' | xargs tar --strip-components 1 -xf"
{envdir}/bin/pip install -U {toxinidir} # install pecan-dev
+ {envdir}/bin/pip install .
nosetests -v tests/pecantest
[testenv:wsme-tip]