Пример #1
0
 def test_slug_used(self, client):
     """ slug already exists in parent """
     root = Node.root()
     root.add("world")
     form = formfactory(Type1)(parent=root, data=dict(title="hello", slug="world"))
     assert not form.is_valid()
     assert "slug" in form.errors
Пример #2
0
 def test_change_slug_duplicate(self, client):
     """ change a slug """
     aaa = Node.root().add("aaa")
     aaa.add("bbb")
     node = aaa.add("bbb2")
     py.test.raises(DuplicatePathException, node.set_slug, "bbb")
     assert node.slug() == "bbb2"
Пример #3
0
 def test_coerce_parent(self, client):
     """ coerce a dict holding an parent path """
     root = Node.root()
     a = root.add("a")
     res = MainHandler.coerce(dict(parent="a"))
     assert 'parent' in res
     assert res['parent'] == a
     assert 'instance' not in res
Пример #4
0
    def test_unique(self, client):
        """ paths are unique, you cannot add  the same name twice """
        root = Node.root()
        root.add("child")

        py.test.raises(DuplicatePathException, root.add, "child")
        py.test.raises(DuplicatePathException, root.add, "CHILD")
        py.test.raises(DuplicatePathException, root.add, "Child")
Пример #5
0
    def test_explicit_position(self, client):
        """ childs are returned in order they were added """
        root = Node.root()
        c1 = root.add("c1", position=20)
        c2 = root.add("c2", position=10)
        c3 = root.add("c3", position=30)

        assert list(root.children()) == [c2, c1, c3]
Пример #6
0
 def test_success(self, client):
     """ simple case where create succeeds """
     root = Node.root()
     form = formfactory(Type1)(parent=root, data=dict(title="hello", slug="world"))
     assert form.is_valid()
     assert form.cleaned_data["slug"] == "world"
     tp1 = form.save()
     assert tp1.title == "hello"
Пример #7
0
 def test_add_child_root(self, client):
     """ adding a child to the root results in a new node """
     root = Node.root()
     child = root.add("child")
     assert isinstance(child, Node)
     assert child.path == "/child"
     assert root.children().count() == 1
     assert root.children()[0] == child
     assert child.parent() == root
Пример #8
0
    def test_node_set_base(self, client):
        """ test the node.set method  with Content instance """
        root = Node.root()
        child1 = root.add("n1")
        c1 = Type1()
        c1.save()
        child1.set(c1.content_ptr)

        assert child1.content() == c1
Пример #9
0
 def test_create_get_root(self, client):
     """ test create on root - get """
     root = Node.root()
     Type1(node=root).save()
     request = create_request("GET", "/", data=dict(type="type1"))
     handler = MainHandlerTestable(request=request, instance=root)
     # import pytest; pytest.set_trace()
     create = handler.create()
     assert create['path'] == "wheelcms_axe/create.html"
     assert 'form' in create['context']
Пример #10
0
 def test_coerce_instance_parent(self, client):
     """ coerce a dict holding both instance and parent """
     root = Node.root()
     a = root.add("a")
     b = a.add("b")
     res = MainHandler.coerce(dict(instance="b", parent="a"))
     assert 'instance' in res
     assert 'parent' in res
     assert res['instance'] == b
     assert res['parent'] == a
Пример #11
0
 def test_node_set_inuse(self, client):
     """ a node can not hold two content items """
     root = Node.root()
     child1 = root.add("n1")
     c1 = Type1()
     c1.save()
     child1.set(c1)
     c2 = Type2()
     c2.save()
     pytest.raises(NodeInUse, child1.set, c2)
Пример #12
0
 def test_node_set(self, client):
     """ test the node.set method """
     root = Node.root()
     child1 = root.add("n1")
     c1 = Type1()
     c1.save()
     child1.set(c1)
     c1 = Type1.objects.get(pk=c1.pk)  ## get updated state
     assert child1.content() == c1
     assert c1.node == child1
Пример #13
0
    def test_position_after_end(self, client):
        """ insert a node at the end """
        root = Node.root()
        c1 = root.add("c1", position=100)
        c2 = root.add("c2", position=101)
        c3 = root.add("c3", after=c2)

        children = list(root.children())
        assert children == [c1, c2, c3]
        assert children[0].position < children[1].position \
               < children[2].position
Пример #14
0
    def test_position_before_begin(self, client):
        """ insert a node directly before the first item """
        root = Node.root()
        c1 = root.add("c1", position=100)
        c2 = root.add("c2", position=101)
        c3 = root.add("c3", before=c1)

        children = list(root.children())
        assert children == [c3, c1, c2]
        assert children[0].position < children[1].position \
               < children[2].position
Пример #15
0
    def test_position_after_conflict(self, client):
        """ insert a node directly after another, with position conflict  """
        root = Node.root()
        c1 = root.add("c1", position=100)
        c2 = root.add("c2", position=101)
        c3 = root.add("c3", after=c1)

        children = list(root.children())
        assert children == [c1, c3, c2]
        assert children[0].position < children[1].position \
               < children[2].position
Пример #16
0
    def test_position_after_simple(self, client):
        """ insert a node directly after another """
        root = Node.root()
        c1 = root.add("c1")
        c2 = root.add("c2")
        c3 = root.add("c3", after=c1)

        children = list(root.children())
        assert children == [c1, c3, c2]
        assert children[0].position < children[1].position \
               < children[2].position
Пример #17
0
    def handle(self, *args, **options):
        """ Usage ../bin/django clean_usersnames (0|1) """
        root = Node.root()
        main = Page(title="Welcome", body="This is the main page")
        main.save()
        root.set(main)

        c1 = root.add('sub')
        sub = Page(title="Subpage", body="I'm a sub page")
        sub.save()
        c1.set(sub)
Пример #18
0
    def test_position_twice(self, client):
        """ inserting at the same position twice - it's allowed
            but results in undetermined order """
        root = Node.root()
        c1 = root.add("c1", position=100)
        c2 = root.add("c2", position=100)
        c3 = root.add("c3", position=100)

        children = root.children()
        assert set(children) == set((c3, c1, c2))
        assert children[0].position == children[1].position \
               == children[2].position
Пример #19
0
    def test_node_content(self, client):
        """ get the actual content instance through the node """
        root = Node.root()
        child1 = root.add("n1")
        c1 = Type1(node=child1)
        c1.save()
        child2 = root.add("n2")
        c2 = Type2(node=child2)
        c2.save()

        assert child1.content() == c1
        assert child2.content() == c2
Пример #20
0
    def test_node_set_replace(self, client):
        """ test the node.set method """
        root = Node.root()
        child1 = root.add("n1")
        c1 = Type1()
        c1.save()
        child1.set(c1)
        c2 = Type2()
        c2.save()
        old = child1.set(c2, replace=True)

        assert child1.content() == c2
        assert old == c1
Пример #21
0
    def test_add_child_sub(self, client):
        """ adding a child to a nonroot """
        root = Node.root()
        top = root.add("top")
        sub = top.add("sub")

        assert root.children().count() == 1
        assert top.children().count() == 1

        assert isinstance(sub, Node)
        assert sub.path == "/top/sub"
        assert sub.children().count() == 0
        assert top.children()[0] == sub
        assert sub.parent() == top
Пример #22
0
    def coerce(cls, i):
        """
            coerce either a parent and instance, a parent or an instance.
            If there's both a parent and an instance, the instance is relative
            to the parent, so resolving needs to be done by combing them

            We're supporting the parent/instance combo (somewhat) but don't
            really need it - <instance>/update works fine, and no instance is
            required for /create
        """
        d = dict()
        # import pdb; pdb.set_trace()

        parent_path = ""
        if i.get('parent') is not None:
            parent_path = i['parent']
            if parent_path:
                parent_path = '/' + parent_path
            d['parent'] = Node.get(parent_path)

        if i.get('instance') is not None:
            d['instance'] = Node.get(parent_path + '/' + i['instance'])
        return d
Пример #23
0
    def test_invalid(self, client):
        """ only letters, numbers, _- are allowed """
        root = Node.root()

        assert root.add("c")
        assert root.add("1")
        assert root.add("-")
        assert root.add("_")
        assert root.add("a1")
        assert root.add("aB1_-2")
        assert root.add("x" * Node.MAX_PATHLEN)

        py.test.raises(InvalidPathException, root.add, "")
        py.test.raises(InvalidPathException, root.add, "c hild")
        py.test.raises(InvalidPathException, root.add, "child$")
        py.test.raises(InvalidPathException, root.add, "child/")
        py.test.raises(InvalidPathException, root.add, "child.")
        py.test.raises(InvalidPathException, root.add,
                       "x" * (Node.MAX_PATHLEN+1))
Пример #24
0
 def test_direct_path(self, client):
     """ retrieve a node directly through its path """
     n = Node.root().add("a").add("b").add("c")
     assert Node.get("/a/b/c") == n
Пример #25
0
 def test_duplicate_content(self, client):
     """ two content objects cannot point to the same node """
     root = Node.root()
     child1 = root.add("n1")
     Type1(node=child1).save()
     pytest.raises(IntegrityError, lambda: Type1(node=child1).save())
Пример #26
0
 def test_direct_path_notfound(self, client):
     """ retrieve a node directly through its path """
     Node.root().add("a").add("b").add("c")
     assert Node.get("/d/e/f") is None
Пример #27
0
 def list(self):
     self.instance = Node.root()
     return self.view()
Пример #28
0
 def test_direct_root(self, client):
     """ retrieve the root node directly through its path """
     n = Node.root()
     assert Node.get("") == n
Пример #29
0
 def test_change_slug(self, client):
     """ change a slug """
     node = Node.root().add("aaa").add("bbb")
     assert node.slug() == "bbb"
     node.set_slug("ccc")
     assert node.slug() == "ccc"
Пример #30
0
 def test_root(self, client):
     """ verify we can get a (unique) root node """
     root1 = Node.root()
     root2 = Node.root()
     assert root1 == root2
     assert root1.isroot()