Esempio n. 1
0
    def test_allowed_subpage_types(self):
        # SimplePage does not define any restrictions on subpage types
        # SimplePage is a valid subpage of SimplePage
        self.assertIn(ContentType.objects.get_for_model(SimplePage),
                      SimplePage.allowed_subpage_types())
        # BusinessIndex is a valid subpage of SimplePage
        self.assertIn(ContentType.objects.get_for_model(BusinessIndex),
                      SimplePage.allowed_subpage_types())
        # BusinessSubIndex is not valid, because it explicitly omits SimplePage from parent_page_types
        self.assertNotIn(ContentType.objects.get_for_model(BusinessSubIndex),
                         SimplePage.allowed_subpage_types())

        # BusinessChild has an empty subpage_types list, so does not allow anything
        self.assertNotIn(ContentType.objects.get_for_model(SimplePage),
                         BusinessChild.allowed_subpage_types())
        self.assertNotIn(ContentType.objects.get_for_model(BusinessIndex),
                         BusinessChild.allowed_subpage_types())
        self.assertNotIn(ContentType.objects.get_for_model(BusinessSubIndex),
                         BusinessChild.allowed_subpage_types())

        # BusinessSubIndex only allows BusinessChild as subpage type
        self.assertNotIn(ContentType.objects.get_for_model(SimplePage),
                         BusinessSubIndex.allowed_subpage_types())
        self.assertIn(ContentType.objects.get_for_model(BusinessChild),
                      BusinessSubIndex.allowed_subpage_types())
Esempio n. 2
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()))
Esempio n. 3
0
    def test_can_exist_under(self):
        self.assertTrue(SimplePage.can_exist_under(SimplePage()))

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

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

        self.assertFalse(BusinessSubIndex.can_exist_under(SimplePage()))
        self.assertFalse(BusinessSubIndex.can_exist_under(BusinessSubIndex()))
        self.assertFalse(BusinessChild.can_exist_under(SimplePage()))
Esempio n. 4
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()
Esempio n. 5
0
    def test_allowed_subpage_models(self):
        # SimplePage does not define any restrictions on subpage types
        # SimplePage is a valid subpage of SimplePage
        self.assertIn(SimplePage, SimplePage.allowed_subpage_models())
        # BusinessIndex is a valid subpage of SimplePage
        self.assertIn(BusinessIndex, SimplePage.allowed_subpage_models())
        # BusinessSubIndex is not valid, because it explicitly omits SimplePage from parent_page_types
        self.assertNotIn(BusinessSubIndex, SimplePage.allowed_subpage_models())

        # BusinessChild has an empty subpage_types list, so does not allow anything
        self.assertNotIn(SimplePage, BusinessChild.allowed_subpage_models())
        self.assertNotIn(BusinessIndex, BusinessChild.allowed_subpage_models())
        self.assertNotIn(BusinessSubIndex, BusinessChild.allowed_subpage_models())

        # BusinessSubIndex only allows BusinessChild as subpage type
        self.assertNotIn(SimplePage, BusinessSubIndex.allowed_subpage_models())
        self.assertIn(BusinessChild, BusinessSubIndex.allowed_subpage_models())
Esempio n. 6
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()))
Esempio n. 7
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()))
Esempio n. 8
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)
Esempio n. 9
0
    def test_allowed_subpage_types(self):
        """
        Same assertions as for test_allowed_subpage_models -
        allowed_subpage_types should mirror allowed_subpage_models with ContentType
        objects rather than model classes
        """

        with self.ignore_deprecation_warnings():
            # SimplePage does not define any restrictions on subpage types
            # SimplePage is a valid subpage of SimplePage
            self.assertIn(get_ct(SimplePage), SimplePage.allowed_subpage_types())
            # BusinessIndex is a valid subpage of SimplePage
            self.assertIn(get_ct(BusinessIndex), SimplePage.allowed_subpage_types())
            # BusinessSubIndex is not valid, because it explicitly omits SimplePage from parent_page_types
            self.assertNotIn(get_ct(BusinessSubIndex), SimplePage.allowed_subpage_types())

            # BusinessChild has an empty subpage_types list, so does not allow anything
            self.assertNotIn(get_ct(SimplePage), BusinessChild.allowed_subpage_types())
            self.assertNotIn(get_ct(BusinessIndex), BusinessChild.allowed_subpage_types())
            self.assertNotIn(get_ct(BusinessSubIndex), BusinessChild.allowed_subpage_types())

            # BusinessSubIndex only allows BusinessChild as subpage type
            self.assertNotIn(get_ct(SimplePage), BusinessSubIndex.allowed_subpage_types())
            self.assertIn(get_ct(BusinessChild), BusinessSubIndex.allowed_subpage_types())
Esempio n. 10
0
    def test_allowed_subpage_types(self):
        """
        Same assertions as for test_allowed_subpage_models -
        allowed_subpage_types should mirror allowed_subpage_models with ContentType
        objects rather than model classes
        """

        with self.ignore_deprecation_warnings():
            # SimplePage does not define any restrictions on subpage types
            # SimplePage is a valid subpage of SimplePage
            self.assertIn(get_ct(SimplePage), SimplePage.allowed_subpage_types())
            # BusinessIndex is a valid subpage of SimplePage
            self.assertIn(get_ct(BusinessIndex), SimplePage.allowed_subpage_types())
            # BusinessSubIndex is not valid, because it explicitly omits SimplePage from parent_page_types
            self.assertNotIn(get_ct(BusinessSubIndex), SimplePage.allowed_subpage_types())

            # BusinessChild has an empty subpage_types list, so does not allow anything
            self.assertNotIn(get_ct(SimplePage), BusinessChild.allowed_subpage_types())
            self.assertNotIn(get_ct(BusinessIndex), BusinessChild.allowed_subpage_types())
            self.assertNotIn(get_ct(BusinessSubIndex), BusinessChild.allowed_subpage_types())

            # BusinessSubIndex only allows BusinessChild as subpage type
            self.assertNotIn(get_ct(SimplePage), BusinessSubIndex.allowed_subpage_types())
            self.assertIn(get_ct(BusinessChild), BusinessSubIndex.allowed_subpage_types())
Esempio n. 11
0
    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())
Esempio n. 12
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())
Esempio n. 13
0
    def test_bulk_move_destination_not_allowed(self):
        page = BusinessChild(title="Section no child", slug="section-no-child")
        self.root_page.add_child(instance=page)

        response = self.client.post(self.url, {'chooser': page.id})

        html = response.content.decode()

        self.assertInHTML(
            '<p>The following pages cannot be moved to {}</p>'.format(
                page.title), html)

        for child_page in self.pages_to_be_moved:
            self.assertInHTML(
                '<li><a href="{edit_page_url}" target="_blank" rel="noopener noreferrer">{page_title}</a></li>'
                .format(edit_page_url=reverse('wagtailadmin_pages:edit',
                                              args=[child_page.id]),
                        page_title=child_page.title), html)