コード例 #1
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
コード例 #2
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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)
コード例 #3
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
    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)
コード例 #4
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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')
コード例 #7
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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])
コード例 #8
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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
コード例 #9
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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])
コード例 #10
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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)
コード例 #11
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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
コード例 #12
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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]
コード例 #14
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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]
コード例 #15
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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')
コード例 #16
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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)
コード例 #17
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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"
コード例 #18
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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
コード例 #19
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
    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')
コード例 #20
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
    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")
コード例 #21
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
    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)
コード例 #22
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
    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)
コード例 #23
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
    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"]
コード例 #24
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']
コード例 #25
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()
コード例 #26
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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")
コード例 #27
0
ファイル: test_hierarchy.py プロジェクト: mozilla/bedrock
 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
コード例 #28
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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)
コード例 #29
0
ファイル: test_hierarchy.py プロジェクト: zulqarnain4/bedrock
 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')