[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/tests - test_field.py:1.1.2.1 test_view.py:1.1.2.2

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


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

Modified Files:
      Tag: AdapterAndView-branch
	test_view.py 
Added Files:
      Tag: AdapterAndView-branch
	test_field.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/tests/test_field.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.
#
##############################################################################
"""Tests for ComponentLocation field.

$Id: test_field.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.Traversing import traverse
from Zope.Schema.Exceptions import ValidationError
from Interface import Interface
from Zope.App.OFS.Services.field import ComponentLocation

class I1(Interface):  pass

class C:
    __implements__ = I1

class D:
    pass

class Test(PlacefulSetup, TestCase):

    def test__validate(self):
        self.buildFolders()
        self.folder1.setObject('c', C())
        self.folder1.setObject('d', D())

        folder2 = traverse(self.rootFolder, 'folder2')

        field = ComponentLocation(type=I1)
        field = field.bind(folder2)

        field.validate(u'/folder1/c')

        self.assertRaises(ValidationError, field.validate, u'/folder1/d')
        self.assertRaises(ValidationError, field.validate, u'/folder1/e')

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

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


=== Zope3/lib/python/Zope/App/OFS/Services/tests/test_view.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/lib/python/Zope/App/OFS/Services/tests/test_view.py:1.1.2.1	Wed Dec 11 09:10:24 2002
+++ Zope3/lib/python/Zope/App/OFS/Services/tests/test_view.py	Thu Dec 12 10:19:56 2002
@@ -33,6 +33,10 @@
 from Zope.ComponentArchitecture.GlobalViewService import provideView
 from Zope.Publisher.Browser.BrowserRequest import TestRequest
 from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+from Zope.App.OFS.Services.interfaces import IZPTTemplate
+from Zope.App.OFS.Services.view import PageConfiguration, BoundTemplate
+from Interface.Verify import verifyObject
+from Zope.ComponentArchitecture.IViewService import IViewService
 
 class I1(Interface):
     pass
@@ -84,6 +88,9 @@
     def createTestingConfiguration(self):
         return Configuration()
 
+    def test_implements_IViewService(self):
+        verifyObject(IViewService, ViewService())
+
     def test_queryView_no_view(self):
         service = self._service
         class O:
@@ -172,7 +179,7 @@
             r = self._service.getRegisteredMatching(*args)
             self.assertEqual(list(r), [(I1, I2, registry, 'default', 'test')])
 
-class PhonyServiceManager:
+class PhonyServiceManager(ServiceManager):
 
     __implements__ = IServiceService
 
@@ -201,10 +208,46 @@
         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.__template = PhonyTemplate()
+        default.setObject('t', self.__template)
+        self.__configuration = ContextWrapper(
+            PageConfiguration(I1, 'test', IBrowserPresentation,
+                              "Foo.Bar.A",
+                              '/++etc++Services/Packages/default/t',
+                              ),
+            rootFolder,
+            )
+    
+    def test_getView(self):
+        c = C()
+        request = TestRequest()
+        view = self.__configuration.getView(c, request)
+        self.assertEqual(view.__class__, BoundTemplate)
+        self.assertEqual(view.template, self.__template)
+
+        view = view.view
+        self.assertEqual(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)
+
 def test_suite():
     return TestSuite((
         makeSuite(TestViewService),
         makeSuite(TestViewConfiguration),
+        makeSuite(TestPageConfiguration),
         ))
 
 if __name__=='__main__':