コード例 #1
0
    def test_multiple_roots(self):
        root_page = HelpBasePage.objects.get(parent__isnull=True)

        # create a second parallel tree, which should be ignored
        HelpBasePageFactory(
            tree_id=2,
            parent=None,
            lft=root_page.lft,
            rght=root_page.rght,
            level=root_page.level,
        )
        page = get_root_page()
        self.assertEqual(page, root_page)

        # force a broken tree
        HelpBasePageFactory(
            tree_id=1,
            parent=None,
            lft=root_page.lft,
            rght=root_page.rght,
            level=root_page.level,
        )

        with self.assertRaises(AssertionError):
            get_root_page()
コード例 #2
0
    def test_iterators(self):
        root_page = get_root_page()
        self.assertEqual([root_page],
                         [i for i in breadcrumb_iterator(root_page)])

        sub_page = root_page.get_children()[0]
        self.assertEqual([root_page, sub_page],
                         [i for i in breadcrumb_iterator(sub_page)])
コード例 #3
0
def page(request, path):
    path_components = [component for component in path.split('/') if component]
    root_page = get_root_page()
    if root_page is None:
        raise Http404

    page, args, kwargs = root_page.specific.route(request, path_components)

    return page.serve(request, *args, **kwargs)
コード例 #4
0
 def test_no_root(self):
     HelpBasePage.objects.all().delete()
     page = get_root_page()
     self.assertEqual(page, None)
コード例 #5
0
 def test_get_root(self):
     root_page = HelpBasePage.objects.get(parent__isnull=True)
     page = get_root_page()
     self.assertEqual(page, root_page)