Beispiel #1
0
    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')
Beispiel #2
0
    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/')
Beispiel #3
0
    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/')
Beispiel #4
0
    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/')
Beispiel #5
0
    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')
Beispiel #6
0
    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('/')
Beispiel #7
0
    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/')
Beispiel #8
0
    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('/')
Beispiel #9
0
    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/')
Beispiel #10
0
    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/')
Beispiel #11
0
    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/')
Beispiel #12
0
    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/')
Beispiel #13
0
    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/')
Beispiel #14
0
    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/')
Beispiel #15
0
    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/')
Beispiel #16
0
    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/')
Beispiel #17
0
    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')
Beispiel #18
0
    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')
Beispiel #19
0
    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)
Beispiel #20
0
    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)
Beispiel #21
0
    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)
Beispiel #22
0
    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)
Beispiel #23
0
    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/')
Beispiel #24
0
    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/'))
Beispiel #25
0
 def test_nonexistent_root_page(self):
     with self.assertNumQueries(1):
         with self.assertRaises(Page.DoesNotExist):
             get_page_from_path('/hello/')
Beispiel #26
0
    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/')
Beispiel #27
0
    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/'))
Beispiel #28
0
 def test_nonexistent_root_page(self):
     with self.assertNumQueries(1):
         with self.assertRaises(Page.DoesNotExist):
             get_page_from_path('/hello/')