Esempio n. 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])
Esempio n. 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)
Esempio n. 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)
Esempio n. 4
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)
Esempio n. 5
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