def test_root_page_without_trailing_slash(self): page = PageFactory.create(title='Hello') self.assertEqual(page.slug, 'hello') with self.assertNumQueries(0): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/hello')
def test_fetch_non_root_draft_page(self): root = PageFactory.create(title='root') PageFactory.create(title='child', parent=root, draft=True) with self.assertNumQueries(2): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/root/child/')
def test_fetch_path_with_existent_prefix_fails_on_nonexistent_suffix(self): root = PageFactory.create(title='root') PageFactory.create(title='child', parent=root) with self.assertNumQueries(2): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/root/child/foobar/')
def test_fetch_child_page_without_path_fails(self): root = PageFactory.create(title='root') PageFactory.create(title='child', parent=root) with self.assertNumQueries(1): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/child/')
def test_raises_http_404_on_empty_request(self): with self.assertNumQueries(0): with self.assertRaises(Page.DoesNotExist): get_page_from_path('') with self.assertRaises(Page.DoesNotExist): get_page_from_path('/')
def test_fetch_unpublished_page_fails(self): page = PageFactory.create(title='Hello', draft=True) self.assertEqual(page.slug, 'hello') with self.assertNumQueries(1): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/hello/')
def test_fetch_path_with_wrong_parent(self): root = PageFactory.create(title='root') child = PageFactory.create(title='child', parent=root) PageFactory.create(title='grandchild', parent=child) with self.assertNumQueries(2): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/root/grandchild/')
def test_fetch_path_with_missing_part_halfway_through(self): root = PageFactory.create(title='root') child = PageFactory.create(title='child', parent=root) PageFactory.create(title='grandchild', parent=child) with self.assertNumQueries(2): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/root/foobar/child/')
def test_fetch_child_page_without_trailing_slash(self): root = PageFactory.create(title='root') child = PageFactory.create(title='child', parent=root) child2 = PageFactory.create(title='child2', parent=root) PageFactory.create(title='grandchild', parent=child) PageFactory.create(title='grandchild2', parent=child) PageFactory.create(title='grandchild3', parent=child2) with self.assertNumQueries(0): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/root/child/grandchild')
def automatically_add_page_children(self): # If this navigation element points to a Page, then # automatically add its child pages, provided this navigation # element is top-level. if self.parent: return if not self.url: return try: page = get_page_from_path(self.url) except Page.DoesNotExist: return if page.is_leaf_node(): return children = page.children.filter(draft=False) for child in children: description = child.get_navigation_description() NavigationElement.objects.create(title=child.title, description=description, url='/' + child.get_path(), parent=self, require_login=self.require_login)
def test_fetch_child_page(self): root = PageFactory.create(title='root') child = PageFactory.create(title='child', parent=root) child2 = PageFactory.create(title='child2', parent=root) grandchild = PageFactory.create(title='grandchild', parent=child) PageFactory.create(title='grandchild2', parent=child) PageFactory.create(title='grandchild3', parent=child2) with self.assertNumQueries(2): matched = get_page_from_path('/root/child/grandchild/') self.assertEqual(grandchild, matched)
def test_fetch_child_of_page_with_no_children(self): PageFactory.create(title='root') with self.assertNumQueries(1): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/root/child/')
def test_root_page(self): page = PageFactory.create(title='Hello') self.assertEqual(page.slug, 'hello') with self.assertNumQueries(1): self.assertEqual(page, get_page_from_path('/hello/'))
def test_nonexistent_root_page(self): with self.assertNumQueries(1): with self.assertRaises(Page.DoesNotExist): get_page_from_path('/hello/')