[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_pagefolder.py:1.1 test_configurationmanager.py:1.5 test_folder.py:1.3 test_viewpackage.py:NONE

Jim Fulton jim@zope.com
Sun, 23 Mar 2003 14:24:47 -0500


Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv23262/src/zope/app/services/tests

Modified Files:
	test_configurationmanager.py test_folder.py 
Added Files:
	test_pagefolder.py 
Removed Files:
	test_viewpackage.py 
Log Message:
Refactored support for managing configuration managers by factoring
into separate interfaces and classes so that both site-management
folders and page folders can provide the same bahavior.


=== Added File Zope3/src/zope/app/services/tests/test_pagefolder.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_pagefolder.py,v 1.1 2003/03/23 19:24:46 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.services.pagefolder import PageFolder
from zope.app.traversing import traverse
from zope.app.services.zpt import ZPTTemplate
from zope.app.services.view import ViewService
from zope.app.interfaces.services.configuration import Active
from zope.app.services.service import ServiceManager
from zope.app.services.service import ServiceConfiguration
from zope.interface import Interface
from zope.publisher.interfaces.browser import IBrowserPresentation
from zope.app.services.tests.test_configurationmanager \
     import ConfigurationManagerContainerTests

class I(Interface): pass

class Test(ConfigurationManagerContainerTests, PlacefulSetup, TestCase):

    def test_setObject(self):
        self.buildFolders()
        self.rootFolder.setServiceManager(ServiceManager())
        default = traverse(self.rootFolder, '++etc++Services/default')
        default.setObject('Views', PageFolder())
        views = traverse(default, 'Views')
        views.forInterface = I
        views.factoryName = None
        views.permission = 'zope.View'

        #set up view service
        default.setObject('ViewService', ViewService())
        configure = traverse(default, 'configure')
        configuration = ServiceConfiguration(
            'Views',
            '/++etc++Services/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.assertEqual(configuration.forInterface, I)
        self.assertEqual(configuration.presentationType, IBrowserPresentation)
        self.assertEqual(configuration.viewName, u'foo.html')
        self.assertEqual(configuration.layer, 'default')
        self.assertEqual(configuration.class_, None)
        self.assertEqual(configuration.permission, 'zope.View')
        self.assertEqual(configuration.attribute, None)

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


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

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


=== Zope3/src/zope/app/services/tests/test_configurationmanager.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/services/tests/test_configurationmanager.py:1.4	Fri Mar 21 16:06:27 2003
+++ Zope3/src/zope/app/services/tests/test_configurationmanager.py	Sun Mar 23 14:24:46 2003
@@ -15,17 +15,19 @@
 $Id$
 """
 
-from zope.app.services.configuration import ConfigurationManager
-from zope.app.interfaces.services.configuration import IConfigurationManager
 from unittest import TestCase, TestSuite, main, makeSuite
-from zope.interface.common.tests.basemapping import BaseTestIEnumerableMapping
-from zope.interface.verify import verifyObject
-from zope.app.interfaces.container import IDeleteNotifiable
+from zope.app.container.zopecontainer import ZopeContainerAdapter
 from zope.app.interfaces.container import IContainer
+from zope.app.interfaces.container import IDeleteNotifiable
 from zope.app.interfaces.container import IZopeContainer
-from zope.app.container.zopecontainer import ZopeContainerAdapter
+from zope.app.interfaces.services.configuration import IConfigurationManager
+from zope.app.services.configuration import ConfigurationManager
+from zope.app.services.tests import placefulsetup
 from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.traversing import traverse
 from zope.component.adapter import provideAdapter
+from zope.interface.common.tests.basemapping import BaseTestIEnumerableMapping
+from zope.interface.verify import verifyObject
 
 
 class Undeletable:
@@ -339,6 +341,35 @@
         manager.setObject('xyzzy', thingy)
         manager.beforeDeleteHook(manager, container)
         self.failUnless(thingy.was_called)
+
+class ConfigurationManagerContainerTests(placefulsetup.PlacefulSetup):
+
+    def test_getConfigurationManager(self):
+        self.buildFolders()
+        sm = placefulsetup.createServiceManager(self.rootFolder)
+        default = traverse(sm, 'default')
+        self.assertEqual(default.getConfigurationManager(),
+                         default['configure'])
+        default.setObject('xxx', ConfigurationManager())
+        del default['configure']
+        self.assertEqual(default.getConfigurationManager(),
+                         default['xxx'])
+
+
+#       Can't test empty because there's no way to make it empty.
+##         del default['xxx']
+##         self.assertRaises(Exception,
+##                           default.getConfigurationManager)
+
+    def test_cant_remove_last_cm(self):
+        self.buildFolders()
+        sm = placefulsetup.createServiceManager(self.rootFolder)
+        default = traverse(sm, 'default')
+        self.assertRaises(Exception,
+                          default.__delitem__, 'configuration')
+        default.setObject('xxx', ConfigurationManager())
+        del default['configure']
+        
 
 
 def test_suite():


=== Zope3/src/zope/app/services/tests/test_folder.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/services/tests/test_folder.py:1.2	Sun Mar 23 13:04:27 2003
+++ Zope3/src/zope/app/services/tests/test_folder.py	Sun Mar 23 14:24:46 2003
@@ -17,38 +17,12 @@
 """
 
 import unittest
-from zope.app.services.tests import placefulsetup
-from zope.app.traversing import traverse
-from zope.app.services.configuration import ConfigurationManager
+from zope.app.services.tests.test_configurationmanager \
+     import ConfigurationManagerContainerTests
 
-class TestSomething(placefulsetup.PlacefulSetup, unittest.TestCase):
 
-    def test_getConfigurationManager(self):
-        self.buildFolders()
-        sm = placefulsetup.createServiceManager(self.rootFolder)
-        default = traverse(sm, 'default')
-        self.assertEqual(default.getConfigurationManager(),
-                         default['configure'])
-        default.setObject('xxx', ConfigurationManager())
-        del default['configure']
-        self.assertEqual(default.getConfigurationManager(),
-                         default['xxx'])
-
-
-#       Can't test empty because there's no way to make it empty.
-##         del default['xxx']
-##         self.assertRaises(Exception,
-##                           default.getConfigurationManager)
-
-    def test_cant_remove_last_cm(self):
-        self.buildFolders()
-        sm = placefulsetup.createServiceManager(self.rootFolder)
-        default = traverse(sm, 'default')
-        self.assertRaises(Exception,
-                          default.__delitem__, 'configuration')
-        default.setObject('xxx', ConfigurationManager())
-        del default['configure']
-        
+class TestSomething(ConfigurationManagerContainerTests, unittest.TestCase):
+    "Test configuration manager access"
         
 
 def test_suite():

=== Removed File Zope3/src/zope/app/services/tests/test_viewpackage.py ===