예제 #1
0
    def test_as_urlpatterns(self, page, patterns):
        """
        as_urlpatterns should return a urlconf with the pages for all the nodes
        included in the tree.
        """
        child1 = PageNode('child1', path='asdf/qwer', template='fake.html')
        child2 = PageNode('child2', path='bb/qr', template='fake2.html')
        parent = PageNode('parent', children=[child1, child2])
        root = PageRoot('root',
                        path='badsbi',
                        template='fake3.html',
                        children=[parent])

        patterns.return_value = 'asdf'
        # Mocking properties
        page.__get__ = lambda mock, self, cls: self.display_name

        eq_(root.as_urlpatterns(), 'asdf')

        args = patterns.call_args[0]
        eq_(args[0], '')
        ok_('child1' in args)
        ok_('child2' in args)
        ok_('root' in args)
        ok_('parent' not in args)
예제 #2
0
 def test_previous_cross(self):
     """
     If a node has no siblings, attempt to cross over to the children of the
     parent's sibling.
     """
     # Diagram of the final tree:
     #      root
     #      /  \
     #     O    O--
     #    /    /   \
     #   O    O     O
     #  /    / \   / \
     # c1   c2 c3 c4  O
     child1 = PageNode('', template='test1.html')
     child2 = PageNode('', template='test2.html')
     child3 = PageNode('', template='test3.html')
     child4 = PageNode('', template='test4.html')
     root = PageRoot(
         '',
         template='root.html',
         children=[
             PageNode('', children=[PageNode('', children=[child1])]),
             PageNode('',
                      children=[
                          PageNode('', children=[child2, child3]),
                          PageNode('', children=[child4,
                                                 PageNode('')])
                      ])
         ])
     assert root.previous is None
     assert child1.previous == root
     assert child2.previous == child1
     assert child3.previous == child2
     assert child4.previous == child3
예제 #3
0
 def test_next_cross(self):
     """
     If a node has no siblings, attempt to cross over to the children of the
     parent's sibling.
     """
     # Diagram of the final tree:
     #      root
     #      /  \
     #     O    O--
     #    /    /   \
     #   O    O     O
     #  /    / \   / \
     # c1   c2 c3 c4  O
     child1 = PageNode('', template='test1.html')
     child2 = PageNode('', template='test2.html')
     child3 = PageNode('', template='test3.html')
     child4 = PageNode('', template='test4.html')
     root = PageRoot(
         '',
         template='root.html',
         children=[
             PageNode('', children=[PageNode('', children=[child1])]),
             PageNode('',
                      children=[
                          PageNode('', children=[child2, child3]),
                          PageNode('', children=[child4,
                                                 PageNode('')])
                      ])
         ])
     eq_(root.next, child1)
     eq_(child1.next, child2)
     eq_(child2.next, child3)
     eq_(child3.next, child4)
     eq_(child4.next, None)
예제 #4
0
 def test_next_cross(self):
     """
     If a node has no siblings, attempt to cross over to the children of the
     parent's sibling.
     """
     # Diagram of the final tree:
     #      root
     #      /  \
     #     O    O--
     #    /    /   \
     #   O    O     O
     #  /    / \   / \
     # c1   c2 c3 c4  O
     child1 = PageNode("", template="test1.html")
     child2 = PageNode("", template="test2.html")
     child3 = PageNode("", template="test3.html")
     child4 = PageNode("", template="test4.html")
     root = PageRoot(
         "",
         template="root.html",
         children=[
             PageNode("", children=[PageNode("", children=[child1])]),
             PageNode("",
                      children=[
                          PageNode("", children=[child2, child3]),
                          PageNode("", children=[child4,
                                                 PageNode("")])
                      ]),
         ],
     )
     assert root.next == child1
     assert child1.next == child2
     assert child2.next == child3
     assert child3.next == child4
     assert child4.next is None
예제 #5
0
 def test_full_path_empty(self):
     """
     If one of a node's parents have an empty path, they should not be
     included in the full path.
     """
     child = PageNode("test", path="asdf")
     PageRoot("", path="blah", children=[PageNode("", children=[child])])
     assert child.full_path == "blah/asdf"
예제 #6
0
    def test_as_urlpatterns(self, page):
        """
        as_urlpatterns should return a urlconf with the pages for all the nodes
        included in the tree.
        """
        child1 = PageNode("child1", path="asdf/qwer", template="fake.html")
        child2 = PageNode("child2", path="bb/qr", template="fake2.html")
        parent = PageNode("parent", children=[child1, child2])
        root = PageRoot("root",
                        path="badsbi",
                        template="fake3.html",
                        children=[parent])

        # Mocking properties
        page.__get__ = lambda mock, self, cls: self.display_name

        assert root.as_urlpatterns() == ["root", "child1", "child2"]
예제 #7
0
 def test_full_path_empty(self):
     """
     If one of a node's parents have an empty path, they should not be
     included in the full path.
     """
     child = PageNode('test', path='asdf')
     PageRoot('', path='blah', children=[PageNode('', children=[child])])
     eq_(child.full_path, 'blah/asdf')
예제 #8
0
    def test_as_urlpatterns(self, page):
        """
        as_urlpatterns should return a urlconf with the pages for all the nodes
        included in the tree.
        """
        child1 = PageNode('child1', path='asdf/qwer', template='fake.html')
        child2 = PageNode('child2', path='bb/qr', template='fake2.html')
        parent = PageNode('parent', children=[child1, child2])
        root = PageRoot('root',
                        path='badsbi',
                        template='fake3.html',
                        children=[parent])

        # Mocking properties
        page.__get__ = lambda mock, self, cls: self.display_name

        assert root.as_urlpatterns() == ['root', 'child1', 'child2']
예제 #9
0
 def test_path_to_root(self):
     """
     path_to_root should return an iterable of nodes following the route from
     the child node to the root of the tree.
     """
     child1 = PageNode("test")
     child2 = PageNode("test", children=[child1])
     root = PageRoot("test", children=[child2, PageNode("test")])
     assert list(child1.path_to_root) == [child1, child2, root]
예제 #10
0
 def test_breadcrumbs(self):
     """
     breadcrumbs should return a list of nodes following the path from the
     root to the child node.
     """
     child1 = PageNode("test")
     child2 = PageNode("test", children=[child1])
     root = PageRoot("test", children=[child2, PageNode("test")])
     assert list(child1.breadcrumbs) == [root, child2, child1]
예제 #11
0
 def test_children_parents(self):
     """
     If a node is given children in the constructor, the children must mark
     the node as their parent.
     """
     children = [PageNode("test"), PageNode("test2")]
     parent = PageRoot("parent", children=children)
     for child in children:
         assert child.parent == parent
예제 #12
0
 def test_children_parents(self):
     """
     If a node is given children in the constructor, the children must mark
     the node as their parent.
     """
     children = [PageNode('test'), PageNode('test2')]
     parent = PageRoot('parent', children=children)
     for child in children:
         eq_(child.parent, parent)
예제 #13
0
 def test_path_to_root(self):
     """
     path_to_root should return an iterable of nodes following the route from
     the child node to the root of the tree.
     """
     child1 = PageNode('test')
     child2 = PageNode('test', children=[child1])
     root = PageRoot('test', children=[child2, PageNode('test')])
     eq_(list(child1.path_to_root), [child1, child2, root])
예제 #14
0
 def test_next(self):
     """
     Next should return the next sibling node, or None if one doesn't exist.
     """
     child1 = PageNode('', template='test1.html')
     child2 = PageNode('', template='test1.html')
     PageRoot('', children=[child1, child2])
     eq_(child1.next, child2)
     eq_(child2.next, None)
예제 #15
0
 def test_next(self):
     """
     Next should return the next sibling node, or None if one doesn't exist.
     """
     child1 = PageNode("", template="test1.html")
     child2 = PageNode("", template="test1.html")
     PageRoot("", children=[child1, child2])
     assert child1.next == child2
     assert child2.next is None
예제 #16
0
 def test_breadcrumbs(self):
     """
     breadcrumbs should return a list of nodes following the path from the
     root to the child node.
     """
     child1 = PageNode('test')
     child2 = PageNode('test', children=[child1])
     root = PageRoot('test', children=[child2, PageNode('test')])
     eq_(list(child1.breadcrumbs), [root, child2, child1])
예제 #17
0
 def test_full_path(self):
     """
     full_path should return the path of this node and all of its parents
     joined by slashes.
     """
     child = PageNode('test', path='asdf')
     PageRoot('test',
              path='blah',
              children=[PageNode('test', path='whoo', children=[child])])
     eq_(child.full_path, 'blah/whoo/asdf')
예제 #18
0
 def test_full_path(self):
     """
     full_path should return the path of this node and all of its parents
     joined by slashes.
     """
     child = PageNode("test", path="asdf")
     PageRoot("test",
              path="blah",
              children=[PageNode("test", path="whoo", children=[child])])
     assert child.full_path == "blah/whoo/asdf"
예제 #19
0
 def test_previous(self):
     """
     Previous should return the previous sibling node, or None if one doesn't
     exist.
     """
     child1 = PageNode("", template="test1.html")
     child2 = PageNode("", template="test2.html")
     PageRoot("", children=[child1, child2])
     assert child2.previous == child1
     assert child1.previous is None
예제 #20
0
 def test_previous(self):
     """
     Previous should return the previous sibling node, or None if one doesn't
     exist.
     """
     child1 = PageNode('', template='test1.html')
     child2 = PageNode('', template='test2.html')
     PageRoot('', children=[child1, child2])
     eq_(child2.previous, child1)
     eq_(child1.previous, None)
예제 #21
0
    def test_as_urlpatterns(self, page):
        """
        as_urlpatterns should return a urlconf with the pages for all the nodes
        included in the tree.
        """
        child1 = PageNode('child1', path='asdf/qwer', template='fake.html')
        child2 = PageNode('child2', path='bb/qr', template='fake2.html')
        parent = PageNode('parent', children=[child1, child2])
        root = PageRoot('root', path='badsbi', template='fake3.html',
                        children=[parent])

        # Mocking properties
        page.__get__ = lambda mock, self, cls: self.display_name

        args = root.as_urlpatterns()

        assert 'child1' in args
        assert 'child2' in args
        assert 'root' in args
        assert 'parent' not in args
예제 #22
0
    def test_url_child(self, reverse):
        """
        If a node doesn't have a page, but has children, it should return the
        url of its first child.
        """
        child1 = PageNode('test', path='asdf/qwer', template='fake.html')
        child2 = PageNode('test', path='bb/qr', template='fake2.html')
        parent = PageRoot('', children=[child1, child2])

        reverse.return_value = 'asdf'
        eq_(parent.url, 'asdf')
        reverse.assert_called_with('fake')
예제 #23
0
    def test_url_child(self, reverse):
        """
        If a node doesn't have a page, but has children, it should return the
        url of its first child.
        """
        child1 = PageNode("test", path="asdf/qwer", template="fake.html")
        child2 = PageNode("test", path="bb/qr", template="fake2.html")
        parent = PageRoot("", children=[child1, child2])

        reverse.return_value = "asdf"
        assert parent.url == "asdf"
        reverse.assert_called_with("fake")
예제 #24
0
    def test_as_urlpatterns(self, page, patterns):
        """
        as_urlpatterns should return a urlconf with the pages for all the nodes
        included in the tree.
        """
        child1 = PageNode('child1', path='asdf/qwer', template='fake.html')
        child2 = PageNode('child2', path='bb/qr', template='fake2.html')
        parent = PageNode('parent', children=[child1, child2])
        root = PageRoot('root', path='badsbi', template='fake3.html',
                        children=[parent])

        patterns.return_value = 'asdf'
        # Mocking properties
        page.__get__ = lambda mock, self, cls: self.display_name

        eq_(root.as_urlpatterns(), 'asdf')

        args = patterns.call_args[0]
        eq_(args[0], '')
        ok_('child1' in args)
        ok_('child2' in args)
        ok_('root' in args)
        ok_('parent' not in args)
예제 #25
0
    def test_page(self, page):
        """
        If a pagenode is given a template, it should provide a page for
        inclusion in a urlconf.
        """
        page.return_value = "testreturn"
        assert PageNode("test").page is None

        node = PageNode("test", path="blah", template="test.html")
        parent = PageRoot("testparent", path="yo", children=[node])
        assert node.page == "testreturn"
        page.assert_called_with("yo/blah",
                                "test.html",
                                node_root=parent,
                                node=node)
예제 #26
0
    def test_page(self, page):
        """
        If a pagenode is given a template, it should provide a page for
        inclusion in a urlconf.
        """
        page.return_value = 'testreturn'
        eq_(PageNode('test').page, None)

        node = PageNode('test', path='blah', template='test.html')
        parent = PageRoot('testparent', path='yo', children=[node])
        eq_(node.page, 'testreturn')
        page.assert_called_with('yo/blah',
                                'test.html',
                                node_root=parent,
                                node=node)
예제 #27
0
 def test_root(self):
     """root should return the root of the page tree."""
     child1 = PageNode('test')
     child2 = PageNode('test', children=[child1])
     root = PageRoot('test', children=[child2, PageNode('test')])
     eq_(child1.root, root)
예제 #28
0
 def test_url(self, reverse):
     """If a node has a page, url should return the url for that page."""
     node = PageRoot('test', path='asdf/qwer', template='fake.html')
     reverse.return_value = 'asdf'
     eq_(node.url, 'asdf')
     reverse.assert_called_with('fake')
예제 #29
0
 def test_url(self, reverse):
     """If a node has a page, url should return the url for that page."""
     node = PageRoot("test", path="asdf/qwer", template="fake.html")
     reverse.return_value = "asdf"
     assert node.url == "asdf"
     reverse.assert_called_with("fake")
예제 #30
0
파일: urls.py 프로젝트: quakpac/bedrock
                    'Switches',
                    path='switches',
                    template='styleguide/products/firefox-os/switches.html'),
                PageNode(
                    'Action Icons',
                    path='actionicons',
                    template='styleguide/products/firefox-os/action-icons.html'
                ),
                PageNode('App Icons',
                         path='icons',
                         template='styleguide/products/firefox-os/icons.html'),
            )), )),
]

if settings.DEV:
    all_children.extend((
        PageNode(
            'All Buttons',
            path='all-download-buttons',
            template='styleguide/websites/sandstone-all-download-buttons.html'
        ),
        PageNode('Docs',
                 path='docs',
                 children=(PageNode(
                     'Mozilla Pager JS',
                     path='mozilla-pager',
                     template='styleguide/docs/mozilla-pager.html'), )),
    ))

urlpatterns = PageRoot('Home', children=tuple(all_children)).as_urlpatterns()
예제 #31
0
 def test_root(self):
     """root should return the root of the page tree."""
     child1 = PageNode("test")
     child2 = PageNode("test", children=[child1])
     root = PageRoot("test", children=[child2, PageNode("test")])
     assert child1.root == root