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="******")
def setUp(self): # Find root page self.root_page = Page.objects.get(id=2) # root # |- index_page (BusinessIndex) # | |- child_1 (BusinessChild) # | |- child_2 (BusinessChild) # | |- child_3 (BusinessChild) self.index_page = BusinessIndex(title="Simple", slug="simple") self.root_page.add_child(instance=self.index_page) self.child_1 = BusinessChild(title="Child 1 of BusinessIndex", slug="child-1") self.index_page.add_child(instance=self.child_1) self.child_2 = BusinessChild(title="Child 2 of BusinessIndex", slug="child-2") self.index_page.add_child(instance=self.child_2) self.child_3 = BusinessChild(title="Child 3 of BusinessIndex", slug="child-3") self.index_page.add_child(instance=self.child_3) # Login self.user = self.login()
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)
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" role="menuitem"> <svg class="icon icon-plus wagtail-action-icon" aria-hidden="true"> <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)
class TestPageReorderWithParentPageRestrictions(TestPageReorder): """ This testCase is the same as the TestPageReorder class above, but with a different page type: BusinessChild has a parent_page_types restriction. This ensures that this restriction doesn't affect the ability to reorder pages. """ def setUp(self): # Find root page self.root_page = Page.objects.get(id=2) # root # |- index_page (BusinessIndex) # | |- child_1 (BusinessChild) # | |- child_2 (BusinessChild) # | |- child_3 (BusinessChild) self.index_page = BusinessIndex(title="Simple", slug="simple") self.root_page.add_child(instance=self.index_page) self.child_1 = BusinessChild(title="Child 1 of BusinessIndex", slug="child-1") self.index_page.add_child(instance=self.child_1) self.child_2 = BusinessChild(title="Child 2 of BusinessIndex", slug="child-2") self.index_page.add_child(instance=self.child_2) self.child_3 = BusinessChild(title="Child 3 of BusinessIndex", slug="child-3") self.index_page.add_child(instance=self.child_3) # Login self.user = self.login()
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))