Skip to content

Commit

Permalink
Add tests for pages_edit_init tag
Browse files Browse the repository at this point in the history
  • Loading branch information
poxip authored and Batiste Bieler committed May 17, 2017
1 parent acec025 commit e2c3a71
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pages/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.template import Context, Template, TemplateSyntaxError
from django.core.files.uploadedfile import SimpleUploadedFile
from django.conf import settings
from django.contrib.auth.models import User


def render(template, context):
Expand Down Expand Up @@ -454,3 +455,27 @@ def test_block_placeholder(self):
self.assertTrue("block 1:content;" in render(template, context), render(template, context))
self.assertTrue("block 2:content;" in render(template, context), render(template, context))

def test_pages_edit_init(self):
"""Test initializing page edit"""
tpl = "{% load pages_tags %}{% pages_edit_init %}"
user = User.objects.create_user(username='user', email='a@example.com', password='secret')
request = get_request_mock()
request.user = user

template = self.get_template_from_string(tpl)

# Test accessing by non-staff user
self.assertEqual(render(template, context=Context({'request': request})), '')

request.user.is_staff = True
# Test not using the tag on a cms page
self.assertEqual(render(template, context=Context({
'request': request, 'template_name': 'foo.html'
})), '')

# Test regular
page = self.new_page({'slug': 'page1'})
self.assertNotEqual(render(template, context=Context({
'request': request, 'template_name': 'pages/examples/cool.html', 'current_page': page
})), '')

0 comments on commit e2c3a71

Please sign in to comment.