1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
4 from twisted.trial import unittest
5 from twisted.python import roots
8 class RootsTest(unittest.TestCase):
10 def testExceptions(self):
11 request = roots.Request()
14 except NotImplementedError:
20 except NotImplementedError:
25 def testCollection(self):
26 collection = roots.Collection()
27 collection.putEntity("x", 'test')
28 self.assertEqual(collection.getStaticEntity("x"),
30 collection.delEntity("x")
31 self.assertEqual(collection.getStaticEntity('x'),
34 collection.storeEntity("x", None)
35 except NotImplementedError:
40 collection.removeEntity("x", None)
41 except NotImplementedError:
46 def testConstrained(self):
47 class const(roots.Constrained):
48 def nameConstraint(self, name):
51 self.assertEqual(c.putEntity('x', 'test'), None)
52 self.failUnlessRaises(roots.ConstraintViolation,
53 c.putEntity, 'y', 'test')
56 def testHomogenous(self):
57 h = roots.Homogenous()
58 h.entityType = types.IntType
60 self.assertEqual(h.getStaticEntity('a'),1 )
61 self.failUnlessRaises(roots.ConstraintViolation,
62 h.putEntity, 'x', 'y')