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', 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)
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)
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)) )
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)))