testHTMLTests.py :  » Web-Frameworks » Zope » Zope-2.6.0 » lib » python » Products » PageTemplates » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Zope 
Zope » Zope 2.6.0 » lib » python » Products » PageTemplates » tests » testHTMLTests.py
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################

import os, sys, unittest

from Products.PageTemplates.tests import util
from Products.PageTemplates.PageTemplate import PageTemplate
from Products.PageTemplates.GlobalTranslationService import \
     setGlobalTranslationService
from AccessControl import SecurityManager
from AccessControl.SecurityManagement import noSecurityManager

from Acquisition import Implicit
class AqPageTemplate(Implicit, PageTemplate):
    pass

class Folder(util.Base):
    pass

class TestTranslationService:
    def translate(self, domain, msgid, *args, **kw):
        return "[%s](%s)" % (domain, msgid)


class UnitTestSecurityPolicy:
    """
        Stub out the existing security policy for unit testing purposes.
    """
    #
    #   Standard SecurityPolicy interface
    #
    def validate( self
                , accessed=None
                , container=None
                , name=None
                , value=None
                , context=None
                , roles=None
                , *args
                , **kw):
        return 1

    def checkPermission( self, permission, object, context) :
        return 1

class HTMLTests(unittest.TestCase):

    def setUp(self):
        self.folder = f = Folder()
        f.laf = AqPageTemplate()
        f.t = AqPageTemplate()
        self.policy = UnitTestSecurityPolicy()
        self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
        noSecurityManager()  # Use the new policy.

    def tearDown(self):
        SecurityManager.setSecurityPolicy( self.oldPolicy )
        noSecurityManager()  # Reset to old policy.

    def assert_expected(self, t, fname, *args, **kwargs):
        t.write(util.read_input(fname))
        assert not t._v_errors, 'Template errors: %s' % t._v_errors
        expect = util.read_output(fname)
        out = apply(t, args, kwargs)
        util.check_html(expect, out)

    def assert_expected_unicode(self, t, fname, *args, **kwargs):
        t.write(util.read_input(fname))
        assert not t._v_errors, 'Template errors: %s' % t._v_errors
        expect = util.read_output(fname)
        expect = unicode(expect, 'utf8')
        out = apply(t, args, kwargs)
        util.check_html(expect, out)

    def getProducts(self):
        return [
           {'description': 'This is the tee for those who LOVE Zope. '
            'Show your heart on your tee.',
            'price': 12.99, 'image': 'smlatee.jpg'
            },
           {'description': 'This is the tee for Jim Fulton. '
            'He\'s the Zope Pope!',
            'price': 11.99, 'image': 'smpztee.jpg'
            },
           ]

    def check1(self):
        self.assert_expected(self.folder.laf, 'TeeShopLAF.html')

    def check2(self):
        self.folder.laf.write(util.read_input('TeeShopLAF.html'))

        self.assert_expected(self.folder.t, 'TeeShop2.html',
                             getProducts=self.getProducts)

    def check3(self):
        self.folder.laf.write(util.read_input('TeeShopLAF.html'))

        self.assert_expected(self.folder.t, 'TeeShop1.html',
                             getProducts=self.getProducts)

    def checkSimpleLoop(self):
        self.assert_expected(self.folder.t, 'Loop1.html')

    def checkFancyLoop(self):
        self.assert_expected(self.folder.t, 'Loop2.html')

    def checkGlobalsShadowLocals(self):
        self.assert_expected(self.folder.t, 'GlobalsShadowLocals.html')

    def checkStringExpressions(self):
        self.assert_expected(self.folder.t, 'StringExpression.html')

    def checkReplaceWithNothing(self):
        self.assert_expected(self.folder.t, 'CheckNothing.html')

    def checkWithXMLHeader(self):
        self.assert_expected(self.folder.t, 'CheckWithXMLHeader.html')

    def checkNotExpression(self):
        self.assert_expected(self.folder.t, 'CheckNotExpression.html')

    def checkPathNothing(self):
        self.assert_expected(self.folder.t, 'CheckPathNothing.html')

    def checkPathAlt(self):
        self.assert_expected(self.folder.t, 'CheckPathAlt.html')

    def checkBatchIteration(self):
        self.assert_expected(self.folder.t, 'CheckBatchIteration.html')

    def checkUnicodeInserts(self):
        self.assert_expected_unicode(self.folder.t, 'CheckUnicodeInserts.html')

    def checkI18nTranslate(self):
        self.assert_expected(self.folder.t, 'CheckI18nTranslate.html')

    def checkI18nTranslateHooked(self):
        old_ts = setGlobalTranslationService(TestTranslationService())
        self.assert_expected(self.folder.t, 'CheckI18nTranslateHooked.html')
        setGlobalTranslationService(old_ts)

def test_suite():
    return unittest.makeSuite(HTMLTests, 'check')

if __name__=='__main__':
   main()

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.