示例#1
0
    def check_path(self):
        node = zikebase.Node(self.ds, ID=2)
        node.name = "subnode"
        node.save()

        assert node.path == "top/subnode", \
               "Node has wrong path after name change: %s" % node.path
示例#2
0
    def check_recusionCheck(self):

        # if you assign a node to itself, it's bad juju,
        # because of the check for children, you can
        # never delete it! So, we want to prevent that.

        node = zikebase.Node(self.ds, ID=1)
        try:
            gotError = 0
            node.parentID = 1
        except:
            gotError = 1

        assert gotError, \
               "didn't get error assigning a node to itself."

        # need to handle strings, too, because of the web.

        try:
            gotError = 0
            node.parentID = "1"
        except:
            gotError = 1

        assert gotError, \
               "didn't get error assigning a node to itself when using string"
示例#3
0
    def check_updatePaths(self):
        # idle thought... this really doesn't account for record
        # locking... if a child is in memory, and you updatePaths,
        # it could be in conflict with the data in memory.. :/

        node1 = zikebase.Node(self.ds, ID=1)
        node1.name = "super"
        node1.save()

        node2 = zikebase.Node(self.ds, ID=2)
        assert node2.path == "super/sub", \
               "wrong child after updatePaths: %s" % node2.path

        node3 = zikebase.Node(self.ds, ID=3)
        assert node3.path == "super/sub/subsub", \
               "updatePaths doesn't update grandchildren properly."
示例#4
0
    def check_crumbs(self):
        node = zikebase.Node(self.ds, ID=1)
        goal = []
        assert node.crumbs == goal, \
               "Didn't get right crumbs for node 1."

        node = zikebase.Node(self.ds, ID=3)
        goal = [{
            "ID": 1,
            "name": "top",
            "path": "top"
        }, {
            "ID": 2,
            "name": "sub",
            "path": "top/sub"
        }]
        assert len(node.crumbs) == len(goal), \
               "Didn't get right crumbs for node 3."
示例#5
0
    def check_setPath(self):
        node = zikebase.Node(self.ds)
        try:
            gotError = 0
            node.path = "XXXX"
        except TypeError:
            gotError = 1

        assert (gotError) and (node.path != "XXXX"), \
               "Node.path is supposed to be read only!"
示例#6
0
    def check_nested(self):
        """
        Sometimes, we want to save several objects at once.
        for example, in zikeshop's point of sale system
        we want to save a Sale object with several details.

        This test attemps to save a node and one subnode.
        """
        node = zikebase.Node(self.ds)
        node.name = 'general'
        node.save()

        nodeID = node.ID
        del node

        req = {
            "action":"save",
            "children(+0|parentID)":nodeID,
            "children(+0|name)":'specific',
            }
        
        ed = zikebase.ObjectEditor(zikebase.Node, self.ds, req, nodeID)
        ed.act()

        assert len(ed.object.children) == 1, \
               "wrong length for ed.object.children: %s" \
               % len(ed.object.children)


        # now check that it actually made it to the db..
        del ed
        node = zikebase.Node(self.ds, ID=nodeID)
        assert len(node.children) == 1, \
               "wrong length for node.children: %s" % len(node.children)

        assert node.children[0].name=='specific', \
               "wrong name for child node: %s" % node.children[0].name
示例#7
0
    def check_editNode(self):
        """
        for some reason, it wasn't triggering error
        on a recursive node, even though the node
        object itself did.. (??)

        turns out it had to do with the fact that
        on the web, the parentID is a string..
        """
        node = zikebase.Node(self.ds)
        node.name="fred"
        node.save()

        req = {"action":"save", "parentID":"1"}
        ed = zikebase.ObjectEditor(zikebase.Node, self.ds, req, key=1)

        try:
            gotError = 0
            ed.act()
        except:
            gotError = 1

        assert gotError, \
               "shouldn't be able to assign Nodes to themselves!!"
示例#8
0
 def check_parent(self):
     node = zikebase.Node(self.ds, ID=2)
     assert isinstance(node.parent, zikebase.Node), \
            ".parent doesn't return a Node"
示例#9
0
 def check_q_children(self):
     node = zikebase.Node(self.ds, ID=1)
     assert len(node.q_children()) == 1, \
            "wrong q_children"