Exemple #1
0
    def test_get_alphabetical_insert_position(self):
        page = create_page("toolbar-page", "nav_playground.html", "en",
                           published=True)
        request = self.get_page_request(page, self.get_staff(), '/')
        toolbar = CMSToolbar(request)
        toolbar.get_left_items()
        toolbar.get_right_items()

        admin_menu = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, 'TestAppMenu')

        # Insert alpha
        alpha_position = admin_menu.get_alphabetical_insert_position('menu-alpha', SubMenu, None)

        # As this will be the first item added to this, this use should return the default, or namely None
        if not alpha_position:
            alpha_position = admin_menu.find_first(Break, identifier=ADMINISTRATION_BREAK) + 1
        admin_menu.get_or_create_menu('menu-alpha', 'menu-alpha', position=alpha_position)

        # Insert gamma (should return alpha_position + 1)
        gamma_position = admin_menu.get_alphabetical_insert_position('menu-gamma', SubMenu)
        self.assertEqual(int(gamma_position), int(alpha_position) + 1)
        admin_menu.get_or_create_menu('menu-gamma', 'menu-gamma', position=gamma_position)

        # Where should beta go? It should go right where gamma is now...
        beta_position = admin_menu.get_alphabetical_insert_position('menu-beta', SubMenu)
        self.assertEqual(beta_position, gamma_position)
Exemple #2
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)
     en_request = self.get_page_request(cms_page, user, edit=True)
     en_toolbar = CMSToolbar(en_request)
     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)
     self.assertEqual(len(de_toolbar.get_left_items() + de_toolbar.get_right_items()), 6)
Exemple #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)
     self.assertTrue(toolbar.edit_mode)
     items = toolbar.get_left_items() + toolbar.get_right_items()
     self.assertEqual(len(items), 7)
Exemple #4
0
 def test_template_change_permission(self):
     with SettingsOverride(CMS_PERMISSIONS=True):
         page = create_page("test", "nav_playground.html", "en", published=True)
         request = self.get_page_request(page, self.get_nonstaff())
         toolbar = CMSToolbar(request)
         items = toolbar.get_left_items() + toolbar.get_right_items()
         self.assertEqual([item for item in items if item.css_class_suffix == "templates"], [])
Exemple #5
0
 def test_nonstaff(self):
     page = create_page("test", "nav_playground.html", "en", published=True)
     request = self.get_page_request(page, self.get_nonstaff())
     toolbar = CMSToolbar(request)
     items = toolbar.get_left_items() + toolbar.get_right_items()
     # Logo + edit-mode + logout
     self.assertEqual(len(items), 0)
Exemple #6
0
    def test_anon(self):
        page = create_page("test", "nav_playground.html", "en")
        request = self.get_page_request(page, self.get_anon())
        toolbar = CMSToolbar(request)

        items = toolbar.get_left_items() + toolbar.get_right_items()
        self.assertEqual(len(items), 0)
    def test_anon(self):
        page = create_page('test', 'nav_playground.html', 'en')
        request = self.get_page_request(page, self.get_anon())
        toolbar = CMSToolbar(request)

        items = toolbar.get_left_items() + toolbar.get_right_items()
        self.assertEqual(len(items), 0)
Exemple #8
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)
 def test_nonstaff(self):
     page = create_page('test', 'nav_playground.html', 'en', published=True)
     request = self.get_page_request(page, self.get_nonstaff())
     toolbar = CMSToolbar(request)
     items = toolbar.get_left_items() + toolbar.get_right_items()
     # Logo + edit-mode + logout
     self.assertEqual(len(items), 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)
     self.assertTrue(toolbar.edit_mode)
     items = toolbar.get_left_items() + toolbar.get_right_items()
     self.assertEqual(len(items), 7)
Exemple #11
0
 def test_not_is_staff(self):
     request = RequestFactory().get("/en/?edit")
     request.session = {}
     request.LANGUAGE_CODE = "en"
     request.user = AnonymousUser()
     toolbar = CMSToolbar(request)
     self.assertEqual(len(toolbar.get_left_items()), 0)
     self.assertEqual(len(toolbar.get_right_items()), 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'])
    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'])
Exemple #14
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)
Exemple #15
0
    def test_no_page_superuser(self):
        request = self.get_page_request(None, self.get_superuser(), "/")
        toolbar = CMSToolbar(request)

        items = toolbar.get_left_items() + toolbar.get_right_items()
        # Logo + edit-mode + admin-menu + logout
        self.assertEqual(len(items), 3)
        admin_items = toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER, "Test").get_items()
        self.assertEqual(len(admin_items), 7, admin_items)
Exemple #16
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)
 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)
     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)
Exemple #18
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)
Exemple #19
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)
     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)
Exemple #20
0
    def test_out_of_order(self):
        page = create_page("toolbar-page", "nav_playground.html", "en",
                           published=True)
        request = self.get_page_request(page, self.get_staff(), '/')
        toolbar = CMSToolbar(request)
        menu1 = toolbar.get_or_create_menu("test")
        menu2 = toolbar.get_or_create_menu("test", "Test", side=toolbar.RIGHT, position=2)

        self.assertEqual(menu1, menu2)
        self.assertEqual(menu1.name, 'Test')
        self.assertEqual(len(toolbar.get_right_items()), 1)
 def test_template_change_permission(self):
     with SettingsOverride(CMS_PERMISSIONS=True):
         page = create_page('test',
                            'nav_playground.html',
                            'en',
                            published=True)
         request = self.get_page_request(page, self.get_nonstaff())
         toolbar = CMSToolbar(request)
         items = toolbar.get_left_items() + toolbar.get_right_items()
         self.assertEqual([
             item for item in items if item.css_class_suffix == 'templates'
         ], [])
 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)
     en_request = self.get_page_request(cms_page, user, edit=True)
     en_toolbar = CMSToolbar(en_request)
     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)
     self.assertEqual(
         len(de_toolbar.get_left_items() + de_toolbar.get_right_items()), 6)
Exemple #23
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)
Exemple #24
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)
        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)
    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)
        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)
Exemple #26
0
    def test_no_page_anon(self):
        request = self.get_page_request(None, self.get_anon(), "/")
        toolbar = CMSToolbar(request)

        items = toolbar.get_left_items() + toolbar.get_right_items()
        self.assertEqual(len(items), 0)