aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/test/test_roots.py
blob: c9fd39ef582c32db3a90849fe5648ceecac290b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

from twisted.trial import unittest
from twisted.python import roots
import types

class RootsTest(unittest.TestCase):

    def testExceptions(self):
        request = roots.Request()
        try:
            request.write("blah")
        except NotImplementedError:
            pass
        else:
            self.fail()
        try:
            request.finish()
        except NotImplementedError:
            pass
        else:
            self.fail()

    def testCollection(self):
        collection = roots.Collection()
        collection.putEntity("x", 'test')
        self.assertEqual(collection.getStaticEntity("x"),
                             'test')
        collection.delEntity("x")
        self.assertEqual(collection.getStaticEntity('x'),
                             None)
        try:
            collection.storeEntity("x", None)
        except NotImplementedError:
            pass
        else:
            self.fail()
        try:
            collection.removeEntity("x", None)
        except NotImplementedError:
            pass
        else:
            self.fail()

    def testConstrained(self):
        class const(roots.Constrained):
            def nameConstraint(self, name):
                return (name == 'x')
        c = const()
        self.assertEqual(c.putEntity('x', 'test'), None)
        self.failUnlessRaises(roots.ConstraintViolation,
                              c.putEntity, 'y', 'test')


    def testHomogenous(self):
        h = roots.Homogenous()
        h.entityType = types.IntType
        h.putEntity('a', 1)
        self.assertEqual(h.getStaticEntity('a'),1 )
        self.failUnlessRaises(roots.ConstraintViolation,
                              h.putEntity, 'x', 'y')