Skip to content

Commit

Permalink
Merge branch '2926-snippet-html-comment-only-debug' of https://github…
Browse files Browse the repository at this point in the history
….com/torfsen/ckan into torfsen-2926-snippet-html-comment-only-debug
  • Loading branch information
amercader committed Mar 24, 2016
2 parents a340374 + dc1cb46 commit 12ef4e0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ckan/lib/base.py
Expand Up @@ -75,8 +75,9 @@ def render_snippet(template_name, **kw):
cache_force = kw.pop('cache_force', None)
output = render(template_name, extra_vars=kw, cache_force=cache_force,
renderer='snippet')
output = '\n<!-- Snippet %s start -->\n%s\n<!-- Snippet %s end -->\n' % (
template_name, output, template_name)
if config.get('debug'):
output = ('\n<!-- Snippet %s start -->\n%s\n<!-- Snippet %s end -->\n'
% (template_name, output, template_name))
return literal(output)


Expand Down
2 changes: 2 additions & 0 deletions ckan/tests/controllers/test_admin.py
Expand Up @@ -223,6 +223,7 @@ def test_custom_css(self):
style_tag = reset_intro_response_html.select('head style')
assert_equal(len(style_tag), 0)

@helpers.change_config('debug', True)
def test_homepage_style(self):
'''Select a homepage style'''
app = self._get_test_app()
Expand Down Expand Up @@ -255,6 +256,7 @@ def test_homepage_style(self):
class TestTrashView(helpers.FunctionalTestBase):
'''View tests for permanently deleting datasets with Admin Trash.'''

@helpers.change_config('debug', True)
def test_trash_view_anon_user(self):
'''An anon user shouldn't be able to access trash view.'''
app = self._get_test_app()
Expand Down
15 changes: 15 additions & 0 deletions ckan/tests/lib/test_base.py
Expand Up @@ -3,6 +3,21 @@
import ckan.tests.helpers as helpers


class TestRenderSnippet(helpers.FunctionalTestBase):
"""
Test ``ckan.lib.base.render_snippet``.
"""
@helpers.change_config('debug', True)
def test_comment_present_if_debug_true(self):
response = self._get_test_app().get('/')
assert '<!-- Snippet ' in response

@helpers.change_config('debug', False)
def test_comment_absent_if_debug_false(self):
response = self._get_test_app().get('/')
assert '<!-- Snippet ' not in response


class TestCORS(helpers.FunctionalTestBase):

def test_options(self):
Expand Down

0 comments on commit 12ef4e0

Please sign in to comment.