コード例 #1
0
 def testmoveNode(self):
     clist = [TextCell(),InputCell(),Section(),TextCell(),InputCell()]
     for c in clist:
         self.u.addNode(self.nb.root.nodeID, c)
     nb = self.u.addNotebook('title')
     root = self.nb.root
     self.u.moveNode(root.nodeID, nb.root.nodeID)
     self.assertEquals(self.u.user.notebooks, [nb])
     self.assertEquals(nb.root.children, [root])
     kids = root.children
     c1 = root[1]
     c = c1.previous
     self.u.moveNode(c1.nodeID, nb.root.nodeID,0)
     self.assertEquals(nb.root.children, [c1,root])
     self.assertEquals(root.children, kids[:1]+kids[2:])
 
     c0 = root[0]
     if c0.nextID is None:
         print 'anomalous next/nextID disagreement',
         n = c0.next
         c0.next = None
         c0.next = n
         self.nbc.session.flush()
     self.u.moveNode(c0.nodeID, nb.root.nodeID,1)
     self.assertEquals(nb.root.children, [c1, c0, root])
     self.assertEquals(root.children, kids[2:])
 
     c2 = root[-1]
     self.u.moveNode(c2.nodeID, nb.root.nodeID,1)
     self.assertEquals(nb.root.children, [c1, c2, c0, root])
     self.assertEquals(root.children, kids[2:-1])
     self.assertIdentical(root.head, kids[2])
     self.assertIdentical(root.tail, kids[-2])
コード例 #2
0
 def testappendNode(self):
     clist = [
         TextCell(),
         InputCell(),
         Section(),
         TextCell(),
         InputCell()
     ]
     for c in clist:
         self.u.addNode(self.nb.root.nodeID, c)
     self.assertEquals(clist, self.nb.root.children)
コード例 #3
0
 def testinsertNode(self):
     clist = [
         TextCell(),
         InputCell(),
         Section(),
         TextCell(),
         InputCell()
     ]
     for c in clist:
         self.u.addNode(self.nb.root.nodeID, c, 1)
     clist = clist[:1] + clist[-1:-5:-1]
     self.assertEquals(clist, self.nb.root.children)
コード例 #4
0
 def testeditNode(self):
     c = TextCell()
     self.u.addNode(self.nb.root.nodeID, c)
     mod1 = c.dateModified
     self.u.editNode(c.nodeID, comment="some comment")
     self.assertEquals(c.comment, "some comment")
     self.assertNotEquals(c.dateModified, mod1)
コード例 #5
0
 def testdropNode(self):
     c = TextCell()
     self.u.addNode(self.nb.root.nodeID, c)
     self.assertEquals(self.u.user.nodes, [self.nb.root, c])
     self.u.dropNode(c.nodeID)
     self.assertEquals(self.u.user.nodes, [self.nb.root])
     self.assertEquals(self.nb.root.children, [])
コード例 #6
0
 def testmultiUser(self):
     self.assertRaises(AssertionError, notebook.NotebookUser, self.nbc, 'userB')
     del self.u
     self.assertEquals(self.nbc.users, [])
     ua = notebook.NotebookUser(self.nbc, 'userA')
     ub = notebook.NotebookUser(self.nbc, 'userB', 'b@email')
     self.assertEquals(self.nbc.users, [ua.user.userID, ub.user.userID])
     c = TextCell()
     self.assertRaises(AssertionError, ub.addNode, self.nb.root.nodeID, c)
     self.assertRaises(NotFoundError, ub.addNode, 73, c)
     nb = ub.addNotebook('title')
     ub.addNode(nb.root.nodeID, c)
     c2 = InputCell()
     self.assertRaises(NotFoundError, ub.addNode, c.nodeID, c2)
コード例 #7
0
 def loadNodes(self, n):
     l = []
     for _ in range(n):
         sections = self.nbc.nodeQuery.select_by(nodeType='section')
         parent = (sections + [None])[randint(0, len(sections))]
         if parent is None:
             l.append(self.u.addNotebook("title"))
         else:
             i = randint(1, 3)
             if i == 1:
                 c = TextCell()
             elif i == 2:
                 c = InputCell()
             else:
                 c = Section()
             index = None
             if parent.children:
                 index = randint(0, len(parent.children) - 1)
             l.append(self.u.addNode(parent.nodeID, c, index))
     return l