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
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"
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."
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."
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!"
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
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!!"
def check_parent(self): node = zikebase.Node(self.ds, ID=2) assert isinstance(node.parent, zikebase.Node), \ ".parent doesn't return a Node"
def check_q_children(self): node = zikebase.Node(self.ds, ID=1) assert len(node.q_children()) == 1, \ "wrong q_children"