コード例 #1
0
ファイル: toolbar.py プロジェクト: Konviser/django-cms
    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)
コード例 #2
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
 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)
コード例 #3
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
 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)
コード例 #4
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
 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"], [])
コード例 #5
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
 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)
コード例 #6
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
    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)
コード例 #7
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)
コード例 #8
0
ファイル: toolbar.py プロジェクト: Konviser/django-cms
 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)
コード例 #9
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)
コード例 #10
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)
コード例 #11
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
 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)
コード例 #12
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'])
コード例 #13
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'])
コード例 #14
0
ファイル: toolbar.py プロジェクト: Konviser/django-cms
 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)
コード例 #15
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
    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)
コード例 #16
0
ファイル: toolbar.py プロジェクト: Konviser/django-cms
 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)
コード例 #17
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)
コード例 #18
0
ファイル: toolbar.py プロジェクト: Konviser/django-cms
 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)
コード例 #19
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
 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)
コード例 #20
0
ファイル: toolbar.py プロジェクト: Konviser/django-cms
    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)
コード例 #21
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'
         ], [])
コード例 #22
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)
コード例 #23
0
ファイル: toolbar.py プロジェクト: Konviser/django-cms
    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)
コード例 #24
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
    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)
コード例 #25
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)
コード例 #26
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
    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)