Пример #1
0
    def test_when_old_homepage_tree_has_no_apphooks_shouldnt_trigger_signal(self):
        PageVersionFactory(
            content__page__node__depth=1, content__page__is_home=1, state=PUBLISHED
        )
        version = PageVersionFactory(content__page__node__depth=1, state=PUBLISHED)
        to_be_homepage = version.content
        with self.login_user_context(self.get_superuser()), patch(
            "djangocms_pageadmin.admin.set_restart_trigger"
        ) as mock_handler, patch(
            "cms.models.query.PageQuerySet.has_apphooks", return_value=False
        ):
            self.client.post(
                self.get_admin_url(PageContent, "set_home_content", to_be_homepage.pk)
            )

            mock_handler.assert_not_called()
 def test_unpublish_not_shown(self):
     version = PageVersionFactory()
     pagecontent = version.content
     func = self.modeladmin._list_actions(self.get_request("/"))
     response = func(pagecontent)
     soup = parse_html(response)
     element = soup.find("a", {"class": "cms-page-admin-action-unpublish"})
     self.assertIsNone(
         element,
         "Element a.cms-page-admin-action-unpublish is shown when it shouldn't",
     )
 def test_non_root_page_should_not_allowed_to_set_home(self):
     version = PageVersionFactory(content__page__node__depth=2,
                                  state=PUBLISHED)
     pagecontent = version.content
     with self.login_user_context(self.get_superuser()):
         response = self.client.post(
             self.get_admin_url(PageContent, "set_home_content",
                                pagecontent.pk))
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.content.decode("utf-8"),
                      "The page is not eligible to be home.")
     self.assertFalse(pagecontent.page.is_home)
Пример #4
0
    def test_when_old_home_tree_is_none_should_not_trigger_signal(self):
        version = PageVersionFactory(content__page__node__depth=1, state=PUBLISHED)
        pagecontent = version.content

        with self.login_user_context(self.get_superuser()), patch(
            "djangocms_pageadmin.admin.set_restart_trigger"
        ) as mock_handler:
            self.client.post(
                self.get_admin_url(PageContent, "set_home_content", pagecontent.pk)
            )

            mock_handler.assert_not_called()
Пример #5
0
 def test_set_home_link(self):
     version = PageVersionFactory(state=PUBLISHED)
     pagecontent = version.content
     func = self.modeladmin._list_actions(self.get_request("/"))
     response = func(pagecontent)
     soup = parse_html(response)
     element = soup.find("a", {"class": "cms-page-admin-action-set-home"})
     self.assertEqual(element["title"], "Set as a home")
     self.assertEqual(
         element["href"],
         reverse("admin:cms_pagecontent_set_home_content", args=(version.pk,)),
     )
Пример #6
0
    def test_root_page_is_allowed_to_set_home(self):
        version = PageVersionFactory(content__page__node__depth=1, state=PUBLISHED)
        pagecontent = version.content
        with self.login_user_context(self.get_superuser()):
            response = self.client.post(
                self.get_admin_url(PageContent, "set_home_content", pagecontent.pk)
            )
        url = reverse("admin:cms_pagecontent_changelist")
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, url)

        pagecontent.page.refresh_from_db()
        self.assertTrue(pagecontent.page.is_home)
 def test_duplicate_link(self):
     version = PageVersionFactory(state=PUBLISHED)
     pagecontent = version.content
     func = self.modeladmin._list_actions(self.get_request("/"))
     response = func(pagecontent)
     soup = parse_html(response)
     element = soup.find("a", {"class": "cms-page-admin-action-duplicate"})
     self.assertIsNotNone(
         element, "Missing a.cms-page-admin-action-duplicate element")
     self.assertEqual(element["title"], "Duplicate")
     self.assertEqual(
         element["href"],
         reverse("admin:cms_pagecontent_duplicate", args=(version.pk, )),
     )
Пример #8
0
    def test_permission_to_set_home_page(self):
        version = PageVersionFactory(content__page__node__depth=1, state=PUBLISHED)
        pagecontent = version.content
        with self.login_user_context(self.get_superuser()), patch(
            "cms.models.pagemodel.Page.has_change_permission", return_value=False
        ) as mock:
            response = self.client.post(
                self.get_admin_url(PageContent, "set_home_content", pagecontent.pk)
            )

        self.assertEqual(mock.call_count, 1)
        self.assertEqual(response.status_code, 403)

        pagecontent.page.refresh_from_db()
        self.assertFalse(pagecontent.page.is_home)
Пример #9
0
 def test_pages_menu_item_url_has_no_params(self):
     """
     Create a page and get the toolbar for that page's preview
     Then check that the page menu item URL does not have an id parameter
     in the query string, so as not to trigger filters
     """
     user = self.get_superuser()
     pagecontent = PageVersionFactory(content__template="")
     toolbar = get_toolbar(
         pagecontent.content,
         user=user,
         toolbar_class=PageAdminToolbar,
         preview_mode=True,
     )
     toolbar.post_template_populate()
     menu = toolbar.toolbar.get_menu("admin-menu")
     pagemenu = menu.get_items()[0]
     self.assertEqual("/en/admin/cms/pagecontent/", pagemenu.url)
Пример #10
0
 def test_edit_link(self):
     user = UserFactory()
     version = PageVersionFactory(created_by=user)
     pagecontent = version.content
     request = self.get_request("/")
     request.user = user
     func = self.modeladmin._list_actions(request)
     response = func(pagecontent)
     soup = parse_html(response)
     element = soup.find("a", {"class": "cms-page-admin-action-edit"})
     self.assertIsNotNone(element, "Missing a.cms-page-admin-action-edit element")
     self.assertEqual(element["title"], "Edit")
     self.assertEqual(
         element["href"],
         reverse(
             "admin:djangocms_versioning_pagecontentversion_edit_redirect",
             args=(version.pk,),
         ),
     )