[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Traversing/tests - testAcquire.py:1.1.2.1 testAtterItem.py:1.1.2.1 testEtc.py:1.1.2.1 testNamespaceTrversal.py:1.1.2.1 testPresentation.py:1.1.2.1 testTraverser.py:1.1.2.13

Jim Fulton jim@zope.com
Thu, 23 May 2002 14:01:48 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Traversing/tests
In directory cvs.zope.org:/tmp/cvs-serv26429/lib/python/Zope/App/Traversing/tests

Modified Files:
      Tag: Zope-3x-branch
	testTraverser.py 
Added Files:
      Tag: Zope-3x-branch
	testAcquire.py testAtterItem.py testEtc.py 
	testNamespaceTrversal.py testPresentation.py 
Log Message:
This all started with wanting to be able to use url;view in a ZPT path. :)

That lead me to:

- Massive traversal refactoring.

  Namespace handling is now centralized in Zope.App.Traversing. 

- ZPT refactoring, including some renaming that touches pretty much everything. :)

  - The application specific ZPT support was moved into
    Zope.App.PageTemplate. 

  - To get page template files (for use in views):

    from Zope.App.PageTemplate import ViewPageTemplateFile

  - Fixed up security so that ZPT expressions only have access to 
    safe builtins and so that modules namespace does imports safely.

  - Got ZPTPage working!

- renaming url to absolute_url and got absolute_url to work in paths.

- Cleaned up the (as yet unused) RestrictedInterpreter module in
  Zope.Security. In particular, changed to use a separate
  RestrictedBuiltins module.



=== Added File Zope3/lib/python/Zope/App/Traversing/tests/testAcquire.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
# 
##############################################################################
"""

Revision information:
$Id: testAcquire.py,v 1.1.2.1 2002/05/23 18:01:17 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
from Zope.App.Traversing.ITraversable import ITraversable
from Zope.App.Traversing.DefaultTraversable import DefaultTraversable
from Zope.ComponentArchitecture.GlobalAdapterService import provideAdapter
from Zope.Proxy.ContextWrapper import ContextWrapper, getWrapperContext
from Zope.App.Traversing.AcquireNamespace import acquire
from Zope.Exceptions import NotFoundError

class Test(PlacelessSetup, TestCase):

    def test(self):
        provideAdapter(None, ITraversable, DefaultTraversable)

        class C:
            def __init__(self, name):
                self.name = name

        a = C('a')
        a.a1 = C('a1')
        a.a2 = C('a2')
        a.a2.a21 = C('a21')
        a.a2.a21.a211 = C('a211')

        a2 = ContextWrapper(a.a2, a)
        a21 = ContextWrapper(a.a2.a21, a2)
        a211 = ContextWrapper(a.a2.a21.a211, a21)

        acquired = acquire('a1', (), 'a1;acquire', a211, None)

        self.assertEqual(acquired.name, 'a1')

        self.assertRaises(NotFoundError,
                          acquire, 'a3', (), 'a1;acquire', a211, None)
        
        

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

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


=== Added File Zope3/lib/python/Zope/App/Traversing/tests/testAtterItem.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
# 
##############################################################################
"""

Revision information:
$Id: testAtterItem.py,v 1.1.2.1 2002/05/23 18:01:17 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup


class C:
    a = 1
    def __getitem__(self, key): return key+'value'
c=C()


class Test(CleanUp, TestCase):

    def testAttr(self):
        from Zope.App.Traversing.AttrItemNamespaces import attr
        self.assertEqual(attr('a', (), 'a;attribute', c, None), 1)

    def testItem(self):
        from Zope.App.Traversing.AttrItemNamespaces import item
        self.assertEqual(item('a', (), 'a;item', c, None), 'avalue')
        
        

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

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


=== Added File Zope3/lib/python/Zope/App/Traversing/tests/testEtc.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
# 
##############################################################################
"""

Revision information:
$Id: testEtc.py,v 1.1.2.1 2002/05/23 18:01:17 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup

class Test(CleanUp, TestCase):

    def testApplicationControl(self):
        from Zope.App.Traversing.EtcNamespace import etc
        from Zope.App.OFS.ApplicationControl.ApplicationControl \
             import ApplicationController
        
        self.assertEqual(
            etc('ApplicationController', (), 'Services;etc', None, None),
            ApplicationController)

    def testServices(self):
        from Zope.App.Traversing.EtcNamespace import etc
        class C:
            def getServiceManager(self): return 42
        
        self.assertEqual(etc('Services', (), 'Services;etc', C(), None), 42)

        

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

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


=== Added File Zope3/lib/python/Zope/App/Traversing/tests/testNamespaceTrversal.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
# 
##############################################################################
"""

Revision information:
$Id: testNamespaceTrversal.py,v 1.1.2.1 2002/05/23 18:01:17 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup

class C:
    a = 1
    def __getitem__(self, key): return key+'value'
    
c=C()


class Test(CleanUp, TestCase):

    def testAttr(self):
        from Zope.App.Traversing.Traverser import Traverser
        traverser = Traverser(c)
        v = traverser.traverse('a;attribute')
        self.assertEqual(v, 1)

    def testItem(self):
        from Zope.App.Traversing.Traverser import Traverser
        traverser = Traverser(c)
        v = traverser.traverse('a;item')
        self.assertEqual(v, 'avalue')
        
        

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

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


=== Added File Zope3/lib/python/Zope/App/Traversing/tests/testPresentation.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
# 
##############################################################################
"""

Revision information:
$Id: testPresentation.py,v 1.1.2.1 2002/05/23 18:01:17 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
from Zope.ComponentArchitecture.GlobalViewService import provideView
from Zope.ComponentArchitecture.GlobalResourceService import provideResource
from Zope.App.Traversing.PresentationNamespaces import view, resource
from Zope.Exceptions import NotFoundError
from Interface import Interface

class IContent(Interface): pass
class IPresentationType(Interface): pass

class Content: __implements__ = IContent
class Resource: __implements__ = IPresentationType
class View:
    __implements__ = IPresentationType
    
    def __init__(self, content):
        self.content = content

class Request:

    def getViewType(self): return IPresentationType
    def getViewSkin(self): return ''
    

class Test(PlacelessSetup, TestCase):

    def testView(self):
        provideView(IContent, 'foo', IPresentationType, View)

        ob = Content()
        v = view('foo', (), 'foo;view', ob, Request())
        self.assertEqual(v.__class__, View)

    def testResource(self):
        r = Resource()
        provideResource('foo', IPresentationType, r)

        ob = Content()
        rr = resource('foo', (), 'foo;resource', ob, Request())
        self.assertEqual(rr, r)
        

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

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


=== Zope3/lib/python/Zope/App/Traversing/tests/testTraverser.py 1.1.2.12 => 1.1.2.13 ===
 from Interface.Verify import verifyClass
 from Interface.Implements import instancesOfObjectImplements
-from Zope.App.OFS.ServiceManager.tests.PlacefulSetup\
-           import PlacefulSetup
+from Zope.App.OFS.ServiceManager.tests.PlacefulSetup import PlacefulSetup
 from Zope.Security.Checker \
      import ProxyFactory, defineChecker, NamesChecker, CheckerPublic, Checker
 from Zope.Security.SecurityManagement import newSecurityManager
@@ -208,7 +207,7 @@
         df = DefaultTraversable(root)
 
         further = []
-        next = df.traverse('item', further)
+        next = df.traverse('item', (), 'item', further)
         self.failUnless(next is item)
         self.assertEquals(further, [])
 
@@ -219,14 +218,14 @@
         df = DefaultTraversable(dict)
 
         further = []
-        next = df.traverse('foo', further)
+        next = df.traverse('foo', (), 'foo', further)
         self.failUnless(next is foo)
         self.assertEquals(further, [])
 
     def testNotFound(self):
         df = DefaultTraversable(C('dummy'))
 
-        self.assertRaises(NotFoundError, df.traverse, 'bar', [])
+        self.assertRaises(NotFoundError, df.traverse, 'bar', (), 'bar', [])
 
 def test_suite():
     loader = unittest.TestLoader()