djangocms_blog/tests/test_toolbar.py

60 lines
2.6 KiB
Python
Raw Normal View History

2014-06-09 22:11:48 +00:00
# -*- coding: utf-8 -*-
2015-09-12 22:46:05 +00:00
from __future__ import absolute_import, print_function, unicode_literals
2016-02-12 06:42:58 +00:00
from cms.toolbar.items import ButtonList, ModalItem
2014-06-09 22:11:48 +00:00
from django.core.urlresolvers import reverse
2016-02-12 06:42:58 +00:00
from django.utils.encoding import force_text
2015-09-12 22:33:13 +00:00
2014-06-09 22:11:48 +00:00
from djangocms_blog.models import BLOG_CURRENT_POST_IDENTIFIER
2015-10-18 11:16:43 +00:00
from .base import BaseTest
2014-06-09 22:11:48 +00:00
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
2015-09-19 23:11:14 +00:00
posts = self.get_posts()
pages = self.get_pages()
request = self.get_page_request(pages[0], self.user, r'/en/blog/', edit=True)
setattr(request, BLOG_CURRENT_POST_IDENTIFIER, posts[0])
2016-02-12 06:42:58 +00:00
posts[0].publish = False
posts[0].save()
2014-06-09 22:11:48 +00:00
toolbar = CMSToolbar(request)
2016-02-12 06:42:58 +00:00
toolbar.populate()
toolbar.post_template_populate()
2014-06-09 22:11:48 +00:00
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)
2015-09-19 23:11:14 +00:00
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse('admin:djangocms_blog_post_change', args=(posts[0].pk,)))), 1)
2016-02-12 06:42:58 +00:00
# Publish button only appears if current post is unpublished
right = toolbar.get_right_items()
buttons = sum([item.buttons for item in right if isinstance(item, ButtonList)], [])
self.assertTrue([button for button in buttons if force_text(button.name) == 'Publish Blog now'])
# Publish button does not appears if current post is published
posts[0].publish = True
posts[0].save()
toolbar = CMSToolbar(request)
toolbar.populate()
toolbar.post_template_populate()
right = toolbar.get_right_items()
buttons = sum([item.buttons for item in right if isinstance(item, ButtonList)], [])
self.assertFalse([button for button in buttons if force_text(button.name) == 'Publish Blog now'])
# Publish button does not appears if other posts but the current one are unpublished
posts[1].publish = True
posts[1].save()
toolbar = CMSToolbar(request)
toolbar.populate()
toolbar.post_template_populate()
right = toolbar.get_right_items()
buttons = sum([item.buttons for item in right if isinstance(item, ButtonList)], [])
self.assertFalse([button for button in buttons if force_text(button.name) == 'Publish Blog now'])