~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

Viewing changes to src/zope/app/zptpage/tests/test_zptpageeval.py

  • Committer: Sidnei da Silva
  • Date: 2010-07-05 21:07:01 UTC
  • Revision ID: sidnei.da.silva@canonical.com-20100705210701-zmqhqrbzad1mhzsl
- Reduce deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##############################################################################
2
 
#
3
 
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
4
 
# All Rights Reserved.
5
 
#
6
 
# This software is subject to the provisions of the Zope Public License,
7
 
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
 
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
 
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
 
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
 
# FOR A PARTICULAR PURPOSE
12
 
#
13
 
##############################################################################
14
 
"""Test ZPT Page Evaluation 
15
 
 
16
 
$Id: test_zptpageeval.py 95489 2009-01-29 18:38:14Z faassen $
17
 
"""
18
 
from unittest import TestCase, main, makeSuite
19
 
from zope.testing.cleanup import CleanUp # Base class w registry cleanup
20
 
from zope.container.contained import contained
21
 
from zope.app.zptpage.browser.zptpage import ZPTPageEval
22
 
 
23
 
class Test(CleanUp, TestCase):
24
 
 
25
 
    def testTemplateRendering(self):
26
 
 
27
 
        class Template(object):
28
 
            def render(self, request, **kw):
29
 
                self.called = request, kw
30
 
                return 42
31
 
 
32
 
            content_type = 'text/x-test'
33
 
 
34
 
        class Folder(object):
35
 
            name='zope'
36
 
        folder = Folder()
37
 
 
38
 
        class Response(object):
39
 
 
40
 
            base = None
41
 
 
42
 
            def setBase(self, base):
43
 
                self.base = base
44
 
 
45
 
            def setHeader(self, name, value):
46
 
                setattr(self, name, value)
47
 
 
48
 
        class Request(object):
49
 
 
50
 
            response = Response()
51
 
 
52
 
            URL = ['http://localhost', 'http://localhost/pt']
53
 
 
54
 
        request = Request()
55
 
        template = contained(Template(), folder)
56
 
 
57
 
        view = ZPTPageEval()
58
 
        # Do manually, since directive adds BrowserView as base class
59
 
        view.context = template
60
 
        view.request = request
61
 
        self.assertEqual(view.index(), 42)
62
 
        self.assertEqual(template.called, (request, {}))
63
 
        self.assertEqual(getattr(request.response, 'content-type'),
64
 
                         'text/x-test')
65
 
 
66
 
def test_suite():
67
 
    return makeSuite(Test)
68
 
 
69
 
if __name__=='__main__':
70
 
    main(defaultTest='test_suite')