[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_zpt.py:1.1.2.1 objecthubsetup.py:1.4.4.1 placefulsetup.py:1.5.4.1 test_auth.py:1.5.2.1 test_eventservice.py:1.7.2.1 test_view.py:1.3.2.1 test_viewpackage.py:1.3.2.1

Sidnei da Silva sidnei@x3ng.com.br
Tue, 11 Feb 2003 09:42:01 -0500


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

Modified Files:
      Tag: paris-copypasterename-branch
	objecthubsetup.py placefulsetup.py test_auth.py 
	test_eventservice.py test_view.py test_viewpackage.py 
Added Files:
      Tag: paris-copypasterename-branch
	test_zpt.py 
Log Message:
Updating from HEAD to make sure everything still works before merging

=== Added File Zope3/src/zope/app/services/tests/test_zpt.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""
$Id: test_zpt.py,v 1.1.2.1 2003/02/11 14:41:30 sidnei Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
import zope.app.services.zpt

class Test(TestCase):

    # XXX We need tests for the template class itself and for the
    # SearchableText adapter.

    def test_ReadFile(self):
        template = zope.app.services.zpt.ZPTTemplate()
        source = '<p>Test content</p>'
        template.source = source
        adapter = zope.app.services.zpt.ReadFile(template)
        self.assertEqual(adapter.read(), source)
        self.assertEqual(adapter.size(), len(source))

    def test_WriteFile(self):
        template = zope.app.services.zpt.ZPTTemplate()
        source = '<p>Test content</p>'
        template.source = '<p>Old content</p>'
        adapter = zope.app.services.zpt.WriteFile(template)
        adapter.write(source)        
        self.assertEqual(template.source, source)

    def test_ZPTFactory(self):
        factory = zope.app.services.zpt.ZPTFactory(None)
        source = '<p>Test content</p>'
        template = factory('foo', 'text/html', source)
        self.assertEqual(template.source, source)

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


=== Zope3/src/zope/app/services/tests/objecthubsetup.py 1.4 => 1.4.4.1 ===
--- Zope3/src/zope/app/services/tests/objecthubsetup.py:1.4	Mon Dec 30 10:08:17 2002
+++ Zope3/src/zope/app/services/tests/objecthubsetup.py	Tue Feb 11 09:41:30 2003
@@ -19,6 +19,7 @@
 
 from zope.app.services.tests.eventsetup import EventSetup
 from zope.component import getServiceManager, getService
+from zope.component.servicenames import HubIds
 from zope.app.services.service import ServiceConfiguration
 from zope.app.traversing import getPhysicalPathString, traverse
 from zope.app.traversing import locationAsTuple
@@ -98,5 +99,5 @@
         
     def setUp(self):
         EventSetup.setUp(self)
-        self.object_hub = getService(self.rootFolder, 'HubIds')
+        self.object_hub = getService(self.rootFolder, HubIds)
 


=== Zope3/src/zope/app/services/tests/placefulsetup.py 1.5 => 1.5.4.1 ===
--- Zope3/src/zope/app/services/tests/placefulsetup.py:1.5	Mon Dec 30 09:03:17 2002
+++ Zope3/src/zope/app/services/tests/placefulsetup.py	Tue Feb 11 09:41:30 2003
@@ -19,6 +19,7 @@
 from zope import component as CA
 from zope.component.adapter import provideAdapter
 from zope.component.view import provideView
+from zope.component.servicenames import HubIds, Events, Subscription
 from zope.publisher.interfaces.browser import IBrowserPresentation
 
 from zope.app.browser.absoluteurl import SiteAbsoluteURL, AbsoluteURL
@@ -155,12 +156,12 @@
         default.setObject(service_name, EventService())
 
         path = "%s/%s" % (getPhysicalPathString(default), service_name)
-        configuration = ServiceConfiguration("Events", path)
+        configuration = ServiceConfiguration(Events, path)
         default['configure'].setObject(
                 "%sEventsDir" % service_name, configuration)
         traverse(default, 'configure/1').status = Active
 
-        configuration = ServiceConfiguration("Subscription", path)
+        configuration = ServiceConfiguration(Subscription, path)
         default['configure'].setObject(
                 "%sSubscriptionServiceDir" % service_name, configuration)
         traverse(default, 'configure/2').status = Active
@@ -180,12 +181,12 @@
         from zope.app.interfaces.services.hub import IObjectHub
         from zope.app.interfaces.services.event import ISubscriptionService
         from zope.app.services.event import EventService
-        defineService("Subscription", ISubscriptionService)
+        defineService(Subscription, ISubscriptionService)
 
         # Events service already defined by
         # zope.app.events.tests.PlacelessSetup
 
-        defineService("HubIds", IObjectHub)
+        defineService(HubIds, IObjectHub)
 
         sm = traverse(root, '++etc++Services')
         default = traverse(sm, 'Packages/default')
@@ -193,17 +194,17 @@
         default.setObject("myObjectHub", self.getObjectHub())
 
         path = "%s/Packages/default/myEventService" % getPhysicalPathString(sm)
-        configuration = ServiceConfiguration("Events", path)
+        configuration = ServiceConfiguration(Events, path)
         default['configure'].setObject("myEventServiceDir", configuration)
         traverse(default, 'configure/1').status = Active
 
-        configuration = ServiceConfiguration("Subscription", path)
+        configuration = ServiceConfiguration(Subscription, path)
         default['configure'].setObject(
                 "mySubscriptionServiceDir", configuration)
         traverse(default, 'configure/2').status = Active
 
         path = "%s/Packages/default/myObjectHub" % getPhysicalPathString(sm)
-        configuration = ServiceConfiguration("HubIds", path)
+        configuration = ServiceConfiguration(HubIds, path)
         default['configure'].setObject("myHubIdsServiceDir", configuration)
         traverse(default, 'configure/3').status = Active
 


=== Zope3/src/zope/app/services/tests/test_auth.py 1.5 => 1.5.2.1 ===
--- Zope3/src/zope/app/services/tests/test_auth.py:1.5	Fri Jan 31 06:03:32 2003
+++ Zope3/src/zope/app/services/tests/test_auth.py	Tue Feb 11 09:41:30 2003
@@ -20,6 +20,7 @@
      import AuthenticationService, DuplicateLogin, DuplicateId
 from zope.app.services.auth import User
 from zope.app.interfaces.services.auth import IUser
+from zope.component.servicenames import Adapters, Authentication
 
 from zope.exceptions import NotFoundError
 from zope.publisher.interfaces.http import IHTTPCredentials
@@ -53,7 +54,7 @@
         from zope.component import getService
         from zope.app.security.basicauthadapter import BasicAuthAdapter
         from zope.app.interfaces.security import ILoginPassword
-        getService(None, "Adapters").provideAdapter(
+        getService(None, Adapters).provideAdapter(
             IHTTPCredentials, ILoginPassword, BasicAuthAdapter)
 
         folder = self.rootFolder
@@ -66,7 +67,7 @@
         auth = traverse(default, key)
 
         path = getPhysicalPathString(auth)
-        configuration = ServiceConfiguration("Authentication", path)
+        configuration = ServiceConfiguration(Authentication, path)
         configure = traverse(default, 'configure')
         key = configure.setObject(None, configuration)
         traverse(configure, key).status = Active
@@ -88,8 +89,8 @@
              import principalRegistry
         from zope.app.interfaces.security import IAuthenticationService
         sm = getServiceManager(None)
-        sm.defineService("Authentication", IAuthenticationService)
-        sm.provideService("Authentication", principalRegistry)
+        sm.defineService(Authentication, IAuthenticationService)
+        sm.provideService(Authentication, principalRegistry)
 
 
 class AuthServiceTest(AuthSetup, TestCase):


=== Zope3/src/zope/app/services/tests/test_eventservice.py 1.7 => 1.7.2.1 ===
--- Zope3/src/zope/app/services/tests/test_eventservice.py:1.7	Mon Feb  3 10:59:17 2003
+++ Zope3/src/zope/app/services/tests/test_eventservice.py	Tue Feb 11 09:41:30 2003
@@ -21,6 +21,7 @@
 from zope.interface import Interface
 from zope.app.services.service import ServiceManager, ServiceConfiguration
 from zope.component import getServiceManager
+from zope.component.servicenames import Events, Subscription
 from zope.app.services.event import EventService
 from zope.app.traversing import getPhysicalPathString, traverse
 from zope.exceptions import NotFoundError
@@ -810,11 +811,11 @@
         default.setObject("myEventService", service)
 
         path = "%s/Packages/default/myEventService" % getPhysicalPathString(sm)
-        configuration = ServiceConfiguration("Events", path)
+        configuration = ServiceConfiguration(Events, path)
         default['configure'].setObject("myEventServiceDir", configuration)
         traverse(default, 'configure/1').status = Active
 
-        configuration = ServiceConfiguration("Subscription", path)
+        configuration = ServiceConfiguration(Subscription, path)
         default['configure'].setObject("mySubscriptionServiceDir",
                                        configuration)
         traverse(
@@ -867,13 +868,13 @@
             )
 
         sm = traverse(self.rootFolder, "folder1/++etc++Services")
-        configuration = sm.queryConfigurations("Events").active()
+        configuration = sm.queryConfigurations(Events).active()
         configuration.status = Registered
         publish(self.rootFolder, ObjectAddedEvent(None, '/foo'))
         self.assertEqual(self.folder1Subscriber.notified, 1)
         self.assertEqual(self.folder1_1Subscriber.notified, 1)
 
-        configuration = sm.queryConfigurations("Subscription").active()
+        configuration = sm.queryConfigurations(Subscription).active()
         configuration.status = Registered
 
         publish(self.rootFolder, ObjectAddedEvent(None, '/foo'))
@@ -891,10 +892,10 @@
         self.assertEqual(self.rootFolderSubscriber.notified, 1)
 
         sm = traverse(self.rootFolder, "folder2/++etc++Services")
-        configuration = sm.queryConfigurations("Subscription").active()
+        configuration = sm.queryConfigurations(Subscription).active()
         # make sure it doesn't raise any errors
         configuration.status = Registered
-        configuration = sm.queryConfigurations("Events").active()
+        configuration = sm.queryConfigurations(Events).active()
         # make sure it doesn't raise any errors
         configuration.status = Registered
 


=== Zope3/src/zope/app/services/tests/test_view.py 1.3 => 1.3.2.1 ===
--- Zope3/src/zope/app/services/tests/test_view.py:1.3	Tue Jan 21 16:45:09 2003
+++ Zope3/src/zope/app/services/tests/test_view.py	Tue Feb 11 09:41:30 2003
@@ -37,6 +37,8 @@
 from zope.interface.verify import verifyObject
 from zope.component.interfaces import IViewService
 from zope.proxy.introspection import removeAllProxies
+from zope.configuration.exceptions import ConfigurationError
+
 class I1(Interface):
     pass
 
@@ -66,11 +68,16 @@
 
 class C: pass
 
+class PhonyTemplate:
+
+    __implements__ = IZPTTemplate
+
 class A:
     def __init__(self, object, request):
         self.context = object
         self.request = request
 
+    run = PhonyTemplate()
 
 class TestViewService(PlacefulSetup, TestingIConfigurable, TestCase):
 
@@ -214,31 +221,29 @@
         self.assertEqual(self.configuration.forInterface, I1)
         self.assertEqual(self.configuration.presentationType, I2)
 
-class PhonyTemplate:
-
-    __implements__ = IZPTTemplate
 
 class TestPageConfiguration(PlacefulSetup, TestCase):
 
     def setUp(self):
         PlacefulSetup.setUp(self)
-        rootFolder = RootFolder()
-        rootFolder.setServiceManager(PhonyServiceManager())
-        default = traverse(rootFolder, '++etc++Services/Packages/default')
+        self.rootFolder = RootFolder()
+        self.rootFolder.setServiceManager(PhonyServiceManager())
+        default = traverse(self.rootFolder, '++etc++Services/Packages/default')
         self.__template = PhonyTemplate()
         default.setObject('t', self.__template)
-        self.__configuration = ContextWrapper(
+
+    def test_getView_template(self):
+        configuration = ContextWrapper(
             PageConfiguration(I1, 'test', 'zope.View',
                               "Foo.Bar.A",
-                              '/++etc++Services/Packages/default/t',
+                              template='/++etc++Services/Packages/default/t',
                               ),
-            rootFolder,
+            self.rootFolder,
             )
 
-    def test_getView(self):
         c = C()
         request = TestRequest()
-        view = self.__configuration.getView(c, request)
+        view = configuration.getView(c, request)
         self.assertEqual(view.__class__, BoundTemplate)
         self.assertEqual(removeAllProxies(view).template, self.__template)
 
@@ -246,8 +251,36 @@
         self.assert_(issubclass(view.__class__, A))
         self.assertEqual(view.context, c)
         self.assertEqual(view.request, request)
-        self.assertEqual(self.__configuration.forInterface, I1)
-        self.assertEqual(self.__configuration.presentationType, I2)
+        self.assertEqual(configuration.forInterface, I1)
+        self.assertEqual(configuration.presentationType, I2)
+
+    def test_getView_attribute(self):
+        configuration = ContextWrapper(
+            PageConfiguration(I1, 'test', 'zope.View',
+                              "Foo.Bar.A",
+                              attribute='run',
+                              ),
+            self.rootFolder,
+            )
+        c = C()
+        request = TestRequest()
+        view = configuration.getView(c, request)
+        self.assertEquals(view, A.run)
+
+    def test_getView_errors(self):
+        configuration = ContextWrapper(
+            PageConfiguration(I1, 'test', 'zope.View',
+                              "Foo.Bar.A",
+                              ),
+            self.rootFolder,
+            )
+        c = C()
+        request = TestRequest()
+        self.assertRaises(ConfigurationError, configuration.getView, c, request)
+        configuration.template = '/++etc++Services/Packages/default/t'
+        configuration.attribute = 'run'
+        self.assertRaises(ConfigurationError, configuration.getView, c, request)
+
 
 def test_suite():
     return TestSuite((


=== Zope3/src/zope/app/services/tests/test_viewpackage.py 1.3 => 1.3.2.1 ===
--- Zope3/src/zope/app/services/tests/test_viewpackage.py:1.3	Mon Feb  3 12:29:11 2003
+++ Zope3/src/zope/app/services/tests/test_viewpackage.py	Tue Feb 11 09:41:30 2003
@@ -17,17 +17,18 @@
 """
 
 from unittest import TestCase, TestSuite, main, makeSuite
-from zope.app.services.tests.placefulsetup \
-     import PlacefulSetup
+from zope.app.services.tests.placefulsetup import PlacefulSetup
 from zope.app.services.viewpackage import ViewPackage
 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.app.services.service import ServiceConfiguration
 from zope.interface import Interface
+from zope.publisher.interfaces.browser import IBrowserPresentation
+
+class I(Interface): pass
 
 class Test(PlacefulSetup, TestCase):
 
@@ -37,9 +38,9 @@
         default = traverse(self.rootFolder, '++etc++Services/Packages/default')
         default.setObject('Views', ViewPackage())
         views = traverse(default, 'Views')
-        views.forInterface = Interface
+        views.forInterface = I
         views.factoryName = None
-        views.permission = None
+        views.permission = 'zope.View'
 
         #set up view service
         default.setObject('ViewService', ViewService())
@@ -55,6 +56,13 @@
 
         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', ViewPackage())