~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/web2/test/test_compat.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from twisted.web2.test.test_server import BaseCase
 
2
import sys
 
3
 
 
4
try:
 
5
    from twisted.web import resource
 
6
 
 
7
    class OldWebResource(resource.Resource):
 
8
        def __init__(self, message, *args, **kwargs):
 
9
            self.message = message
 
10
            resource.Resource.__init__(self, *args, **kwargs)
 
11
            
 
12
        isLeaf = True
 
13
        
 
14
        def render(self, req):
 
15
            return self.message
 
16
    
 
17
except ImportError:
 
18
    resource = None
 
19
 
 
20
class OldWebCompat(BaseCase):
 
21
    try:
 
22
        import twisted.web
 
23
    except ImportError:
 
24
        skip = "can't run w/o twisted.web"
 
25
 
 
26
    def testOldWebResource(self):
 
27
        ow = OldWebResource('I am an OldWebResource')
 
28
        
 
29
        self.assertResponse((ow, "http://localhost/"),
 
30
                            (200, {}, 'I am an OldWebResource'))
 
31
 
 
32
    def testOldWebResourceNotLeaf(self):
 
33
        ow = OldWebResource('I am not a leaf')
 
34
        ow.isLeaf = False
 
35
 
 
36
        self.assertResponse((ow, "http://localhost/"),
 
37
                            (200, {}, 'I am not a leaf'))
 
38
 
 
39
    def testOldWebResourceWithChildren(self):
 
40
            
 
41
        ow = OldWebResource('I am an OldWebResource with a child')
 
42
        
 
43
        ow.isLeaf = False
 
44
 
 
45
        ow.putChild('child',
 
46
                    OldWebResource('I am a child of an OldWebResource'))
 
47
 
 
48
        self.assertResponse((ow, "http://localhost/"),
 
49
                            (200, {},
 
50
                             'I am an OldWebResource with a child'))
 
51
 
 
52
        self.assertResponse((ow, "http://localhost/child"),
 
53
                            (200, {},
 
54
                             'I am a child of an OldWebResource'))
 
55
 
 
56
        
 
57
if not resource:
 
58
    OldWebCompat.skip = "can't run w/o twisted.web"