Browse files

Added tests for the render_placeholder template tag

  • Loading branch information...
1 parent af23df0 commit 8f3a05fea6b54605447851eb647b9b7c73538d5e Jonas Obrist committed Dec 31, 2010
Showing with 32 additions and 13 deletions.
  1. +7 −9 cms/tests/base.py
  2. +3 −3 cms/tests/permmod.py
  3. +22 −1 cms/tests/placeholder.py
View
16 cms/tests/base.py
@@ -331,14 +331,12 @@ def assign_user_to_page(self, page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
page_permission.save()
return page_permission
- def add_plugin(self, user=None, page=None, placeholder=None, language='en'):
- if placeholder:
- page = placeholder.page_set.all()[0]
- elif page:
- placeholder = page.placeholders.get(slot__iexact='Right-Column')
- else:
- page = self.slave_page
- placeholder = page.placeholders.get(slot__iexact='Right-Column')
+ def add_plugin(self, user=None, page=None, placeholder=None, language='en', body=''):
+ if not placeholder:
+ if page:
+ placeholder = page.placeholders.get(slot__iexact='Right-Column')
+ else:
+ placeholder = page.placeholders.get(slot__iexact='Right-Column')
plugin_base = CMSPlugin(
plugin_type='TextPlugin',
@@ -348,7 +346,7 @@ def add_plugin(self, user=None, page=None, placeholder=None, language='en'):
)
plugin_base.insert_at(None, position='last-child', commit=False)
- plugin = Text(body='')
+ plugin = Text(body=body)
plugin_base.set_base_attr(plugin)
plugin.save()
return plugin.pk
View
6 cms/tests/permmod.py
@@ -180,15 +180,15 @@ def test_06_page_added_by_slave_can_be_published_approved_by_user_master(self):
page = self.approve_page(page)
def test_07_super_can_add_plugin(self):
- self.add_plugin(self.user_super)
+ self.add_plugin(self.user_super, page=self.slave_page)
def test_08_master_can_add_plugin(self):
- self.add_plugin(self.user_master)
+ self.add_plugin(self.user_master, page=self.slave_page)
def test_09_slave_can_add_plugin(self):
- self.add_plugin(self.user_slave)
+ self.add_plugin(self.user_slave, page=self.slave_page)
def test_10_same_order(self):
View
23 cms/tests/placeholder.py
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
from cms.exceptions import DuplicatePlaceholderWarning
+from cms.models.placeholdermodel import Placeholder
from cms.tests.base import CMSTestCase
from cms.utils.plugins import get_placeholders
+from django.conf import settings
from django.contrib import admin
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
-from django.template import TemplateSyntaxError
+from django.template import TemplateSyntaxError, Template
+from django.template.context import Context, RequestContext
from testapp.placeholderapp.models import Example1, Example2, Example3, Example4, \
Example5
@@ -93,3 +96,21 @@ def test_10_fieldsets(self):
def test_11_placeholder_scanning_fail(self):
self.assertRaises(TemplateSyntaxError, get_placeholders, 'placeholder_tests/test_eleven.html')
+
+ def test_12_placeholder_tag(self):
+ template = Template("{% load placeholder_tags %}{% render_placeholder placeholder %}")
+ ctx = Context()
+ self.assertEqual(template.render(ctx), "")
+ request = self.get_request('/')
+ rctx = RequestContext(request)
+ self.assertEqual(template.render(rctx), "")
+ placeholder = Placeholder.objects.create(slot="test")
+ rctx['placeholder'] = placeholder
+ self.assertEqual(template.render(rctx), "")
+ self.assertEqual(placeholder.cmsplugin_set.count(), 0)
+ self.add_plugin(placeholder=placeholder, body="test", language=settings.LANGUAGES[0][0])
+ self.assertEqual(placeholder.cmsplugin_set.count(), 1)
+ rctx = RequestContext(request)
+ placeholder = self.reload(placeholder)
+ rctx['placeholder'] = placeholder
+ self.assertEqual(template.render(rctx).strip(), "test")

0 comments on commit 8f3a05f

Please sign in to comment.