~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/test/test_roots.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
from twisted.trial import unittest
 
5
from twisted.python import roots
 
6
import types
 
7
 
 
8
class RootsTest(unittest.TestCase):
 
9
 
 
10
    def testExceptions(self):
 
11
        request = roots.Request()
 
12
        try:
 
13
            request.write("blah")
 
14
        except NotImplementedError:
 
15
            pass
 
16
        else:
 
17
            self.fail()
 
18
        try:
 
19
            request.finish()
 
20
        except NotImplementedError:
 
21
            pass
 
22
        else:
 
23
            self.fail()
 
24
 
 
25
    def testCollection(self):
 
26
        collection = roots.Collection()
 
27
        collection.putEntity("x", 'test')
 
28
        self.failUnlessEqual(collection.getStaticEntity("x"),
 
29
                             'test')
 
30
        collection.delEntity("x")
 
31
        self.failUnlessEqual(collection.getStaticEntity('x'),
 
32
                             None)
 
33
        try:
 
34
            collection.storeEntity("x", None)
 
35
        except NotImplementedError:
 
36
            pass
 
37
        else:
 
38
            self.fail()
 
39
        try:
 
40
            collection.removeEntity("x", None)
 
41
        except NotImplementedError:
 
42
            pass
 
43
        else:
 
44
            self.fail()
 
45
 
 
46
    def testConstrained(self):
 
47
        class const(roots.Constrained):
 
48
            def nameConstraint(self, name):
 
49
                return (name == 'x')
 
50
        c = const()
 
51
        self.failUnlessEqual(c.putEntity('x', 'test'), None)
 
52
        self.failUnlessRaises(roots.ConstraintViolation,
 
53
                              c.putEntity, 'y', 'test')
 
54
 
 
55
 
 
56
    def testHomogenous(self):
 
57
        h = roots.Homogenous()
 
58
        h.entityType = types.IntType
 
59
        h.putEntity('a', 1)
 
60
        self.failUnlessEqual(h.getStaticEntity('a'),1 )
 
61
        self.failUnlessRaises(roots.ConstraintViolation,
 
62
                              h.putEntity, 'x', 'y')
 
63