Browse files

Added test for sekizai/show-placeholder issue

  • Loading branch information...
1 parent 646d65b commit 799d166fd6633f70b689a157ca40fa7243f0ef1d @ojii ojii committed Jan 18, 2013
View
1 cms/test_utils/project/templates/alt_plugin_templates/show_placeholder/cms/plugins/text.html
@@ -0,0 +1 @@
+{% load sekizai_tags %}{% addtoblock "js" %}JAVASCRIPT{% endaddtoblock %}
View
57 cms/tests/templatetags.py
@@ -1,15 +1,17 @@
from __future__ import with_statement
import copy
-from cms.api import create_page, create_title
+from django.test import RequestFactory
+import os
+from cms.api import create_page, create_title, add_plugin
from cms.models.pagemodel import Page, Placeholder
+from cms.plugins.text.cms_plugins import TextPlugin
from cms.templatetags.cms_tags import (get_site_id, _get_page_by_untyped_arg,
_show_placeholder_for_page)
from cms.test_utils.fixtures.templatetags import TwoPagesFixture
from cms.test_utils.testcases import SettingsOverrideTestCase
from cms.test_utils.util.context_managers import SettingsOverride
from cms.utils import get_cms_setting
from cms.utils.plugins import get_placeholders
-from django.conf import settings
from django.contrib.sites.models import Site
from django.core import mail
from django.core.exceptions import ImproperlyConfigured
@@ -60,13 +62,6 @@ class FakeRequest(object):
class TemplatetagDatabaseTests(TwoPagesFixture, SettingsOverrideTestCase):
-
- def setUp(self):
- self._prev_DEBUG = settings.DEBUG
-
- def tearDown(self):
- settings.DEBUG = self._prev_DEBUG
-
def _getfirst(self):
return Page.objects.public().get(title_set__title='first')
@@ -129,19 +124,19 @@ def test_show_placeholder_for_page_placeholder_does_not_exist(self):
Verify ``show_placeholder`` correctly handles being given an
invalid identifier.
"""
- settings.DEBUG = True # So we can see the real exception raised
- request = HttpRequest()
- request.REQUEST = {}
- request.session = {}
- self.assertRaises(Placeholder.DoesNotExist,
- _show_placeholder_for_page,
- RequestContext(request),
- 'does_not_exist',
- 'myreverseid')
- settings.DEBUG = False # Now test the non-debug output
- content = _show_placeholder_for_page(RequestContext(request),
- 'does_not_exist', 'myreverseid')
- self.assertEqual(content['content'], '')
+ with SettingsOverride(DEBUG=True):
+ request = HttpRequest()
+ request.REQUEST = {}
+ request.session = {}
+ self.assertRaises(Placeholder.DoesNotExist,
+ _show_placeholder_for_page,
+ RequestContext(request),
+ 'does_not_exist',
+ 'myreverseid')
+ with SettingsOverride(DEBUG=False):
+ content = _show_placeholder_for_page(RequestContext(request),
+ 'does_not_exist', 'myreverseid')
+ self.assertEqual(content['content'], '')
def test_untranslated_language_url(self):
""" Tests page_language_url templatetag behavior when used on a page
@@ -192,3 +187,21 @@ def test_untranslated_language_url(self):
context['request'].current_page = page_3.publisher_public
res = tpl.render(context)
self.assertEqual(res,"/de/")
+
+
+class NoFixtureDatabaseTemplateTagTests(TestCase):
+ def test_cached_show_placeholder_sekizai(self):
+ from cms.test_utils import project
+ template_dir = os.path.join(os.path.dirname(project.__file__), 'templates', 'alt_plugin_templates', 'show_placeholder')
+ page = create_page('Test', 'col_two.html', 'en')
+ placeholder = page.placeholders.all()[0]
+ add_plugin(placeholder, TextPlugin, 'en', body='HIDDEN')
+ request = RequestFactory().get('/')
+ with SettingsOverride(TEMPLATE_DIRS=[template_dir]):
+ template = Template("{% load cms_tags sekizai_tags %}{% show_placeholder slot page 'en' 1 %}{% render_block 'js' %}")
+ context = RequestContext(request, {'page': page, 'slot': placeholder.slot})
+ output = template.render(context)
+ self.assertIn('JAVASCRIPT', output)
+ context = RequestContext(request, {'page': page, 'slot': placeholder.slot})
+ output = template.render(context)
+ self.assertIn('JAVASCRIPT', output)

0 comments on commit 799d166

Please sign in to comment.