def setUp(self):
        homepage = Page.objects.get(url_path='/home/')
        business_index = BusinessIndex(title='Public Business Index')
        homepage.add_child(instance=business_index)

        another_business_index = BusinessIndex(title='Another Business Index')
        homepage.add_child(instance=another_business_index)

        secret_business_index = BusinessIndex(title='Private Business Index')
        homepage.add_child(instance=secret_business_index)

        business_editors = Group.objects.create(name='Business editors')
        business_editors.permissions.add(
            Permission.objects.get(codename='access_admin'))
        GroupPagePermission.objects.create(group=business_editors,
                                           page=business_index,
                                           permission_type='add')
        GroupPagePermission.objects.create(group=business_editors,
                                           page=another_business_index,
                                           permission_type='add')

        user = get_user_model().objects._create_user(username='******',
                                                     email='*****@*****.**',
                                                     password='******',
                                                     is_staff=True,
                                                     is_superuser=False)
        user.groups.add(business_editors)
        # Login
        self.client.login(username='******', password='******')
示例#2
0
class TestUserbarAddLink(TestCase, WagtailTestUtils):
    fixtures = ['test.json']

    def setUp(self):
        self.login()
        self.homepage = Page.objects.get(url_path='/home/')
        self.event_index = Page.objects.get(url_path='/home/events/')

        self.business_index = BusinessIndex(title='Business', live=True)
        self.homepage.add_child(instance=self.business_index)

        self.business_child = BusinessChild(title='Business Child', live=True)
        self.business_index.add_child(instance=self.business_child)

    def test_page_allowing_subpages(self):
        response = self.client.get(reverse('wagtailadmin_userbar_frontend', args=(self.event_index.id, )))

        # page allows subpages, so the 'add page' button should show
        expected_url = reverse('wagtailadmin_pages:add_subpage', args=(self.event_index.id, ))
        expected_link = '<a href="%s" target="_parent">Add a child page</a>' \
            % expected_url
        self.assertContains(response, expected_link)

    def test_page_disallowing_subpages(self):
        response = self.client.get(reverse('wagtailadmin_userbar_frontend', args=(self.business_child.id, )))

        # page disallows subpages, so the 'add page' button shouldn't show
        expected_url = reverse('wagtailadmin_pages:add_subpage', args=(self.business_index.id, ))
        expected_link = '<a href="%s" target="_parent">Add a child page</a>' \
            % expected_url
        self.assertNotContains(response, expected_link)
class TestUserbarAddLink(TestCase, WagtailTestUtils):
    fixtures = ["test.json"]

    def setUp(self):
        self.login()
        self.homepage = Page.objects.get(url_path="/home/")
        self.event_index = Page.objects.get(url_path="/home/events/")

        self.business_index = BusinessIndex(title="Business", slug="business", live=True)
        self.homepage.add_child(instance=self.business_index)

        self.business_child = BusinessChild(title="Business Child", slug="child", live=True)
        self.business_index.add_child(instance=self.business_child)

    def test_page_allowing_subpages(self):
        response = self.client.get(reverse("wagtailadmin_userbar_frontend", args=(self.event_index.id,)))

        # page allows subpages, so the 'add page' button should show
        expected_url = reverse("wagtailadmin_pages:add_subpage", args=(self.event_index.id,))
        expected_link = (
            '<a href="%s" target="_parent" class="action icon icon-plus" title="Add a child page">Add</a>'
            % expected_url
        )
        self.assertContains(response, expected_link)

    def test_page_disallowing_subpages(self):
        response = self.client.get(reverse("wagtailadmin_userbar_frontend", args=(self.business_child.id,)))

        # page disallows subpages, so the 'add page' button shouldn't show
        expected_url = reverse("wagtailadmin_pages:add_subpage", args=(self.business_index.id,))
        expected_link = (
            '<a href="%s" target="_parent" class="action icon icon-plus" title="Add a child page">Add</a>'
            % expected_url
        )
        self.assertNotContains(response, expected_link)
示例#4
0
class TestUserbarAddLink(TestCase, WagtailTestUtils):
    fixtures = ['test.json']

    def setUp(self):
        self.login()
        self.homepage = Page.objects.get(url_path='/home/')
        self.event_index = Page.objects.get(url_path='/home/events/')

        self.business_index = BusinessIndex(title='Business', live=True)
        self.homepage.add_child(instance=self.business_index)

        self.business_child = BusinessChild(title='Business Child', live=True)
        self.business_index.add_child(instance=self.business_child)

    def test_page_allowing_subpages(self):
        response = self.client.get(reverse('wagtailadmin_userbar_frontend', args=(self.event_index.id, )))

        # page allows subpages, so the 'add page' button should show
        expected_url = reverse('wagtailadmin_pages:add_subpage', args=(self.event_index.id, ))
        expected_link = '<a href="%s" target="_parent">Add a child page</a>' \
            % expected_url
        self.assertContains(response, expected_link)

    def test_page_disallowing_subpages(self):
        response = self.client.get(reverse('wagtailadmin_userbar_frontend', args=(self.business_child.id, )))

        # page disallows subpages, so the 'add page' button shouldn't show
        expected_url = reverse('wagtailadmin_pages:add_subpage', args=(self.business_index.id, ))
        expected_link = '<a href="%s" target="_parent">Add a child page</a>' \
            % expected_url
        self.assertNotContains(response, expected_link)
示例#5
0
    def setUp(self):
        # Find root page
        self.root_page = Page.objects.get(id=2)

        # Add standard page (allows subpages of any type)
        self.standard_index = StandardIndex()
        self.standard_index.title = "Standard Index"
        self.standard_index.slug = "standard-index"
        self.root_page.add_child(instance=self.standard_index)

        # Add business page (allows BusinessChild and BusinessSubIndex as subpages)
        self.business_index = BusinessIndex()
        self.business_index.title = "Business Index"
        self.business_index.slug = "business-index"
        self.root_page.add_child(instance=self.business_index)

        # Add business child (allows no subpages)
        self.business_child = BusinessChild()
        self.business_child.title = "Business Child"
        self.business_child.slug = "business-child"
        self.business_index.add_child(instance=self.business_child)

        # Add business subindex (allows only BusinessChild as subpages)
        self.business_subindex = BusinessSubIndex()
        self.business_subindex.title = "Business Subindex"
        self.business_subindex.slug = "business-subindex"
        self.business_index.add_child(instance=self.business_subindex)

        # Login
        self.login()
示例#6
0
    def setUp(self):
        homepage = Page.objects.get(url_path='/home/')
        business_index = BusinessIndex(
            title='Public Business Index',
            draft_title='Public Business Index',
        )
        homepage.add_child(instance=business_index)

        another_business_index = BusinessIndex(
            title='Another Business Index',
            draft_title='Another Business Index',
        )
        homepage.add_child(instance=another_business_index)

        secret_business_index = BusinessIndex(
            title='Private Business Index',
            draft_title='Private Business Index',
        )
        homepage.add_child(instance=secret_business_index)

        business_editors = Group.objects.create(name='Business editors')
        business_editors.permissions.add(
            Permission.objects.get(codename='access_admin'))
        GroupPagePermission.objects.create(group=business_editors,
                                           page=business_index,
                                           permission_type='add')
        GroupPagePermission.objects.create(group=business_editors,
                                           page=another_business_index,
                                           permission_type='add')

        user = self.create_user(username='******', password='******')
        user.groups.add(business_editors)
        # Login
        self.login(username='******', password='******')
示例#7
0
    def setUp(self):
        self.login()
        self.homepage = Page.objects.get(url_path='/home/')
        self.event_index = Page.objects.get(url_path='/home/events/')

        self.business_index = BusinessIndex(title='Business', live=True)
        self.homepage.add_child(instance=self.business_index)

        self.business_child = BusinessChild(title='Business Child', live=True)
        self.business_index.add_child(instance=self.business_child)
示例#8
0
    def test_can_move_to(self):
        self.assertTrue(SimplePage().can_move_to(SimplePage()))

        # StandardIndex should only be allowed under a Page
        self.assertTrue(StandardIndex().can_move_to(Page()))
        self.assertFalse(StandardIndex().can_move_to(SimplePage()))

        # The Business pages are quite restrictive in their structure
        self.assertTrue(BusinessSubIndex().can_move_to(BusinessIndex()))
        self.assertTrue(BusinessChild().can_move_to(BusinessIndex()))
        self.assertTrue(BusinessChild().can_move_to(BusinessSubIndex()))

        self.assertFalse(BusinessChild().can_move_to(SimplePage()))
        self.assertFalse(BusinessSubIndex().can_move_to(SimplePage()))
示例#9
0
    def test_can_create_at(self):
        # Pages are not `is_creatable`, and should not be creatable
        self.assertFalse(Page.can_create_at(Page()))

        # SimplePage can be created under a simple page
        self.assertTrue(SimplePage.can_create_at(SimplePage()))

        # StandardIndex can be created under a Page, but not a SimplePage
        self.assertTrue(StandardIndex.can_create_at(Page()))
        self.assertFalse(StandardIndex.can_create_at(SimplePage()))

        # The Business pages are quite restrictive in their structure
        self.assertTrue(BusinessSubIndex.can_create_at(BusinessIndex()))
        self.assertTrue(BusinessChild.can_create_at(BusinessIndex()))
        self.assertTrue(BusinessChild.can_create_at(BusinessSubIndex()))

        self.assertFalse(BusinessChild.can_create_at(SimplePage()))
        self.assertFalse(BusinessSubIndex.can_create_at(SimplePage()))
示例#10
0
    def test_add_subpage_with_one_valid_subpage_type(self):
        # Add a BusinessSubIndex to test business rules in
        business_index = BusinessIndex(
            title="Hello world!",
            slug="hello-world",
        )
        self.root_page.add_child(instance=business_index)
        business_subindex = BusinessSubIndex(
            title="Hello world!",
            slug="hello-world",
        )
        business_index.add_child(instance=business_subindex)

        response = self.client.get(reverse('wagtailadmin_pages:add_subpage', args=(business_subindex.id, )))
        # Should be redirected to the 'add' page for BusinessChild, the only valid subpage type
        self.assertRedirects(
            response,
            reverse('wagtailadmin_pages:add', args=('tests', 'businesschild', business_subindex.id))
        )
    def setUp(self):
        self.login()
        self.homepage = Page.objects.get(url_path="/home/")
        self.event_index = Page.objects.get(url_path="/home/events/")

        self.business_index = BusinessIndex(title="Business", slug="business", live=True)
        self.homepage.add_child(instance=self.business_index)

        self.business_child = BusinessChild(title="Business Child", slug="child", live=True)
        self.business_index.add_child(instance=self.business_child)
示例#12
0
class TestUserbarAddLink(TestCase, WagtailTestUtils):
    fixtures = ['test.json']

    def setUp(self):
        self.login()
        self.homepage = Page.objects.get(url_path='/home/')
        self.event_index = Page.objects.get(url_path='/home/events/')

        self.business_index = BusinessIndex(title='Business', live=True)
        self.homepage.add_child(instance=self.business_index)

        self.business_child = BusinessChild(title='Business Child', live=True)
        self.business_index.add_child(instance=self.business_child)

    def test_page_allowing_subpages(self):
        response = self.client.get(
            reverse('wagtailadmin_userbar_frontend',
                    args=(self.event_index.id, )))

        # page allows subpages, so the 'add page' button should show
        expected_url = reverse('wagtailadmin_pages:add_subpage',
                               args=(self.event_index.id, ))
        needle = f"""
            <a href="{expected_url}" target="_parent">
                <svg class="icon icon-plus wagtail-action-icon" aria-hidden="true" focusable="false">
                    <use href="#icon-plus"></use>
                </svg>
                Add a child page
            </a>
            """
        self.assertTagInHTML(needle, str(response.content))

    def test_page_disallowing_subpages(self):
        response = self.client.get(
            reverse('wagtailadmin_userbar_frontend',
                    args=(self.business_child.id, )))

        # page disallows subpages, so the 'add page' button shouldn't show
        expected_url = reverse('wagtailadmin_pages:add_subpage',
                               args=(self.business_index.id, ))
        expected_link = '<a href="%s" target="_parent">Add a child page</a>' \
            % expected_url
        self.assertNotContains(response, expected_link)
示例#13
0
    def setUp(self):
        self.login()
        self.homepage = Page.objects.get(url_path='/home/')
        self.event_index = Page.objects.get(url_path='/home/events/')

        self.business_index = BusinessIndex(title='Business', live=True)
        self.homepage.add_child(instance=self.business_index)

        self.business_child = BusinessChild(title='Business Child', live=True)
        self.business_index.add_child(instance=self.business_child)
示例#14
0
    def test_one_parent_exists(self):
        # Create a BusinessIndex page that BusinessChild can exist under
        homepage = Page.objects.get(url_path='/home/')
        business_index = BusinessIndex(title='Business Index')
        homepage.add_child(instance=business_index)

        # When one possible parent page exists, redirect straight to the page create view
        response = self.client.get('/admin/tests/businesschild/create/')

        expected_path = '/admin/pages/add/tests/businesschild/%d/' % business_index.pk
        expected_next_path = '/admin/tests/businesschild/'
        self.assertRedirects(response, '%s?next=%s' % (expected_path, expected_next_path))
示例#15
0
    def test_add_subpage_with_subpage_types(self):
        # Add a BusinessIndex to test business rules in
        business_index = BusinessIndex(
            title="Hello world!",
            slug="hello-world",
        )
        self.root_page.add_child(instance=business_index)

        response = self.client.get(reverse('wagtailadmin_pages:add_subpage', args=(business_index.id, )))
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, "Business child")
        # List should not contain page types not in the subpage_types list
        self.assertNotContains(response, "Simple page")
示例#16
0
    def test_cannot_create_page_with_wrong_subpage_types(self):
        # Add a BusinessIndex to test business rules in
        business_index = BusinessIndex(
            title="Hello world!",
            slug="hello-world",
        )
        self.root_page.add_child(instance=business_index)

        # BusinessIndex has limited subpage_types, so attempting to add a SimplePage
        # underneath it should fail with permission denied
        response = self.client.get(
            reverse('wagtailadmin_pages:add',
                    args=('tests', 'simplepage', business_index.id)))
        self.assertEqual(response.status_code, 403)
示例#17
0
    def test_standard_subpage(self):
        add_subpage_url = reverse('wagtailadmin_pages:add_subpage', args=(self.standard_index.id, ))

        # explorer should contain a link to 'add child page'
        response = self.client.get(reverse('wagtailadmin_explore', args=(self.standard_index.id, )))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, add_subpage_url)

        # add_subpage should give us choices of StandardChild, and BusinessIndex.
        # BusinessSubIndex and BusinessChild are not allowed
        response = self.client.get(add_subpage_url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, StandardChild.get_verbose_name())
        self.assertContains(response, BusinessIndex.get_verbose_name())
        self.assertNotContains(response, BusinessSubIndex.get_verbose_name())
        self.assertNotContains(response, BusinessChild.get_verbose_name())
示例#18
0
class TestSubpageBusinessRules(TestCase, WagtailTestUtils):
    def setUp(self):
        # Find root page
        self.root_page = Page.objects.get(id=2)

        # Add standard page (allows subpages of any type)
        self.standard_index = StandardIndex()
        self.standard_index.title = "Standard Index"
        self.standard_index.slug = "standard-index"
        self.root_page.add_child(instance=self.standard_index)

        # Add business page (allows BusinessChild and BusinessSubIndex as subpages)
        self.business_index = BusinessIndex()
        self.business_index.title = "Business Index"
        self.business_index.slug = "business-index"
        self.root_page.add_child(instance=self.business_index)

        # Add business child (allows no subpages)
        self.business_child = BusinessChild()
        self.business_child.title = "Business Child"
        self.business_child.slug = "business-child"
        self.business_index.add_child(instance=self.business_child)

        # Add business subindex (allows only BusinessChild as subpages)
        self.business_subindex = BusinessSubIndex()
        self.business_subindex.title = "Business Subindex"
        self.business_subindex.slug = "business-subindex"
        self.business_index.add_child(instance=self.business_subindex)

        # Login
        self.login()

    def test_standard_subpage(self):
        add_subpage_url = reverse('wagtailadmin_pages:add_subpage',
                                  args=(self.standard_index.id, ))

        # explorer should contain a link to 'add child page'
        response = self.client.get(
            reverse('wagtailadmin_explore', args=(self.standard_index.id, )))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, add_subpage_url)

        # add_subpage should give us choices of StandardChild, and BusinessIndex.
        # BusinessSubIndex and BusinessChild are not allowed
        response = self.client.get(add_subpage_url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, StandardChild.get_verbose_name())
        self.assertContains(response, BusinessIndex.get_verbose_name())
        self.assertNotContains(response, BusinessSubIndex.get_verbose_name())
        self.assertNotContains(response, BusinessChild.get_verbose_name())

    def test_business_subpage(self):
        add_subpage_url = reverse('wagtailadmin_pages:add_subpage',
                                  args=(self.business_index.id, ))

        # explorer should contain a link to 'add child page'
        response = self.client.get(
            reverse('wagtailadmin_explore', args=(self.business_index.id, )))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, add_subpage_url)

        # add_subpage should give us a cut-down set of page types to choose
        response = self.client.get(add_subpage_url)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, StandardIndex.get_verbose_name())
        self.assertNotContains(response, StandardChild.get_verbose_name())
        self.assertContains(response, BusinessSubIndex.get_verbose_name())
        self.assertContains(response, BusinessChild.get_verbose_name())

    def test_business_child_subpage(self):
        add_subpage_url = reverse('wagtailadmin_pages:add_subpage',
                                  args=(self.business_child.id, ))

        # explorer should not contain a link to 'add child page', as this page doesn't accept subpages
        response = self.client.get(
            reverse('wagtailadmin_explore', args=(self.business_child.id, )))
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, add_subpage_url)

        # this also means that fetching add_subpage is blocked at the permission-check level
        response = self.client.get(
            reverse('wagtailadmin_pages:add_subpage',
                    args=(self.business_child.id, )))
        self.assertEqual(response.status_code, 403)

    def test_cannot_add_invalid_subpage_type(self):
        # cannot add StandardChild as a child of BusinessIndex, as StandardChild is not present in subpage_types
        response = self.client.get(
            reverse('wagtailadmin_pages:add',
                    args=('tests', 'standardchild', self.business_index.id)))
        self.assertEqual(response.status_code, 403)

        # likewise for BusinessChild which has an empty subpage_types list
        response = self.client.get(
            reverse('wagtailadmin_pages:add',
                    args=('tests', 'standardchild', self.business_child.id)))
        self.assertEqual(response.status_code, 403)

        # cannot add BusinessChild to StandardIndex, as BusinessChild restricts is parent page types
        response = self.client.get(
            reverse('wagtailadmin_pages:add',
                    args=('tests', 'businesschild', self.standard_index.id)))
        self.assertEqual(response.status_code, 403)

        # but we can add a BusinessChild to BusinessIndex
        response = self.client.get(
            reverse('wagtailadmin_pages:add',
                    args=('tests', 'businesschild', self.business_index.id)))
        self.assertEqual(response.status_code, 200)

    def test_not_prompted_for_page_type_when_only_one_choice(self):
        response = self.client.get(
            reverse('wagtailadmin_pages:add_subpage',
                    args=(self.business_subindex.id, )))
        # BusinessChild is the only valid subpage type of BusinessSubIndex, so redirect straight there
        self.assertRedirects(
            response,
            reverse('wagtailadmin_pages:add',
                    args=('tests', 'businesschild',
                          self.business_subindex.id)))