[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests - test_viewpackage.py:1.1.2.1

Jim Fulton jim@zope.com
Thu, 12 Dec 2002 10:19:56 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests
In directory cvs.zope.org:/tmp/cvs-serv23093/lib/python/Zope/App/OFS/Services/ServiceManager/tests

Added Files:
      Tag: AdapterAndView-branch
	test_viewpackage.py 
Log Message:
Got view service and view registration working TTW (sort of).

This includes a new "View Package". You set up a view package with
default registration parameters. Then, as you add ZPT templates to the
package, they are automatically registered as views.

There are lots of rough edges that need to be smoothed out after the
sprint and before this branch merge.



=== Added File Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/test_viewpackage.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""View package tests.

$Id: test_viewpackage.py,v 1.1.2.1 2002/12/12 15:19:56 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup \
     import PlacefulSetup
from Zope.App.OFS.Services.ServiceManager.viewpackage import ViewPackage
from Zope.App.Traversing import traverse
from Zope.App.OFS.Services.zpt import ZPTTemplate
from Zope.App.OFS.Services.view import ViewService
from Zope.App.OFS.Services.ConfigurationInterfaces import Active
from Zope.App.OFS.Services.ServiceManager.ServiceManager import ServiceManager
from Zope.App.OFS.Services.ServiceManager.ServiceConfiguration \
     import ServiceConfiguration
from Interface import Interface

class Test(PlacefulSetup, TestCase):

    def test_setObject(self):
        self.buildFolders()
        self.rootFolder.setServiceManager(ServiceManager())
        default = traverse(self.rootFolder, '++etc++Services/Packages/default')
        default.setObject('Views', ViewPackage())
        views = traverse(default, 'Views')
        views.forInterface = Interface
        views.factoryName = None

        #set up view service
        default.setObject('ViewService', ViewService())
        configure = traverse(default, 'configure')
        configuration = ServiceConfiguration(
            'Views',
            '/++etc++Services/Packages/default/ViewService')
        configure.setObject('', configuration)
        configuration = traverse(configure, '1')
        configuration.status = Active

        views.setObject('foo.html', ZPTTemplate())

        configuration = traverse(views, 'configure/1')
        self.assertEqual(configuration.status, Active)

        self.assertRaises(TypeError,
                          views.setObject, 'bar.html', ViewPackage())
        

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')