Ejemplo n.º 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')
Ejemplo n.º 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/')
Ejemplo n.º 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/')
Ejemplo n.º 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/')
Ejemplo n.º 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')
Ejemplo n.º 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('/')
Ejemplo n.º 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/')
Ejemplo n.º 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('/')
Ejemplo n.º 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/')
Ejemplo n.º 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/')
Ejemplo n.º 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/')
Ejemplo n.º 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/')
Ejemplo n.º 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/')
Ejemplo n.º 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/')
Ejemplo n.º 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/')
Ejemplo n.º 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/')
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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/')
Ejemplo n.º 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/'))
Ejemplo n.º 25
0
 def test_nonexistent_root_page(self):
     with self.assertNumQueries(1):
         with self.assertRaises(Page.DoesNotExist):
             get_page_from_path('/hello/')
Ejemplo n.º 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/')
Ejemplo n.º 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/'))
Ejemplo n.º 28
0
 def test_nonexistent_root_page(self):
     with self.assertNumQueries(1):
         with self.assertRaises(Page.DoesNotExist):
             get_page_from_path('/hello/')