예제 #1
0
    def test_toolbar_staff(self):
        # Test that the toolbar contains edito mode switcher if placeholders are available
        apphooks = (
            'cms.test_utils.project.placeholderapp.cms_app.Example1App',
        )
        with SettingsOverride(CMS_APPHOOKS=apphooks, ROOT_URLCONF='cms.test_utils.project.placeholderapp_urls'):
            self.create_base_structure('Example1App', 'en')
            ex1 = Example1.objects.create(char_1='1', char_2='2', char_3='3', char_4='4', date_field=now())
            path = reverse('example_detail', kwargs={'pk': ex1.pk})

            self.user = self._create_user('admin_staff', True, True)
            response = self.client.get(path+"?edit")
            toolbar = CMSToolbar(response.context['request'])
            toolbar.populate()
            placeholder_toolbar = PlaceholderToolbar(response.context['request'], toolbar, True, path)
            placeholder_toolbar.populate()
            placeholder_toolbar.init_placeholders_from_request()
            placeholder_toolbar.add_structure_mode()
            self.assertEqual(len(placeholder_toolbar.toolbar.get_right_items()), 1)

            self.user = self._create_user('staff', True, False)
            response = self.client.get(path+"?edit")
            toolbar = CMSToolbar(response.context['request'])
            toolbar.populate()
            placeholder_toolbar = PlaceholderToolbar(response.context['request'], toolbar, True, path)
            placeholder_toolbar.populate()
            placeholder_toolbar.init_placeholders_from_request()
            placeholder_toolbar.add_structure_mode()
            self.assertEqual(len(placeholder_toolbar.toolbar.get_right_items()), 1)

            self.user = None
예제 #2
0
 def test_no_page_anon(self):
     request = self.get_page_request(None, self.get_anon(), '/')
     toolbar = CMSToolbar(request)
     toolbar.populate()
     toolbar.post_template_populate()
     items = toolbar.get_left_items() + toolbar.get_right_items()
     self.assertEqual(len(items), 0)
예제 #3
0
 def test_publish_button(self):
     page = create_page('test', 'nav_playground.html', 'en', published=True)
     request = self.get_page_request(page, self.get_superuser(), edit=True)
     toolbar = CMSToolbar(request)
     toolbar.populate()
     toolbar.post_template_populate()
     self.assertTrue(toolbar.edit_mode)
     items = toolbar.get_left_items() + toolbar.get_right_items()
     self.assertEqual(len(items), 7)
예제 #4
0
 def test_no_page_staff(self):
     request = self.get_page_request(None, self.get_staff(), '/')
     toolbar = CMSToolbar(request)
     toolbar.populate()
     toolbar.post_template_populate()
     items = toolbar.get_left_items() + toolbar.get_right_items()
     # Logo + admin-menu + logout
     self.assertEqual(len(items), 2, items)
     admin_items = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, 'Test').get_items()
     self.assertEqual(len(admin_items), 6, admin_items)
예제 #5
0
 def test_no_publish_button(self):
     page = create_page('test', 'nav_playground.html', 'en', published=True)
     request = self.get_page_request(page, self.get_staff(), edit=True)
     toolbar = CMSToolbar(request)
     toolbar.populate()
     toolbar.post_template_populate()
     self.assertTrue(page.has_change_permission(request))
     self.assertFalse(page.has_publish_permission(request))
     self.assertTrue(toolbar.edit_mode)
     items = toolbar.get_left_items() + toolbar.get_right_items()
     # Logo + edit-mode + templates + page-menu + admin-menu + logout
     self.assertEqual(len(items), 6)
예제 #6
0
    def test_no_page_superuser(self):
        request = self.get_page_request(None, self.get_superuser(), '/')
        toolbar = CMSToolbar(request)
        toolbar.populate()
        toolbar.post_template_populate()
        items = toolbar.get_left_items() + toolbar.get_right_items()
        # Logo + edit-mode + admin-menu + logout
        self.assertEqual(len(items), 2)
        admin_items = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, 'Test').get_items()

        if is_user_swapped:
            self.assertEqual(len(admin_items), 6, admin_items)
        else:
            self.assertEqual(len(admin_items), 7, admin_items)
예제 #7
0
    def test_no_change_button(self):
        page = create_page('test', 'nav_playground.html', 'en', published=True)
        user = self.get_staff()
        user.user_permissions.all().delete()
        request = self.get_page_request(page, user, edit=True)
        toolbar = CMSToolbar(request)
        toolbar.populate()
        toolbar.post_template_populate()
        self.assertFalse(page.has_change_permission(request))
        self.assertFalse(page.has_publish_permission(request))

        items = toolbar.get_left_items() + toolbar.get_right_items()
        # Logo + page-menu + admin-menu + logout
        self.assertEqual(len(items), 3, items)
        admin_items = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, 'Test').get_items()
        self.assertEqual(len(admin_items), 6, admin_items)
예제 #8
0
 def test_button_consistency_staff(self):
     """
     Tests that the buttons remain even when the language changes.
     """
     user = self.get_staff()
     cms_page = create_page('test-en', 'nav_playground.html', 'en', published=True)
     create_title('de', 'test-de', cms_page)
     cms_page.publish('de')
     en_request = self.get_page_request(cms_page, user, edit=True)
     en_toolbar = CMSToolbar(en_request)
     en_toolbar.populate()
     en_toolbar.post_template_populate()
     self.assertEqual(len(en_toolbar.get_left_items() + en_toolbar.get_right_items()), 6)
     de_request = self.get_page_request(cms_page, user, path='/de/', edit=True, lang_code='de')
     de_toolbar = CMSToolbar(de_request)
     de_toolbar.populate()
     de_toolbar.post_template_populate()
     self.assertEqual(len(de_toolbar.get_left_items() + de_toolbar.get_right_items()), 6)
예제 #9
0
    def test_toolbar_staff(self):
        # Test that the toolbar contains edito mode switcher if placeholders are available
        apphooks = (
            'cms.test_utils.project.placeholderapp.cms_app.Example1App', )
        with SettingsOverride(
                CMS_APPHOOKS=apphooks,
                ROOT_URLCONF='cms.test_utils.project.placeholderapp_urls'):
            self.create_base_structure('Example1App', 'en')
            ex1 = Example1.objects.create(char_1='1',
                                          char_2='2',
                                          char_3='3',
                                          char_4='4',
                                          date_field=now())
            path = reverse('example_detail', kwargs={'pk': ex1.pk})

            self.user = self._create_user('admin_staff', True, True)
            response = self.client.get(path + "?edit")
            toolbar = CMSToolbar(response.context['request'])
            toolbar.populate()
            placeholder_toolbar = PlaceholderToolbar(
                response.context['request'], toolbar, True, path)
            placeholder_toolbar.populate()
            placeholder_toolbar.init_placeholders_from_request()
            placeholder_toolbar.add_structure_mode()
            self.assertEqual(
                len(placeholder_toolbar.toolbar.get_right_items()), 1)

            self.user = self._create_user('staff', True, False)
            response = self.client.get(path + "?edit")
            toolbar = CMSToolbar(response.context['request'])
            toolbar.populate()
            placeholder_toolbar = PlaceholderToolbar(
                response.context['request'], toolbar, True, path)
            placeholder_toolbar.populate()
            placeholder_toolbar.init_placeholders_from_request()
            placeholder_toolbar.add_structure_mode()
            self.assertEqual(
                len(placeholder_toolbar.toolbar.get_right_items()), 1)

            self.user = None
예제 #10
0
    def test_toolbar_with_items(self):
        """
        Test that Blog toolbar is present and contains all items
        """
        from cms.toolbar.toolbar import CMSToolbar
        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])

        posts[0].publish = False
        posts[0].save()
        toolbar = CMSToolbar(request)
        toolbar.populate()
        toolbar.post_template_populate()
        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=(posts[0].pk,)))), 1)

        # 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'])
예제 #11
0
    def test_toolbar_with_items(self):
        """
        Test that Blog toolbar is present and contains all items
        """
        from cms.toolbar.toolbar import CMSToolbar
        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])

        posts[0].publish = False
        posts[0].save()
        toolbar = CMSToolbar(request)
        toolbar.populate()
        toolbar.post_template_populate()
        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=(posts[0].pk,)))), 1)

        # 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'])
예제 #12
0
 def get_toolbar(self, request):
     toolbar = CMSToolbar(request)
     toolbar.populate()
     toolbar.post_template_populate()
     return toolbar