Exemplo n.º 1
0
    def build(tree_dict, items):
        def attach_items(tree, items, parent=None):
            for item_dict in items:
                children = item_dict.pop('children', [])

                access_permissions = item_dict.pop('access_permissions', [])

                item = TreeItem(**item_dict)
                item.tree = tree
                item.parent = parent
                item.save()

                for permission in access_permissions:
                    item.access_permissions.add(
                        Permission.objects.get(codename=permission))

                items_map['%s' % item.url] = item

                children and attach_items(tree, children, parent=item)

        items_map = {}

        tree = Tree(**tree_dict)
        tree.save()
        attach_items(tree, items)

        return items_map
Exemplo n.º 2
0
def test_model_tree_item():
    from sitetree.models import Tree, TreeItem

    tree1 = Tree(alias='test')
    tree1.save()

    item1 = TreeItem(tree=tree1, alias='only', title='only title')
    item1.save()

    assert str(item1) == item1.title

    item2 = TreeItem(tree=tree1, alias='other', parent=item1)
    item2.save()

    item3 = TreeItem(tree=tree1, parent=item1)
    item3.save()

    item3.sort_order = 100
    item3.parent = item3
    item3.save()

    assert item3.parent is None  # Can't be itself
    assert item3.sort_order == 100

    item3.sort_order = 0
    item3.save()

    assert item3.sort_order == item3.id  # Automatic ordering

    with pytest.raises(Exception):
        TreeItem(tree=tree1, alias='only').save()  # Unique alias within tree
Exemplo n.º 3
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        tree_ttags = Tree(alias='ttags')
        tree_ttags.save()
        cls.tree_ttags = tree_ttags

        tree_ttags_root = TreeItem(title='root',
                                   tree=tree_ttags,
                                   url='/',
                                   insitetree=True,
                                   inbreadcrumbs=True,
                                   inmenu=True)
        tree_ttags_root.save()
        cls.tree_ttags_root = tree_ttags_root

        tree_ttags_root_child1 = TreeItem(title='sometitle',
                                          tree=tree_ttags,
                                          parent=tree_ttags_root,
                                          url='/child1',
                                          insitetree=True,
                                          inbreadcrumbs=True,
                                          inmenu=True,
                                          hint='somehint',
                                          description='somedescr')
        tree_ttags_root_child1.save()
        cls.tree_ttags_root_child1 = tree_ttags_root_child1
Exemplo n.º 4
0
def test_admin_tree_item_move(common_tree):
    from sitetree.models import TreeItem, Tree

    main_tree = Tree(alias='main')
    main_tree.save()

    new_item_1 = TreeItem(title='title_1', sort_order=1, tree_id=main_tree.pk)
    new_item_1.save()

    new_item_2 = TreeItem(title='title_2', sort_order=2, tree_id=main_tree.pk)
    new_item_2.save()

    new_item_3 = TreeItem(title='title_3', sort_order=3, tree_id=main_tree.pk)
    new_item_3.save()

    admin = get_item_admin()

    admin.item_move(None, None, new_item_2.id, 'up')

    assert TreeItem.objects.get(pk=new_item_1.id).sort_order == 2
    assert TreeItem.objects.get(pk=new_item_2.id).sort_order == 1
    assert TreeItem.objects.get(pk=new_item_3.id).sort_order == 3

    admin.item_move(None, None, new_item_1.id, 'down')

    assert TreeItem.objects.get(pk=new_item_1.id).sort_order == 3
    assert TreeItem.objects.get(pk=new_item_2.id).sort_order == 1
    assert TreeItem.objects.get(pk=new_item_3.id).sort_order == 2
Exemplo n.º 5
0
    def build(tree_dict, items):

        def attach_items(tree, items, parent=None):
            for item_dict in items:
                children = item_dict.pop('children', [])

                access_permissions = item_dict.pop('access_permissions', [])

                item = TreeItem(**item_dict)
                item.tree = tree
                item.parent = parent
                item.save()

                for permission in access_permissions:
                    item.access_permissions.add(Permission.objects.get(codename=permission))

                items_map['%s' % item.url] = item

                children and attach_items(tree, children, parent=item)

        items_map = {}

        tree = Tree(**tree_dict)
        tree.save()
        attach_items(tree, items)

        return items_map
Exemplo n.º 6
0
def test_admin_tree_item_move(mock_request, common_tree):
    from sitetree.models import TreeItem, Tree

    main_tree = Tree(alias='main')
    main_tree.save()

    new_item_1 = TreeItem(title='title_1', sort_order=1, tree_id=main_tree.pk)
    new_item_1.save()

    new_item_2 = TreeItem(title='title_2', sort_order=2, tree_id=main_tree.pk)
    new_item_2.save()

    new_item_3 = TreeItem(title='title_3', sort_order=3, tree_id=main_tree.pk)
    new_item_3.save()

    admin = get_item_admin()

    admin.item_move(None, None, new_item_2.id, 'up')

    assert TreeItem.objects.get(pk=new_item_1.id).sort_order == 2
    assert TreeItem.objects.get(pk=new_item_2.id).sort_order == 1
    assert TreeItem.objects.get(pk=new_item_3.id).sort_order == 3

    admin.item_move(None, None, new_item_1.id, 'down')

    assert TreeItem.objects.get(pk=new_item_1.id).sort_order == 3
    assert TreeItem.objects.get(pk=new_item_2.id).sort_order == 1
    assert TreeItem.objects.get(pk=new_item_3.id).sort_order == 2
Exemplo n.º 7
0
 def test_create_rename_delete(self):
     tree = Tree(alias='mytree')
     tree.save(force_insert=True)
     self.assertIsNotNone(tree.id)
     self.assertEqual(tree.alias, 'mytree')
     tree.alias = 'not_mytree'
     tree.save(force_update=True)
     self.assertEqual(tree.alias, 'not_mytree')
     tree.delete()
     self.assertIsNone(tree.id)
Exemplo n.º 8
0
 def test_create_rename_delete(self):
     tree = Tree(alias='mytree')
     tree.save(force_insert=True)
     self.assertIsNotNone(tree.id)
     self.assertEqual(tree.alias, 'mytree')
     tree.alias = 'not_mytree'
     tree.save(force_update=True)
     self.assertEqual(tree.alias, 'not_mytree')
     tree.delete()
     self.assertIsNone(tree.id)
Exemplo n.º 9
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias='main')
        t1.save(force_insert=True)

        t1_root = TreeItem(title='root', tree=t1, url='/', alias='for_dynamic')
        t1_root.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
Exemplo n.º 10
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias="main")
        t1.save(force_insert=True)

        t1_root = TreeItem(title="root", tree=t1, url="/", alias="for_dynamic")
        t1_root.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
Exemplo n.º 11
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias='main')
        t1.save(force_insert=True)

        t1_root = TreeItem(title='root', tree=t1, url='/', alias='for_dynamic')
        t1_root.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
 def create_menu(self, alias, title):
     sitetree = Tree.objects.filter(alias=alias)
     if sitetree:
         logger.info('Main navigation already present, nothing to do')
     else:
         Tree(title=title, alias=alias).save()
         logger.info('Successfully created main navigation tree')
Exemplo n.º 13
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        tree_ttags = Tree(alias='ttags')
        tree_ttags.save()
        cls.tree_ttags = tree_ttags

        tree_ttags_root = TreeItem(
            title='root', tree=tree_ttags, url='/',
            insitetree=True, inbreadcrumbs=True, inmenu=True
        )
        tree_ttags_root.save()
        cls.tree_ttags_root = tree_ttags_root

        tree_ttags_root_child1 = TreeItem(
            title='sometitle', tree=tree_ttags, parent=tree_ttags_root, url='/child1',
            insitetree=True, inbreadcrumbs=True, inmenu=True,
            hint='somehint', description='somedescr'
        )
        tree_ttags_root_child1.save()
        cls.tree_ttags_root_child1 = tree_ttags_root_child1
Exemplo n.º 14
0
    def test_no_recursive_parents(self):
        """Verify that treeitems cannot be their own parent."""
        tree = Tree(alias="mytree")
        tree.save()
        tree_item = TreeItem(title="i'm my own grandpa", tree=tree)
        # This item needs to be saved, otherwise it cannot be set
        # as a parent.
        tree_item.save()

        tree_item.parent = tree_item
        tree_item.save()
        self.assertNotEqual(tree_item, tree_item.parent)
Exemplo n.º 15
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias='tree1')
        t1.save(force_insert=True)

        t1_root = TreeItem(title='root', tree=t1, url='/')
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title='child1', tree=t1, parent=t1_root, url='/about/')
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title='child2', tree=t1, parent=t1_root, url='articles_list', urlaspattern=True)
        t1_root_child2.save(force_insert=True)

        t1_root_child2_sub1 = TreeItem(title='subchild1', tree=t1, parent=t1_root_child2,
            url='articles_detailed art_id', urlaspattern=True)
        t1_root_child2_sub1.save(force_insert=True)

        t1_root_child2_sub2 = TreeItem(title='subchild2', tree=t1, parent=t1_root_child2, url='/not_articles/10/')
        t1_root_child2_sub2.save(force_insert=True)

        t2 = Tree(alias='tree2')
        t2.save(force_insert=True)

        t2_root1 = TreeItem(title='{{ t2_root1_title }}', tree=t2, url='/')
        t2_root1.save(force_insert=True)

        t2_root2 = TreeItem(title='put {{ t2_root2_title }} inside', tree=t2, url='/sub/')
        t2_root2.save(force_insert=True)

        t2_root3 = TreeItem(title='for logged in only', tree=t2, url='/some/', access_loggedin=True)
        t2_root3.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child2_sub1 = t1_root_child2_sub1
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        cls.t2 = t2
        cls.t2_root1 = t2_root1

        cls.t2_root2 = t2_root2
        cls.t2_root3 = t2_root3

        # set urlconf to test's one
        cls.old_urlconf = urlresolvers.get_urlconf()
        urlresolvers.set_urlconf('sitetree.tests')
Exemplo n.º 16
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias='tree1')
        t1.save(force_insert=True)

        t1_root = TreeItem(title='root', tree=t1, url='/')
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title='child1', tree=t1, parent=t1_root, url='/about/')
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title='child2', tree=t1, parent=t1_root, url='articles_list', urlaspattern=True)
        t1_root_child2.save(force_insert=True)

        t1_root_child2_sub1 = TreeItem(title='subchild1', tree=t1, parent=t1_root_child2,
            url='articles_detailed art_id', urlaspattern=True)
        t1_root_child2_sub1.save(force_insert=True)

        t1_root_child2_sub2 = TreeItem(title='subchild2', tree=t1, parent=t1_root_child2, url='/not_articles/10/')
        t1_root_child2_sub2.save(force_insert=True)

        t1_root_child3 = TreeItem(title='child_with_var_str', tree=t1, parent=t1_root, url='somevar_str', urlaspattern=True)
        t1_root_child3.save(force_insert=True)

        t1_root_child4 = TreeItem(title='child_with_var_list', tree=t1, parent=t1_root, url='somevar_list', urlaspattern=True)
        t1_root_child4.save(force_insert=True)

        t2 = Tree(alias='tree2')
        t2.save(force_insert=True)

        t2_root1 = TreeItem(title='{{ t2_root1_title }}', tree=t2, url='/')
        t2_root1.save(force_insert=True)

        t2_root2 = TreeItem(title='put {{ t2_root2_title }} inside', tree=t2, url='/sub/')
        t2_root2.save(force_insert=True)

        t2_root3 = TreeItem(title='for logged in only', tree=t2, url='/some/', access_loggedin=True)
        t2_root3.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child3 = t1_root_child3
        cls.t1_root_child2_sub1 = t1_root_child2_sub1
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        cls.t2 = t2
        cls.t2_root1 = t2_root1

        cls.t2_root2 = t2_root2
        cls.t2_root3 = t2_root3

        # set urlconf to test's one
        cls.old_urlconf = urlresolvers.get_urlconf()
        urlresolvers.set_urlconf('sitetree.tests')
Exemplo n.º 17
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias='tree3')
        t1.save(force_insert=True)

        t1_root = TreeItem(title='root', tree=t1, url='/', hidden=True)
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title='child1', tree=t1, parent=t1_root, url='/0/', access_loggedin=True)
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title='child2', tree=t1, parent=t1_root, url='/1/', inmenu=True, hidden=True)
        t1_root_child2.save(force_insert=True)

        t1_root_child3 = TreeItem(title='child3', tree=t1, parent=t1_root, url='/2/', inmenu=False)
        t1_root_child3.save(force_insert=True)

        t1_root_child4 = TreeItem(title='child4', tree=t1, parent=t1_root, url='/3/', hidden=True)
        t1_root_child4.save(force_insert=True)

        t1_root_child5 = TreeItem(title='child5', tree=t1, parent=t1_root, url='/4/', inmenu=True, hidden=True)
        t1_root_child5.save(force_insert=True)

        t2 = Tree(alias='tree3_en')
        t2.save(force_insert=True)

        t2_root = TreeItem(title='root_en', tree=t2, url='/')
        t2_root.save(force_insert=True)

        t2_root_child1 = TreeItem(title='child1_en', tree=t2, parent=t2_root, url='/0_en/')
        t2_root_child1.save(force_insert=True)

        t2_root_child2 = TreeItem(title='child2_en', tree=t2, parent=t2_root, url='/1_en/')
        t2_root_child2.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child2 = t1_root_child3
        cls.t1_root_child2 = t1_root_child4
        cls.t1_root_child2 = t1_root_child5

        cls.t2_root = t2_root
Exemplo n.º 18
0
def test_model_tree():
    from sitetree.models import Tree

    tree = Tree(alias='test')
    tree.save()

    assert str(tree) == tree.alias
    assert tree.get_title() == tree.alias

    with pytest.raises(Exception):
        Tree(alias='test').save()  # Unique alias
Exemplo n.º 19
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias='tree3')
        t1.save(force_insert=True)

        t1_root = TreeItem(title='root', tree=t1, url='/', hidden=True)
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title='child1', tree=t1, parent=t1_root, url='/0/', access_loggedin=True)
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title='child2', tree=t1, parent=t1_root, url='/1/', inmenu=True, hidden=True)
        t1_root_child2.save(force_insert=True)

        t1_root_child3 = TreeItem(title='child3', tree=t1, parent=t1_root, url='/the_same_url/', inmenu=False)
        t1_root_child3.save(force_insert=True)

        t1_root_child4 = TreeItem(title='child4', tree=t1, parent=t1_root, url='/3/', hidden=True)
        t1_root_child4.save(force_insert=True)

        t1_root_child5 = TreeItem(title='child5', tree=t1, parent=t1_root, url='/4/', inmenu=True, hidden=True)
        t1_root_child5.save(force_insert=True)

        t2 = Tree(alias='tree3_en', title='tree3en_title')
        t2.save(force_insert=True)

        t2_root = TreeItem(title='root_en', tree=t2, url='/')
        t2_root.save(force_insert=True)

        t2_root_child1 = TreeItem(title='child1_en', tree=t2, parent=t2_root, url='/0_en/')
        t2_root_child1.save(force_insert=True)

        t2_root_child2 = TreeItem(title='child2_en', tree=t2, parent=t2_root, url='/the_same_url/')
        t2_root_child2.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child2 = t1_root_child3
        cls.t1_root_child2 = t1_root_child4
        cls.t1_root_child2 = t1_root_child5

        cls.t2 = t2
        cls.t2_root = t2_root
Exemplo n.º 20
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias="tree3")
        t1.save(force_insert=True)

        t1_root = TreeItem(title="root", tree=t1, url="/", hidden=True)
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title="child1", tree=t1, parent=t1_root, url="/0/", access_loggedin=True)
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title="child2", tree=t1, parent=t1_root, url="/1/", inmenu=True, hidden=True)
        t1_root_child2.save(force_insert=True)

        t1_root_child3 = TreeItem(title="child3", tree=t1, parent=t1_root, url="/the_same_url/", inmenu=False)
        t1_root_child3.save(force_insert=True)

        t1_root_child4 = TreeItem(title="child4", tree=t1, parent=t1_root, url="/3/", hidden=True)
        t1_root_child4.save(force_insert=True)

        t1_root_child5 = TreeItem(title="child5", tree=t1, parent=t1_root, url="/4/", inmenu=True, hidden=True)
        t1_root_child5.save(force_insert=True)

        t2 = Tree(alias="tree3_en")
        t2.save(force_insert=True)

        t2_root = TreeItem(title="root_en", tree=t2, url="/")
        t2_root.save(force_insert=True)

        t2_root_child1 = TreeItem(title="child1_en", tree=t2, parent=t2_root, url="/0_en/")
        t2_root_child1.save(force_insert=True)

        t2_root_child2 = TreeItem(title="child2_en", tree=t2, parent=t2_root, url="/the_same_url/")
        t2_root_child2.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child2 = t1_root_child3
        cls.t1_root_child2 = t1_root_child4
        cls.t1_root_child2 = t1_root_child5

        cls.t2_root = t2_root
Exemplo n.º 21
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias='tree1')
        t1.save(force_insert=True)

        t1_root = TreeItem(title='root', tree=t1, url='/')
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title='child1', tree=t1, parent=t1_root, url='/about/')
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title='child2', tree=t1, parent=t1_root, url='articles_list', urlaspattern=True, description='items_descr')
        t1_root_child2.save(force_insert=True)

        t1_root_child2_sub1 = TreeItem(title='subchild1', tree=t1, parent=t1_root_child2,
            url='articles_detailed art_id', urlaspattern=True)
        t1_root_child2_sub1.save(force_insert=True)

        t1_root_child2_sub2 = TreeItem(title='subchild2', tree=t1, parent=t1_root_child2, url='/not_articles/10/')
        t1_root_child2_sub2.save(force_insert=True)

        t1_root_child3 = TreeItem(title='child_with_var_str', tree=t1, parent=t1_root, url='somevar_str', urlaspattern=True)
        t1_root_child3.save(force_insert=True)

        t1_root_child4 = TreeItem(title='child_with_var_list', tree=t1, parent=t1_root, url='somevar_list', urlaspattern=True)
        t1_root_child4.save(force_insert=True)

        t2 = Tree(alias='tree2')
        t2.save(force_insert=True)

        t2_root1 = TreeItem(title='{{ t2_root1_title }}', tree=t2, url='/')
        t2_root1.save(force_insert=True)

        t2_root2 = TreeItem(title='put {{ t2_root2_title }} inside', tree=t2, url='/sub/')
        t2_root2.save(force_insert=True)

        t2_root3 = TreeItem(title='for logged in only', tree=t2, url='/some/', access_loggedin=True)
        t2_root3.save(force_insert=True)

        t2_root4 = TreeItem(title='url quoting', tree=t2, url='url 2 put_var', urlaspattern=True)
        t2_root4.save(force_insert=True)

        t2_root5 = TreeItem(title='url quoting 1.5 style', tree=t2, url="'url' 2 put_var", urlaspattern=True)
        t2_root5.save(force_insert=True)

        t2_root6 = TreeItem(title='url quoting 1.5 style', tree=t2, url='"url" 2 put_var', urlaspattern=True)
        t2_root6.save(force_insert=True)

        t2_root7 = TreeItem(title='for guests only', tree=t2, url='/some_other/', access_guest=True)
        t2_root7.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child3 = t1_root_child3
        cls.t1_root_child2_sub1 = t1_root_child2_sub1
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        cls.t2 = t2
        cls.t2_root1 = t2_root1

        cls.t2_root2 = t2_root2
        cls.t2_root3 = t2_root3
        cls.t2_root4 = t2_root4
        cls.t2_root5 = t2_root5
        cls.t2_root6 = t2_root6
        cls.t2_root7 = t2_root7

        # set urlconf to test's one
        cls.old_urlconf = urlresolvers.get_urlconf()
        urlresolvers.set_urlconf('sitetree.tests')
Exemplo n.º 22
0
 def test_unique_aliases(self):
     tree1 = Tree(alias='mytree')
     tree1.save(force_insert=True)
     tree2 = Tree(alias='mytree')
     self.assertRaises(Exception, tree2.save)
Exemplo n.º 23
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias="tree1")
        t1.save(force_insert=True)

        t1_root = TreeItem(title="root", tree=t1, url="/")
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title="child1", tree=t1, parent=t1_root, url="/about/")
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title="child2", tree=t1, parent=t1_root, url="articles_list", urlaspattern=True)
        t1_root_child2.save(force_insert=True)

        t1_root_child2_sub1 = TreeItem(
            title="subchild1", tree=t1, parent=t1_root_child2, url="articles_detailed art_id", urlaspattern=True
        )
        t1_root_child2_sub1.save(force_insert=True)

        t1_root_child2_sub2 = TreeItem(title="subchild2", tree=t1, parent=t1_root_child2, url="/not_articles/10/")
        t1_root_child2_sub2.save(force_insert=True)

        t1_root_child3 = TreeItem(
            title="child_with_var_str", tree=t1, parent=t1_root, url="somevar_str", urlaspattern=True
        )
        t1_root_child3.save(force_insert=True)

        t1_root_child4 = TreeItem(
            title="child_with_var_list", tree=t1, parent=t1_root, url="somevar_list", urlaspattern=True
        )
        t1_root_child4.save(force_insert=True)

        t2 = Tree(alias="tree2")
        t2.save(force_insert=True)

        t2_root1 = TreeItem(title="{{ t2_root1_title }}", tree=t2, url="/")
        t2_root1.save(force_insert=True)

        t2_root2 = TreeItem(title="put {{ t2_root2_title }} inside", tree=t2, url="/sub/")
        t2_root2.save(force_insert=True)

        t2_root3 = TreeItem(title="for logged in only", tree=t2, url="/some/", access_loggedin=True)
        t2_root3.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child3 = t1_root_child3
        cls.t1_root_child2_sub1 = t1_root_child2_sub1
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        cls.t2 = t2
        cls.t2_root1 = t2_root1

        cls.t2_root2 = t2_root2
        cls.t2_root3 = t2_root3

        # set urlconf to test's one
        cls.old_urlconf = urlresolvers.get_urlconf()
        urlresolvers.set_urlconf("sitetree.tests")
Exemplo n.º 24
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias="tree1")
        t1.save(force_insert=True)

        t1_root = TreeItem(title="root", tree=t1, url="/")
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title="child1", tree=t1, parent=t1_root, url="/about/")
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(
            title="child2", tree=t1, parent=t1_root, url="articles_list", urlaspattern=True, description="items_descr"
        )
        t1_root_child2.save(force_insert=True)

        t1_root_child2_sub1 = TreeItem(
            title="subchild1", tree=t1, parent=t1_root_child2, url="articles_detailed art_id", urlaspattern=True
        )
        t1_root_child2_sub1.save(force_insert=True)

        t1_root_child2_sub2 = TreeItem(title="subchild2", tree=t1, parent=t1_root_child2, url="/not_articles/10/")
        t1_root_child2_sub2.save(force_insert=True)

        t1_root_child3 = TreeItem(
            title="child_with_var_str", tree=t1, parent=t1_root, url="somevar_str", urlaspattern=True
        )
        t1_root_child3.save(force_insert=True)

        t1_root_child4 = TreeItem(
            title="child_with_var_list", tree=t1, parent=t1_root, url="somevar_list", urlaspattern=True
        )
        t1_root_child4.save(force_insert=True)

        t2 = Tree(alias="tree2")
        t2.save(force_insert=True)

        t2_root1 = TreeItem(title="{{ t2_root1_title }}", tree=t2, url="/")
        t2_root1.save(force_insert=True)

        t2_root2 = TreeItem(title="put {{ t2_root2_title }} inside", tree=t2, url="/sub/")
        t2_root2.save(force_insert=True)

        t2_root3 = TreeItem(title="for logged in only", tree=t2, url="/some/", access_loggedin=True)
        t2_root3.save(force_insert=True)

        t2_root4 = TreeItem(title="url quoting", tree=t2, url="url 2 put_var", urlaspattern=True)
        t2_root4.save(force_insert=True)

        t2_root5 = TreeItem(title="url quoting 1.5 style", tree=t2, url="'url' 2 put_var", urlaspattern=True)
        t2_root5.save(force_insert=True)

        t2_root6 = TreeItem(title="url quoting 1.5 style", tree=t2, url='"url" 2 put_var', urlaspattern=True)
        t2_root6.save(force_insert=True)

        t2_root7 = TreeItem(title="for guests only", tree=t2, url="/some_other/", access_guest=True)
        t2_root7.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child3 = t1_root_child3
        cls.t1_root_child2_sub1 = t1_root_child2_sub1
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        cls.t2 = t2
        cls.t2_root1 = t2_root1

        cls.t2_root2 = t2_root2
        cls.t2_root3 = t2_root3
        cls.t2_root4 = t2_root4
        cls.t2_root5 = t2_root5
        cls.t2_root6 = t2_root6
        cls.t2_root7 = t2_root7

        # set urlconf to test's one
        cls.old_urlconf = urlresolvers.get_urlconf()
        urlresolvers.set_urlconf("sitetree.tests")
Exemplo n.º 25
0
    def init_trees(cls):
        cls.sitetree = SiteTree()

        ###########################################################

        t1 = Tree(alias='tree1')
        t1.save()
        cls.t1 = t1

        t1_root = TreeItem(title='root', tree=t1, url='/')
        t1_root.save()
        cls.tree_ttags_root = t1_root

        t1_root_child1 = TreeItem(title='child1',
                                  tree=t1,
                                  parent=t1_root,
                                  url='/about/')
        t1_root_child1.save()
        cls.tree_ttags_root_child1 = t1_root_child1

        t1_root_child2 = TreeItem(title='child2',
                                  tree=t1,
                                  parent=t1_root,
                                  url='articles_list',
                                  urlaspattern=True,
                                  description='items_descr')
        t1_root_child2.save()
        cls.t1_root_child2 = t1_root_child2

        t1_root_child2_sub1 = TreeItem(title='subchild1',
                                       tree=t1,
                                       parent=t1_root_child2,
                                       url='articles_detailed art_id',
                                       urlaspattern=True)
        t1_root_child2_sub1.save()
        cls.t1_root_child2_sub1 = t1_root_child2_sub1

        t1_root_child2_sub2 = TreeItem(title='subchild2',
                                       tree=t1,
                                       parent=t1_root_child2,
                                       url='/not_articles/10/')
        t1_root_child2_sub2.save()
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        t1_root_child3 = TreeItem(title='child_with_var_str',
                                  tree=t1,
                                  parent=t1_root,
                                  url='somevar_str',
                                  urlaspattern=True)
        t1_root_child3.save()
        cls.t1_root_child3 = t1_root_child3

        t1_root_child4 = TreeItem(title='child_with_var_list',
                                  tree=t1,
                                  parent=t1_root,
                                  url='somevar_list',
                                  urlaspattern=True)
        t1_root_child4.save()

        t2 = Tree(alias='tree2')
        t2.save()
        cls.t2 = t2

        t2_root1 = TreeItem(title='{{ t2_root1_title }}', tree=t2, url='/')
        t2_root1.save()
        cls.t2_root1 = t2_root1

        t2_root2 = TreeItem(title='put {{ t2_root2_title }} inside',
                            tree=t2,
                            url='/sub/')
        t2_root2.save()
        cls.t2_root2 = t2_root2

        t2_root3 = TreeItem(title='for logged in only',
                            tree=t2,
                            url='/some/',
                            access_loggedin=True)
        t2_root3.save()
        cls.t2_root3 = t2_root3

        t2_root4 = TreeItem(title='url quoting',
                            tree=t2,
                            url='url 2 put_var',
                            urlaspattern=True)
        t2_root4.save()
        cls.t2_root4 = t2_root4

        t2_root5 = TreeItem(title='url quoting 1.5 style',
                            tree=t2,
                            url="'url' 2 put_var",
                            urlaspattern=True)
        t2_root5.save()
        cls.t2_root5 = t2_root5

        t2_root6 = TreeItem(title='url quoting 1.5 style',
                            tree=t2,
                            url='"url" 2 put_var',
                            urlaspattern=True)
        t2_root6.save()
        cls.t2_root6 = t2_root6

        t2_root7 = TreeItem(title='for guests only',
                            tree=t2,
                            url='/some_other/',
                            access_guest=True)
        t2_root7.save()
        cls.t2_root7 = t2_root7

        ###########################################################

        t3 = Tree(alias='tree3')
        t3.save()
        cls.t3 = t3

        t3_en_root = TreeItem(title='root', tree=t3, url='/', hidden=True)
        t3_en_root.save()
        cls.t3_root = t3_en_root

        t3_root_child1 = TreeItem(title='child1',
                                  tree=t3,
                                  parent=t3_en_root,
                                  url='/0/',
                                  access_loggedin=True)
        t3_root_child1.save()
        cls.t3_root_child1 = t3_root_child1

        t3_root_child2 = TreeItem(title='child2',
                                  tree=t3,
                                  parent=t3_en_root,
                                  url='/1/',
                                  inmenu=True,
                                  hidden=True)
        t3_root_child2.save()
        cls.t3_root_child2 = t3_root_child2

        t3_root_child3 = TreeItem(title='child3',
                                  tree=t3,
                                  parent=t3_en_root,
                                  url='/the_same_url/',
                                  inmenu=False)
        t3_root_child3.save()
        cls.t3_root_child3 = t3_root_child3

        t3_root_child4 = TreeItem(title='child4',
                                  tree=t3,
                                  parent=t3_en_root,
                                  url='/3/',
                                  hidden=True)
        t3_root_child4.save()
        cls.t3_root_child4 = t3_root_child4

        t3_root_child5 = TreeItem(title='child5',
                                  tree=t3,
                                  parent=t3_en_root,
                                  url='/4/',
                                  inmenu=True,
                                  hidden=True)
        t3_root_child5.save()
        cls.t3_root_child5 = t3_root_child5

        t3_en = Tree(alias='tree3_en', title='tree3en_title')
        t3_en.save()
        cls.t3_en = t3_en

        t3_en_root = TreeItem(title='root_en', tree=t3_en, url='/')
        t3_en_root.save()
        cls.t3_en_root = t3_en_root

        t3_en_root_child1 = TreeItem(title='child1_en',
                                     tree=t3_en,
                                     parent=t3_en_root,
                                     url='/0_en/')
        t3_en_root_child1.save()

        t3_en_root_child2 = TreeItem(title='child2_en',
                                     tree=t3_en,
                                     parent=t3_en_root,
                                     url='/the_same_url/')
        t3_en_root_child2.save()

        ###########################################################

        tree_main = Tree(alias='main')
        tree_main.save()
        cls.tree_main = tree_main

        tree_main_root = TreeItem(title='root',
                                  tree=tree_main,
                                  url='/',
                                  alias='for_dynamic')
        tree_main_root.save()
        cls.tree_main_root = tree_main_root
Exemplo n.º 26
0
 def test_unique_aliases(self):
     tree1 = Tree(alias='mytree')
     tree1.save(force_insert=True)
     tree2 = Tree(alias='mytree')
     self.assertRaises(Exception, tree2.save)
Exemplo n.º 27
0
    def setUpClass(cls):
        cls.sitetree = SiteTree()

        t1 = Tree(alias='tree1')
        t1.save(force_insert=True)

        t1_root = TreeItem(title='root', tree=t1, url='/')
        t1_root.save(force_insert=True)

        t1_root_child1 = TreeItem(title='child1',
                                  tree=t1,
                                  parent=t1_root,
                                  url='/about/')
        t1_root_child1.save(force_insert=True)

        t1_root_child2 = TreeItem(title='child2',
                                  tree=t1,
                                  parent=t1_root,
                                  url='articles_list',
                                  urlaspattern=True,
                                  description='items_descr')
        t1_root_child2.save(force_insert=True)

        t1_root_child2_sub1 = TreeItem(title='subchild1',
                                       tree=t1,
                                       parent=t1_root_child2,
                                       url='articles_detailed art_id',
                                       urlaspattern=True)
        t1_root_child2_sub1.save(force_insert=True)

        t1_root_child2_sub2 = TreeItem(title='subchild2',
                                       tree=t1,
                                       parent=t1_root_child2,
                                       url='/not_articles/10/')
        t1_root_child2_sub2.save(force_insert=True)

        t1_root_child3 = TreeItem(title='child_with_var_str',
                                  tree=t1,
                                  parent=t1_root,
                                  url='somevar_str',
                                  urlaspattern=True)
        t1_root_child3.save(force_insert=True)

        t1_root_child4 = TreeItem(title='child_with_var_list',
                                  tree=t1,
                                  parent=t1_root,
                                  url='somevar_list',
                                  urlaspattern=True)
        t1_root_child4.save(force_insert=True)

        t2 = Tree(alias='tree2')
        t2.save(force_insert=True)

        t2_root1 = TreeItem(title='{{ t2_root1_title }}', tree=t2, url='/')
        t2_root1.save(force_insert=True)

        t2_root2 = TreeItem(title='put {{ t2_root2_title }} inside',
                            tree=t2,
                            url='/sub/')
        t2_root2.save(force_insert=True)

        t2_root3 = TreeItem(title='for logged in only',
                            tree=t2,
                            url='/some/',
                            access_loggedin=True)
        t2_root3.save(force_insert=True)

        t2_root4 = TreeItem(title='url quoting',
                            tree=t2,
                            url='url 2 put_var',
                            urlaspattern=True)
        t2_root4.save(force_insert=True)

        t2_root5 = TreeItem(title='url quoting 1.5 style',
                            tree=t2,
                            url="'url' 2 put_var",
                            urlaspattern=True)
        t2_root5.save(force_insert=True)

        t2_root6 = TreeItem(title='url quoting 1.5 style',
                            tree=t2,
                            url='"url" 2 put_var',
                            urlaspattern=True)
        t2_root6.save(force_insert=True)

        t2_root7 = TreeItem(title='for guests only',
                            tree=t2,
                            url='/some_other/',
                            access_guest=True)
        t2_root7.save(force_insert=True)

        cls.t1 = t1
        cls.t1_root = t1_root
        cls.t1_root_child1 = t1_root_child1
        cls.t1_root_child2 = t1_root_child2
        cls.t1_root_child3 = t1_root_child3
        cls.t1_root_child2_sub1 = t1_root_child2_sub1
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        cls.t2 = t2
        cls.t2_root1 = t2_root1

        cls.t2_root2 = t2_root2
        cls.t2_root3 = t2_root3
        cls.t2_root4 = t2_root4
        cls.t2_root5 = t2_root5
        cls.t2_root6 = t2_root6
        cls.t2_root7 = t2_root7
Exemplo n.º 28
0
    def init_trees(cls):
        cls.sitetree = SiteTree()

        ###########################################################

        t1 = Tree(alias='tree1')
        t1.save()
        cls.t1 = t1

        t1_root = TreeItem(title='root', tree=t1, url='/')
        t1_root.save()
        cls.tree_ttags_root = t1_root

        t1_root_child1 = TreeItem(title='child1', tree=t1, parent=t1_root, url='/about/')
        t1_root_child1.save()
        cls.tree_ttags_root_child1 = t1_root_child1

        t1_root_child2 = TreeItem(title='child2', tree=t1, parent=t1_root, url='articles_list', urlaspattern=True,
                                  description='items_descr')
        t1_root_child2.save()
        cls.t1_root_child2 = t1_root_child2

        t1_root_child2_sub1 = TreeItem(title='subchild1', tree=t1, parent=t1_root_child2,
                                       url='articles_detailed art_id', urlaspattern=True)
        t1_root_child2_sub1.save()
        cls.t1_root_child2_sub1 = t1_root_child2_sub1

        t1_root_child2_sub2 = TreeItem(title='subchild2', tree=t1, parent=t1_root_child2, url='/not_articles/10/')
        t1_root_child2_sub2.save()
        cls.t1_root_child2_sub2 = t1_root_child2_sub2

        t1_root_child3 = TreeItem(title='child_with_var_str', tree=t1, parent=t1_root, url='somevar_str',
                                  urlaspattern=True)
        t1_root_child3.save()
        cls.t1_root_child3 = t1_root_child3

        t1_root_child4 = TreeItem(title='child_with_var_list', tree=t1, parent=t1_root, url='somevar_list',
                                  urlaspattern=True)
        t1_root_child4.save()

        t2 = Tree(alias='tree2')
        t2.save()
        cls.t2 = t2

        t2_root1 = TreeItem(title='{{ t2_root1_title }}', tree=t2, url='/')
        t2_root1.save()
        cls.t2_root1 = t2_root1

        t2_root2 = TreeItem(title='put {{ t2_root2_title }} inside', tree=t2, url='/sub/')
        t2_root2.save()
        cls.t2_root2 = t2_root2

        t2_root3 = TreeItem(title='for logged in only', tree=t2, url='/some/', access_loggedin=True)
        t2_root3.save()
        cls.t2_root3 = t2_root3

        t2_root4 = TreeItem(title='url quoting', tree=t2, url='url 2 put_var', urlaspattern=True)
        t2_root4.save()
        cls.t2_root4 = t2_root4

        t2_root5 = TreeItem(title='url quoting 1.5 style', tree=t2, url="'url' 2 put_var", urlaspattern=True)
        t2_root5.save()
        cls.t2_root5 = t2_root5

        t2_root6 = TreeItem(title='url quoting 1.5 style', tree=t2, url='"url" 2 put_var', urlaspattern=True)
        t2_root6.save()
        cls.t2_root6 = t2_root6

        t2_root7 = TreeItem(title='for guests only', tree=t2, url='/some_other/', access_guest=True)
        t2_root7.save()
        cls.t2_root7 = t2_root7

        ###########################################################

        t3 = Tree(alias='tree3')
        t3.save()
        cls.t3 = t3

        t3_en_root = TreeItem(title='root', tree=t3, url='/', hidden=True)
        t3_en_root.save()
        cls.t3_root = t3_en_root

        t3_root_child1 = TreeItem(title='child1', tree=t3, parent=t3_en_root, url='/0/', access_loggedin=True)
        t3_root_child1.save()
        cls.t3_root_child1 = t3_root_child1

        t3_root_child2 = TreeItem(title='child2', tree=t3, parent=t3_en_root, url='/1/', inmenu=True, hidden=True)
        t3_root_child2.save()
        cls.t3_root_child2 = t3_root_child2

        t3_root_child3 = TreeItem(title='child3', tree=t3, parent=t3_en_root, url='/the_same_url/', inmenu=False)
        t3_root_child3.save()
        cls.t3_root_child3 = t3_root_child3

        t3_root_child4 = TreeItem(title='child4', tree=t3, parent=t3_en_root, url='/3/', hidden=True)
        t3_root_child4.save()
        cls.t3_root_child4 = t3_root_child4

        t3_root_child5 = TreeItem(title='child5', tree=t3, parent=t3_en_root, url='/4/', inmenu=True, hidden=True)
        t3_root_child5.save()
        cls.t3_root_child5 = t3_root_child5

        t3_en = Tree(alias='tree3_en', title='tree3en_title')
        t3_en.save()
        cls.t3_en = t3_en

        t3_en_root = TreeItem(title='root_en', tree=t3_en, url='/')
        t3_en_root.save()
        cls.t3_en_root = t3_en_root

        t3_en_root_child1 = TreeItem(title='child1_en', tree=t3_en, parent=t3_en_root, url='/0_en/')
        t3_en_root_child1.save()

        t3_en_root_child2 = TreeItem(title='child2_en', tree=t3_en, parent=t3_en_root, url='/the_same_url/')
        t3_en_root_child2.save()

        ###########################################################

        tree_main = Tree(alias='main')
        tree_main.save()
        cls.tree_main = tree_main

        tree_main_root = TreeItem(title='root', tree=tree_main, url='/', alias='for_dynamic')
        tree_main_root.save()
        cls.tree_main_root = tree_main_root