[Zope3-checkins] CVS: Zope3/src/zope/app/tests -
test_decorator.py:1.1.2.1 test_location.py:1.1.2.1
test_rename.py:1.1.2.1 setup.py:1.6.2.1 test_context.py:NONE
Jim Fulton
jim at zope.com
Mon Sep 8 15:22:24 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/tests
In directory cvs.zope.org:/tmp/cvs-serv20092/src/zope/app/tests
Modified Files:
Tag: parentgeddon-branch
setup.py
Added Files:
Tag: parentgeddon-branch
test_decorator.py test_location.py test_rename.py
Removed Files:
Tag: parentgeddon-branch
test_context.py
Log Message:
Checking in work in progress on parentgeddon-branch so Fred can help
me to get the tests passing. Specific log entries will be provided
when we merge this into the head.
=== Added File Zope3/src/zope/app/tests/test_decorator.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.
#
##############################################################################
"""Context Tests
$Id: test_decorator.py,v 1.1.2.1 2003/09/08 18:21:21 jim Exp $
"""
import pickle
import unittest
from zope.app.decorator import Decorator
from zope.interface import Interface, implements, directlyProvides, providedBy
from zope.interface import directlyProvidedBy, implementedBy
from zope.testing.doctestunit import DocTestSuite
from zope.exceptions import ForbiddenAttribute
class I1(Interface):
pass
class I2(Interface):
pass
class I3(Interface):
pass
class I4(Interface):
pass
class D1(Decorator):
implements(I1)
class D2(Decorator):
implements(I2)
def check_forbidden_call(callable, *args):
try:
return callable(*args)
except ForbiddenAttribute, e:
return 'ForbiddenAttribute: %s' % e[0]
def test_providedBy_iter_w_new_style_class():
"""
>>> class X(object):
... implements(I3)
>>> x = X()
>>> directlyProvides(x, I4)
>>> [interface.getName() for interface in list(providedBy(x))]
['I4', 'I3']
>>> [interface.getName() for interface in list(providedBy(D1(x)))]
['I4', 'I3', 'I1']
>>> [interface.getName() for interface in list(providedBy(D2(D1(x))))]
['I4', 'I3', 'I1', 'I2']
"""
def test_providedBy_signature_w_new_style_class():
"""
>>> class X(object):
... implements(I3)
>>> x = X()
>>> int(providedBy(x).__signature__ == implementedBy(X).__signature__)
1
>>> int(providedBy(Decorator(x)).__signature__ ==
... implementedBy(X).__signature__)
1
>>> directlyProvides(x, I4)
>>> int(providedBy(x).__signature__ ==
... (directlyProvidedBy(x).__signature__,
... implementedBy(X).__signature__,
... )
... )
1
>>> int(providedBy(D1(x)).__signature__ ==
... (
... (directlyProvidedBy(x).__signature__,
... implementedBy(X).__signature__,
... ),
... implementedBy(D1).__signature__,
... )
... )
1
>>> int(providedBy(D2(D1(x))).__signature__ ==
... (
... (
... (directlyProvidedBy(x).__signature__,
... implementedBy(X).__signature__,
... ),
... implementedBy(D1).__signature__,
... ),
... implementedBy(D2).__signature__,
... )
... )
1
"""
def test_providedBy_signature_w_classic_class():
"""
>>> class X:
... implements(I3)
>>> x = X()
>>> int(providedBy(x).__signature__ == implementedBy(X).__signature__)
1
>>> int(providedBy(Decorator(x)).__signature__ ==
... implementedBy(X).__signature__)
1
>>> directlyProvides(x, I4)
>>> int(providedBy(x).__signature__ ==
... (directlyProvidedBy(x).__signature__,
... implementedBy(X).__signature__,
... )
... )
1
>>> int(providedBy(D1(x)).__signature__ ==
... (
... (directlyProvidedBy(x).__signature__,
... implementedBy(X).__signature__,
... ),
... implementedBy(D1).__signature__,
... )
... )
1
>>> int(providedBy(D2(D1(x))).__signature__ ==
... (
... (
... (directlyProvidedBy(x).__signature__,
... implementedBy(X).__signature__,
... ),
... implementedBy(D1).__signature__,
... ),
... implementedBy(D2).__signature__,
... )
... )
1
"""
class Thing:
pass
def test_SecurityCheckerDescriptor():
"""Descriptor for a Decorator that provides a decorated security checker.
>>> from zope.security.checker import defineChecker, NamesChecker, NoProxy
>>> from zope.app.context import DecoratedSecurityCheckerDescriptor
>>> class MyDecorator(Decorator):
... __Security_checker__ = DecoratedSecurityCheckerDescriptor()
>>> class Foo:
... a = 1
... b = 2
... c = 3
>>> defineChecker(Foo, NamesChecker(['a']))
>>> defineChecker(MyDecorator, NoProxy)
>>> w = MyDecorator(Foo())
>>> from zope.security.checker import selectChecker
>>> print selectChecker(w)
None
>>> c = w.__Security_checker__
>>> print type(c)
<class 'zope.security.checker.Checker'>
>>> c.check_getattr(w, 'a')
>>> check_forbidden_call(c.check_getattr, w, 'b')
'ForbiddenAttribute: b'
>>> check_forbidden_call(c.check_getattr, w, 'c')
'ForbiddenAttribute: c'
>>> class MyDecorator2(Decorator):
... __Security_checker__ = DecoratedSecurityCheckerDescriptor()
>>> defineChecker(MyDecorator2, NamesChecker(['b']))
>>> w = MyDecorator2(Foo())
>>> c = w.__Security_checker__
>>> print type(c)
<class 'zope.security.checker.CombinedChecker'>
>>> c.check_getattr(w, 'a')
>>> c.check_getattr(w, 'b')
>>> check_forbidden_call(c.check_getattr, w, 'c')
'ForbiddenAttribute: c'
>>> w = MyDecorator(None)
>>> int(w.__Security_checker__ is None)
1
>>> w = MyDecorator2(None)
>>> type(w.__Security_checker__)
<class 'zope.security.checker.Checker'>
"""
def test_suite():
suite = DocTestSuite()
suite.addTest(DocTestSuite('zope.app.decorator'))
return suite
if __name__ == '__main__':
unittest.main()
=== Added File Zope3/src/zope/app/tests/test_location.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.
#
##############################################################################
"""Location support tests
$Id: test_location.py,v 1.1.2.1 2003/09/08 18:21:21 jim Exp $
"""
import unittest
from zope.testing.doctestunit import DocTestSuite
def test_suite():
return unittest.TestSuite((
DocTestSuite('zope.app.location'),
))
if __name__ == '__main__': unittest.main()
=== Added File Zope3/src/zope/app/tests/test_rename.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: test_rename.py,v 1.1.2.1 2003/09/08 18:21:21 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.traversing import traverse
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.component import getAdapter
from zope.component.adapter import provideAdapter
from zope.app.interfaces.copypastemove import IObjectMover
from zope.app.interfaces.container import IContainer
from zope.app.interfaces.container import IPasteTarget
from zope.app.interfaces.container import IMoveSource
from zope.app.interfaces.container import IPasteNamesChooser
from zope.app.container.copypastemove import PasteTarget
from zope.app.container.copypastemove import MoveSource
from zope.app.container.copypastemove import PasteNamesChooser
from zope.app.copypastemove import ObjectMover
from zope.app.content.file import File
from zope.exceptions import NotFoundError, DuplicationError
from zope.app.copypastemove import rename
class RenameTest(PlacefulSetup, TestCase):
def setUp(self):
PlacefulSetup.setUp(self)
PlacefulSetup.buildFolders(self)
provideAdapter(None, IObjectMover, ObjectMover)
provideAdapter(IContainer, IPasteTarget, PasteTarget)
provideAdapter(IContainer, IMoveSource, MoveSource)
provideAdapter(IContainer, IPasteNamesChooser, PasteNamesChooser)
def test_simplerename(self):
root = self.rootFolder
folder1 = traverse(root, 'folder1')
self.failIf('file1' in folder1)
folder1.setObject('file1', File())
rename(folder1, 'file1', 'my_file1')
self.failIf('file1' in container)
self.failUnless('my_file1' in container)
def test_renamenonexisting(self):
root = self.rootFolder
folder1 = traverse(root, 'folder1')
self.failIf('a_test_file' in folder1)
self.assertRaises(NotFoundError, rename, folder1, 'file1', 'my_file1')
def test_renamesamename(self):
root = self.rootFolder
folder1 = traverse(root, 'folder1')
self.failIf('file1' in folder1)
self.failIf('file2' in folder1)
folder1.setObject('file1', File())
folder1.setObject('file2', File())
self.assertRaises(DuplicationError, rename, folder1, 'file1', 'file2')
def test_suite():
return TestSuite((
makeSuite(RenameTest),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Zope3/src/zope/app/tests/setup.py 1.6 => 1.6.2.1 ===
--- Zope3/src/zope/app/tests/setup.py:1.6 Tue Sep 2 16:46:51 2003
+++ Zope3/src/zope/app/tests/setup.py Mon Sep 8 14:21:21 2003
@@ -49,7 +49,7 @@
from zope.app.interfaces.traversing import ITraverser, ITraversable
from zope.app.traversing.adapters import DefaultTraversable
from zope.app.traversing.adapters import Traverser, RootPhysicallyLocatable
-from zope.app.traversing.adapters import WrapperPhysicallyLocatable
+from zope.app.location import LocationPhysicallyLocatable
from zope.app.traversing.namespace import etc, provideNamespaceHandler
from zope.publisher.interfaces.browser import IBrowserPresentation
def setUpTraversal():
@@ -59,7 +59,7 @@
provideAdapter(
ISimpleReadContainer, ITraversable, ContainerTraversable)
provideAdapter(
- None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
+ None, IPhysicallyLocatable, LocationPhysicallyLocatable)
provideAdapter(
IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
@@ -148,7 +148,7 @@
default = zapi.traverse(servicemanager, 'default')
default.setObject(name+suffix, service)
path = "%s/default/%s" % (zapi.getPath(servicemanager), name+suffix)
- registration = ServiceRegistration(name, path, servicemanager)
+ registration = ServiceRegistration(name, path, default)
key = default.getRegistrationManager().setObject("", registration)
zapi.traverse(default.getRegistrationManager(), key).status = ActiveStatus
return zapi.traverse(servicemanager, path)
=== Removed File Zope3/src/zope/app/tests/test_context.py ===
More information about the Zope3-Checkins
mailing list