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