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())
def test_allowed_parent_page_models(self): # SimplePage does not define any restrictions on parent page types # SimplePage is a valid parent page of SimplePage self.assertIn(SimplePage, SimplePage.allowed_parent_page_models()) # BusinessChild cannot be a parent of anything self.assertNotIn(BusinessChild, SimplePage.allowed_parent_page_models()) # BusinessNowherePage does not allow anything as a parent self.assertNotIn(SimplePage, BusinessNowherePage.allowed_parent_page_models()) self.assertNotIn(StandardIndex, BusinessNowherePage.allowed_parent_page_models()) # BusinessSubIndex only allows BusinessIndex as a parent self.assertNotIn(SimplePage, BusinessSubIndex.allowed_parent_page_models()) self.assertIn(BusinessIndex, BusinessSubIndex.allowed_parent_page_models())
def test_allowed_parent_page_types(self): # SimplePage does not define any restrictions on parent page types # SimplePage is a valid parent page of SimplePage self.assertIn(ContentType.objects.get_for_model(SimplePage), SimplePage.allowed_parent_page_types()) # BusinessChild cannot be a parent of anything self.assertNotIn(ContentType.objects.get_for_model(BusinessChild), SimplePage.allowed_parent_page_types()) # StandardIndex does not allow anything as a parent self.assertNotIn(ContentType.objects.get_for_model(SimplePage), StandardIndex.allowed_parent_page_types()) self.assertNotIn(ContentType.objects.get_for_model(StandardIndex), StandardIndex.allowed_parent_page_types()) # BusinessSubIndex only allows BusinessIndex as a parent self.assertNotIn(ContentType.objects.get_for_model(SimplePage), BusinessSubIndex.allowed_parent_page_types()) self.assertIn(ContentType.objects.get_for_model(BusinessIndex), BusinessSubIndex.allowed_parent_page_types())
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()))
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()))
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_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())
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()))
def test_allowed_parent_page_types(self): """ Same assertions as for test_allowed_parent_page_models - allowed_parent_page_types should mirror allowed_parent_page_models with ContentType objects rather than model classes """ with self.ignore_deprecation_warnings(): # SimplePage does not define any restrictions on parent page types # SimplePage is a valid parent page of SimplePage self.assertIn(get_ct(SimplePage), SimplePage.allowed_parent_page_types()) # BusinessChild cannot be a parent of anything self.assertNotIn(get_ct(BusinessChild), SimplePage.allowed_parent_page_types()) # BusinessNowherePage does not allow anything as a parent self.assertNotIn(get_ct(SimplePage), BusinessNowherePage.allowed_parent_page_types()) self.assertNotIn(get_ct(StandardIndex), BusinessNowherePage.allowed_parent_page_types()) # BusinessSubIndex only allows BusinessIndex as a parent self.assertNotIn(get_ct(SimplePage), BusinessSubIndex.allowed_parent_page_types()) self.assertIn(get_ct(BusinessIndex), BusinessSubIndex.allowed_parent_page_types())
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_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())
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_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)) )