def test_permission_forms(self):
        page = create_page("page_b", "nav_playground.html", "en", created_by=self.get_superuser())
        normal_user = self._create_user("randomuser", is_staff=True, add_default_permissions=True)
        assign_user_to_page(page, normal_user, can_view=True, can_change=True)

        with self.login_user_context(self.get_superuser()):
            response = self.client.get("/en/admin/cms/page/%s/permission-settings/" % page.pk)
            self.assertEqual(response.status_code, 200)
            response = self.client.get("/en/admin/cms/page/%s/permissions/" % page.pk)
            self.assertEqual(response.status_code, 200)

        with self.settings(CMS_RAW_ID_USERS=True):
            data = {"page": page.pk, "grant_on": "hello"}
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            data = {"page": page.pk, "grant_on": ACCESS_PAGE}
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertTrue(form.is_valid())
            form.save()

            data = {"page": page.pk, "grant_on": ACCESS_PAGE_AND_CHILDREN, "can_add": "1", "can_change": ""}
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            self.assertTrue("<li>Add page permission also requires edit page " "permission.</li>" in str(form.errors))
            data = {"page": page.pk, "grant_on": ACCESS_PAGE, "can_add": "1"}
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            self.assertTrue(
                "<li>Add page permission requires also access to children, or "
                "descendants, otherwise added page can&#39;t be changed by its "
                "creator.</li>" in str(form.errors)
            )
示例#2
0
    def test_permission_forms(self):
        page = create_page("page_b",
                           "nav_playground.html",
                           "en",
                           created_by=self.get_superuser())
        normal_user = self._create_user("randomuser",
                                        is_staff=True,
                                        add_default_permissions=True)
        assign_user_to_page(page, normal_user, can_view=True, can_change=True)

        with self.login_user_context(self.get_superuser()):
            response = self.client.get(
                "/en/admin/cms/page/%s/permission-settings/" % page.pk)
            self.assertEqual(response.status_code, 200)
            response = self.client.get("/en/admin/cms/page/%s/permissions/" %
                                       page.pk)
            self.assertEqual(response.status_code, 200)

        with self.settings(CMS_RAW_ID_USERS=True):
            data = {
                'page': page.pk,
                'grant_on': "hello",
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE,
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertTrue(form.is_valid())
            form.save()

            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE_AND_CHILDREN,
                'can_add': '1',
                'can_change': ''
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            self.assertEqual(
                str(form.errors),
                '<ul class="errorlist"><li>__all__<ul class="errorlist"><li>Add page permission also '
                'requires edit page permission.</li></ul></li></ul>')
            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE,
                'can_add': '1',
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            self.assertEqual(
                str(form.errors),
                '<ul class="errorlist"><li>__all__<ul class="errorlist"><li>Add page permission requires '
                'also access to children, or descendants, otherwise added page can&#39;t be changed by '
                'its creator.</li></ul></li></ul>')
示例#3
0
    def test_permission_forms(self):
        page = create_page("page_b", "nav_playground.html", "en",
                           created_by=self.get_superuser())
        normal_user = self._create_user("randomuser", is_staff=True, add_default_permissions=True)
        assign_user_to_page(page, normal_user, can_view=True,
                            can_change=True)

        with self.login_user_context(self.get_superuser()):
            response = self.client.get(URL_CMS_PAGE_PERMISSION_CHANGE % page.pk)
            self.assertEqual(response.status_code, 200)
            response = self.client.get(URL_CMS_PAGE_PERMISSIONS % page.pk)
            self.assertEqual(response.status_code, 200)

        with self.settings(CMS_RAW_ID_USERS=True):
            data = {
                'page': page.pk,
                'grant_on': "hello",
                'user': normal_user.pk,
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE,
                'user': normal_user.pk,
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertTrue(form.is_valid())
            form.save()

            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE_AND_CHILDREN,
                'can_add': '1',
                'can_change': '',
                'user': normal_user.pk,
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)

            error_message = ("<li>Users can&#39;t create a page without permissions "
                             "to change the created page. Edit permissions required.</li>")
            self.assertFalse(form.is_valid())
            self.assertTrue(error_message in str(form.errors))
            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE,
                'can_add': '1',
                'can_change': '1',
                'user': normal_user.pk,

            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            self.assertTrue('<li>Add page permission requires also access to children, or '
                            'descendants, otherwise added page can&#39;t be changed by its '
                            'creator.</li>' in str(form.errors))
示例#4
0
    def test_permission_forms(self):
        page = create_page("page_b", "nav_playground.html", "en",
                           created_by=self.get_superuser())
        normal_user = self._create_user("randomuser", is_staff=True, add_default_permissions=True)
        assign_user_to_page(page, normal_user, can_view=True,
                            can_change=True)

        with self.login_user_context(self.get_superuser()):
            response = self.client.get(URL_CMS_PAGE_PERMISSION_CHANGE % page.pk)
            self.assertEqual(response.status_code, 200)
            response = self.client.get(URL_CMS_PAGE_PERMISSIONS % page.pk)
            self.assertEqual(response.status_code, 200)

        with self.settings(CMS_RAW_ID_USERS=True):
            data = {
                'page': page.pk,
                'grant_on': "hello",
                'user': normal_user.pk,
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE,
                'user': normal_user.pk,
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertTrue(form.is_valid())
            form.save()

            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE_AND_CHILDREN,
                'can_add': '1',
                'can_change': '',
                'user': normal_user.pk,
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)

            error_message = ("<li>Users can&#39;t create a page without permissions "
                             "to change the created page. Edit permissions required.</li>")
            self.assertFalse(form.is_valid())
            self.assertTrue(error_message in str(form.errors))
            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE,
                'can_add': '1',
                'can_change': '1',
                'user': normal_user.pk,

            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            self.assertTrue('<li>Add page permission requires also access to children, or '
                            'descendants, otherwise added page can&#39;t be changed by its '
                            'creator.</li>' in str(form.errors))
示例#5
0
文件: forms.py 项目: amaozhao/basecms
    def test_permission_forms(self):
        page = create_page("page_b", "nav_playground.html", "en",
                           created_by=self.get_superuser())
        normal_user = self._create_user("randomuser", is_staff=True, add_default_permissions=True)
        assign_user_to_page(page, normal_user, can_view=True,
                            can_change=True)

        with self.login_user_context(self.get_superuser()):
            response = self.client.get("/en/admin/cms/page/%s/permission-settings/" % page.pk)
            self.assertEqual(response.status_code, 200)
            response = self.client.get("/en/admin/cms/page/%s/permissions/" % page.pk)
            self.assertEqual(response.status_code, 200)

        with SettingsOverride(CMS_RAW_ID_USERS=True):
            data = {
                'page': page.pk,
                'grant_on': "hello",
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE,
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertTrue(form.is_valid())
            form.save()

            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE_AND_CHILDREN,
                'can_add': '1',
                'can_change': ''
            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            self.assertEqual(str(form.errors),
                             '<ul class="errorlist"><li>__all__<ul class="errorlist"><li>Add page permission also '
                             'requires edit page permission.</li></ul></li></ul>')
            data = {
                'page': page.pk,
                'grant_on': ACCESS_PAGE,
                'can_add': '1',

            }
            form = PagePermissionInlineAdminForm(data=data, files=None)
            self.assertFalse(form.is_valid())
            self.assertEqual(str(form.errors),
                             '<ul class="errorlist"><li>__all__<ul class="errorlist"><li>Add page permission requires '
                             'also access to children, or descendants, otherwise added page can&#39;t be changed by '
                             'its creator.</li></ul></li></ul>')