Toolbar tests

This commit is contained in:
Iacopo Spalletti 2014-06-10 00:11:48 +02:00
parent 123692c0f4
commit 1acc78cb31
5 changed files with 87 additions and 56 deletions

View file

@ -13,7 +13,7 @@ class BlogToolbar(CMSToolbar):
def populate(self):
if not (self.is_current_app and self.request.user.has_perm('djangocms_blog.add_post')):
return
return # pragma: no cover
admin_menu = self.toolbar.get_or_create_menu("djangocms_blog", _('Blog'))
url = reverse('admin:djangocms_blog_post_changelist')
admin_menu.add_modal_item(_('Post list'), url=url)
@ -21,7 +21,7 @@ class BlogToolbar(CMSToolbar):
admin_menu.add_modal_item(_('Add post'), url=url)
current_post = getattr(self.request, BLOG_CURRENT_POST_IDENTIFIER, None)
if current_post and self.request.user.has_perm('djangocms_blog.change_post'):
if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover
admin_menu.add_modal_item(_('Edit Post'),reverse(
'admin:djangocms_blog_post_change', args=(current_post.pk,)),
active=True)

View file

@ -3,12 +3,14 @@
Tests for `djangocms_blog` module.
"""
from cms.utils.i18n import get_language_list
from cmsplugin_filer_image.models import ThumbnailOption
from django.contrib.auth.models import User
from django.http import SimpleCookie
from django.test import TestCase, RequestFactory
from six import StringIO
from djangocms_blog.models import BlogCategory, Post
class BaseTest(TestCase):
"""
@ -17,6 +19,28 @@ class BaseTest(TestCase):
request_factory = None
user = None
languages = get_language_list()
category_1 = None
thumb_1 = None
thumb_2 = None
data = {
'it': [
{'title': u'Primo post', 'abstract': u'<p>prima riga</p>',
'description': u'Questa è la descrizione', 'keywords': u'keyword1, keyword2',
'text': u'Testo del post'},
{'title': u'Secondo post', 'abstract': u'<p>prima riga del secondo post</p>',
'description': u'Descrizione del secondo post', 'keywords': u'keyword3, keyword4',
'text': u'Testo del secondo post'},
],
'en': [
{'title': u'First post', 'abstract': u'<p>first line</p>',
'description': u'This is the description', 'keywords': u'keyword1, keyword2',
'text': u'Post text'},
{'title': u'Second post', 'abstract': u'<p>second post first line</p>',
'description': u'Second post description', 'keywords': u'keyword3, keyword4',
'text': u'Second post text'}
]
}
@classmethod
def setUpClass(cls):
@ -25,6 +49,37 @@ class BaseTest(TestCase):
cls.user_staff = User.objects.create(username='staff', is_staff=True)
cls.user_normal = User.objects.create(username='normal')
def setUp(self):
super(BaseTest, self).setUp()
self.category_1 = BlogCategory.objects.create()
self.category_1.name = u'category 1'
self.category_1.save()
self.thumb_1 = ThumbnailOption.objects.create(
name='base', width=100, height=100, crop=True, upscale=False
)
self.thumb_2 = ThumbnailOption.objects.create(
name='main', width=200, height=200, crop=False, upscale=False
)
def _get_post(self, data, post=None, lang='en'):
if not post:
post = Post()
post.set_current_language(lang)
post.author = self.user
post.title = data['title']
post.abstract = data['abstract']
post.meta_description = data['description']
post.meta_keywords = data['keywords']
post.save()
post.categories.add(self.category_1)
post.save()
return post
@classmethod
def tearDownClass(cls):
User.objects.all().delete()
def get_pages(self):
from cms.api import create_page, create_title
page = create_page(u'page one', 'page.html', language='en')

View file

@ -2,14 +2,12 @@
from cms.api import add_plugin
from cms.utils.copy_plugins import copy_plugins_to
from cms.utils.plugins import downcast_plugins
from cmsplugin_filer_image.models import ThumbnailOption
from datetime import date
from django.conf import settings as dj_settings
from django.core.urlresolvers import reverse
import parler
from taggit.models import Tag
from djangocms_blog.models import BlogCategory, Post
from djangocms_blog.models import Post
from djangocms_blog import settings
@ -18,51 +16,6 @@ from . import BaseTest
class ModelsTest(BaseTest):
data = {
'it': [
{'title': u'Primo post', 'abstract': u'<p>prima riga</p>',
'description': u'Questa è la descrizione', 'keywords': u'keyword1, keyword2',
'text': u'Testo del post'},
{'title': u'Secondo post', 'abstract': u'<p>prima riga del secondo post</p>',
'description': u'Descrizione del secondo post', 'keywords': u'keyword3, keyword4',
'text': u'Testo del secondo post'},
],
'en': [
{'title': u'First post', 'abstract': u'<p>first line</p>',
'description': u'This is the description', 'keywords': u'keyword1, keyword2',
'text': u'Post text'},
{'title': u'Second post', 'abstract': u'<p>second post first line</p>',
'description': u'Second post description', 'keywords': u'keyword3, keyword4',
'text': u'Second post text'}
]
}
def setUp(self):
super(ModelsTest, self).setUp()
self.category_1 = BlogCategory.objects.create()
self.category_1.name = u'category 1'
self.category_1.save()
self.thumb_1 = ThumbnailOption.objects.create(
name='base', width=100, height=100, crop=True, upscale=False
)
self.thumb_2 = ThumbnailOption.objects.create(
name='main', width=200, height=200, crop=False, upscale=False
)
def _get_post(self, data, post=None, lang='en'):
if not post:
post = Post()
post.set_current_language(lang)
post.author = self.user
post.title = data['title']
post.abstract = data['abstract']
post.meta_description = data['description']
post.meta_keywords = data['keywords']
post.save()
post.categories.add(self.category_1)
post.save()
return post
def test_model_attributes(self):
post = self._get_post(self.data['en'][0])
post = self._get_post(self.data['it'][0], post, 'it')

27
tests/test_toolbar.py Normal file
View file

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from cms.toolbar.items import ModalItem
from django.core.urlresolvers import reverse
from djangocms_blog.models import BLOG_CURRENT_POST_IDENTIFIER
from . import BaseTest
class ToolbarTest(BaseTest):
def test_toolbar_with_items(self):
"""
Test that Blog toolbar is present and contains all items
"""
from cms.toolbar.toolbar import CMSToolbar
post = self._get_post(self.data['en'][0])
page1, page2 = self.get_pages()
request = self.get_page_request(page1, self.user, r'/en/blog/', edit=True)
setattr(request, BLOG_CURRENT_POST_IDENTIFIER, post)
toolbar = CMSToolbar(request)
toolbar.get_left_items()
blog_menu = toolbar.menus['djangocms_blog']
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse('admin:djangocms_blog_post_changelist'))), 1)
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse('admin:djangocms_blog_post_add'))), 1)
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse('admin:djangocms_blog_post_change', args=(post.pk,)))), 1)

View file

@ -1,10 +1,6 @@
{% load cms_tags sekizai_tags page_tags %}
{% load cms_tags sekizai_tags %}
{% render_block "css" %}
{% cms_toolbar %}
{% placeholder "placeholder" %}
{% page_tags request.current_page as ptags_list %}
{% title_tags request.current_page as ttags_list %}
{% include_page_tags request.current_page %}
{% include_title_tags request.current_page %}
{% render_block "js" %}