Commit c23a708c authored by 's avatar

- ported interfaces shipped with Five 1.0 to Zope core (Five 1.1 will use these interfaces)

- added some basic conformance tests

Note that this is just a first step:
- there are still some z2 interfaces that are not bridged to z3 interfaces
- the bridging introduces a dependency on Five, non-dynamic z3 interfaces might be more suitable (but add redundant code)
- 'implements' declarations are not complete
- many interfaces have unresolved XXX coments
parent 605924f7
......@@ -18,6 +18,9 @@ $Id$
import Globals, urlparse, SpecialUsers, ExtensionClass
from AccessControl import getSecurityManager, Unauthorized
from Acquisition import aq_get, aq_parent, aq_base
from zope.interface import implements
from interfaces import IOwned
UnownableOwner=[]
......@@ -30,6 +33,8 @@ _mark=ownableFilter
class Owned(ExtensionClass.Base):
implements(IOwned)
__ac_permissions__=(
('View management screens',
('manage_owner', 'owner_info')),
......
......@@ -23,13 +23,17 @@ from cgi import escape
import ExtensionClass, Acquisition
from Globals import InitializeClass
from zope.interface import implements
from interfaces import IPermissionMappingSupport
from Owned import UnownableOwner
from Permission import pname
class RoleManager:
implements(IPermissionMappingSupport)
def manage_getPermissionMapping(self):
"""Return the permission mapping for the object
......
......@@ -20,7 +20,9 @@ from Globals import DTMLFile, MessageDialog, Dictionary
from Acquisition import Implicit, Acquired, aq_get
import Globals, ExtensionClass, PermissionMapping, Products
from App.Common import aq_base
from zope.interface import implements
from interfaces import IRoleManager
from Permission import Permission
......@@ -37,6 +39,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
"""An object that has configurable permissions"""
implements(IRoleManager)
__ac_permissions__=(
('Change permissions',
('manage_access', 'permission_settings',
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""AccessControl z3 interfaces.
$Id$
"""
from zope.interface import Attribute
from zope.interface import Interface
# XXX: might contain non-API methods and outdated comments;
# not synced with ZopeBook API Reference;
# based on AccessControl.Owned.Owned
class IOwned(Interface):
manage_owner = Attribute("""Manage owner view""")
def owner_info():
"""Get ownership info for display
"""
def getOwner(info=0):
"""Get the owner
If a true argument is provided, then only the owner path and id are
returned. Otherwise, the owner object is returned.
"""
def getOwnerTuple():
"""Return a tuple, (userdb_path, user_id) for the owner.
o Ownership can be acquired, but only from the containment path.
o If unowned, return None.
"""
def getWrappedOwner():
"""Get the owner, modestly wrapped in the user folder.
o If the object is not owned, return None.
o If the owner's user database doesn't exist, return Nobody.
o If the owner ID does not exist in the user database, return Nobody.
"""
def changeOwnership(user, recursive=0):
"""Change the ownership to the given user.
If 'recursive' is true then also take ownership of all sub-objects,
otherwise sub-objects retain their ownership information.
"""
def userCanTakeOwnership():
"""
"""
def manage_takeOwnership(REQUEST, RESPONSE, recursive=0):
"""Take ownership (responsibility) for an object.
If 'recursive' is true, then also take ownership of all sub-objects.
"""
def manage_changeOwnershipType(explicit=1,
RESPONSE=None, REQUEST=None):
"""Change the type (implicit or explicit) of ownership.
"""
def _deleteOwnershipAfterAdd():
"""
"""
def manage_fixupOwnershipAfterAdd():
"""
"""
# XXX: might contain non-API methods and outdated comments;
# not synced with ZopeBook API Reference;
# based on AccessControl.PermissionMapping.RoleManager
class IPermissionMappingSupport(Interface):
def manage_getPermissionMapping():
"""Return the permission mapping for the object
This is a list of dictionaries with:
permission_name -- The name of the native object permission
class_permission -- The class permission the permission is
mapped to.
"""
def manage_setPermissionMapping(permission_names=[],
class_permissions=[], REQUEST=None):
"""Change the permission mapping
"""
# XXX: might contain non-API methods and outdated comments;
# not synced with ZopeBook API Reference;
# based on AccessControl.Role.RoleManager
class IRoleManager(IPermissionMappingSupport):
"""An object that has configurable permissions"""
permissionMappingPossibleValues = Attribute("""Acquired attribute""")
def ac_inherited_permissions(all=0):
"""Get all permissions not defined in ourself that are inherited.
This will be a sequence of tuples with a name as the first item and an
empty tuple as the second.
"""
def permission_settings(permission=None):
"""Return user-role permission settings.
If 'permission' is passed to the method then only the settings for
'permission' is returned.
"""
manage_roleForm = Attribute(""" """)
def manage_role(role_to_manage, permissions=[], REQUEST=None):
"""Change the permissions given to the given role.
"""
manage_acquiredForm = Attribute(""" """)
def manage_acquiredPermissions(permissions=[], REQUEST=None):
"""Change the permissions that acquire.
"""
manage_permissionForm = Attribute(""" """)
def manage_permission(permission_to_manage,
roles=[], acquire=0, REQUEST=None):
"""Change the settings for the given permission.
If optional arg acquire is true, then the roles for the permission
are acquired, in addition to the ones specified, otherwise the
permissions are restricted to only the designated roles.
"""
def manage_access(REQUEST, **kw):
"""Return an interface for making permissions settings.
"""
def manage_changePermissions(REQUEST):
"""Change all permissions settings, called by management screen.
"""
def permissionsOfRole(role):
"""Used by management screen.
"""
def rolesOfPermission(permission):
"""Used by management screen.
"""
def acquiredRolesAreUsedBy(permission):
"""Used by management screen.
"""
# Local roles support
# -------------------
#
# Local roles allow a user to be given extra roles in the context
# of a particular object (and its children). When a user is given
# extra roles in a particular object, an entry for that user is made
# in the __ac_local_roles__ dict containing the extra roles.
__ac_local_roles__ = Attribute(""" """)
manage_listLocalRoles = Attribute(""" """)
manage_editLocalRoles = Attribute(""" """)
def has_local_roles():
"""
"""
def get_local_roles():
"""
"""
def users_with_local_role(role):
"""
"""
def get_valid_userids():
"""
"""
def get_local_roles_for_userid(userid):
"""
"""
def manage_addLocalRoles(userid, roles, REQUEST=None):
"""Set local roles for a user."""
def manage_setLocalRoles(userid, roles, REQUEST=None):
"""Set local roles for a user."""
def manage_delLocalRoles(userids, REQUEST=None):
"""Remove all local roles for a user."""
#------------------------------------------------------------
def access_debug_info():
"""Return debug info.
"""
def valid_roles():
"""Return list of valid roles.
"""
def validate_roles(roles):
"""Return true if all given roles are valid.
"""
def userdefined_roles():
"""Return list of user-defined roles.
"""
def manage_defined_roles(submit=None, REQUEST=None):
"""Called by management screen.
"""
def _addRole(role, REQUEST=None):
"""
"""
def _delRoles(roles, REQUEST=None):
"""
"""
def _has_user_defined_role(role):
"""
"""
def manage_editRoles(REQUEST, acl_type='A', acl_roles=[]):
"""
"""
def _setRoles(acl_type, acl_roles):
"""
"""
def possible_permissions():
"""
"""
......@@ -63,6 +63,13 @@ class OwnedTests(unittest.TestCase):
return Dummy(*args, **kw)
def test_z3interfaces(self):
from AccessControl.interfaces import IOwned
from AccessControl.Owned import Owned
from zope.interface.verify import verifyClass
verifyClass(IOwned, Owned)
def test_getOwnerTuple_unowned(self):
owned = self._makeOne()
......@@ -169,5 +176,9 @@ class OwnedTests(unittest.TestCase):
self.assertEqual(wrapped_owner.getId(), 'user')
def test_suite():
return unittest.makeSuite(OwnedTests)
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
import unittest
class TestRoleManager(unittest.TestCase):
def test_z3interfaces(self):
from AccessControl.interfaces import IPermissionMappingSupport
from AccessControl.PermissionMapping import RoleManager
from zope.interface.verify import verifyClass
verifyClass(IPermissionMappingSupport, RoleManager)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestRoleManager),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
import unittest
class TestRoleManager(unittest.TestCase):
def test_z3interfaces(self):
from AccessControl.interfaces import IRoleManager
from AccessControl.Role import RoleManager
from zope.interface.verify import verifyClass
verifyClass(IRoleManager, RoleManager)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestRoleManager),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
from zope.interface import classImplements
from _Acquisition import *
from interfaces import IAcquirer
from interfaces import IAcquisitionWrapper
classImplements(Explicit, IAcquirer)
classImplements(ExplicitAcquisitionWrapper, IAcquisitionWrapper)
classImplements(Implicit, IAcquirer)
classImplements(ImplicitAcquisitionWrapper, IAcquisitionWrapper)
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Acquisition z3 interfaces.
$Id$
"""
from zope.interface import Attribute
from zope.interface import Interface
class IAcquirer(Interface):
"""Acquire attributes from containers.
"""
def __of__(context):
"""Get the object in a context.
"""
class IAcquisitionWrapper(Interface):
"""Wrapper object for acquisition.
"""
def aq_acquire(name, filter=None, extra=None, explicit=True, default=0,
containment=0):
"""Get an attribute, acquiring it if necessary.
"""
def aq_inContextOf(obj, inner=1):
"""Test whether the object is currently in the context of the argument.
"""
aq_base = Attribute(
"""Get the object unwrapped."""
)
aq_parent = Attribute(
"""Get the parent of an object."""
)
aq_self = Attribute(
"""Get the object with the outermost wrapper removed."""
)
aq_inner = Attribute(
"""Get the object with all but the innermost wrapper removed."""
)
aq_chain = Attribute(
"""Get a list of objects in the acquisition environment."""
)
......@@ -1502,6 +1502,32 @@ def test_cant_pickle_acquisition_wrappers_newstyle():
TypeError: Can't pickle objects in acquisition wrappers.
"""
def test_z3interfaces():
"""
>>> from zope.interface.verify import verifyClass
Explicit and Implicit implement IAcquirer:
>>> from Acquisition import Explicit
>>> from Acquisition import Implicit
>>> from Acquisition.interfaces import IAcquirer
>>> verifyClass(IAcquirer, Explicit)
True
>>> verifyClass(IAcquirer, Implicit)
True
ExplicitAcquisitionWrapper and ImplicitAcquisitionWrapper implement
IAcquisitionWrapper:
>>> from Acquisition import ExplicitAcquisitionWrapper
>>> from Acquisition import ImplicitAcquisitionWrapper
>>> from Acquisition.interfaces import IAcquisitionWrapper
>>> verifyClass(IAcquisitionWrapper, ExplicitAcquisitionWrapper)
True
>>> verifyClass(IAcquisitionWrapper, ImplicitAcquisitionWrapper)
True
"""
def show(x):
print showaq(x).strip()
......@@ -1604,4 +1630,5 @@ def test_suite():
DocTestSuite(),
))
if __name__ == '__main__': unittest.main()
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
......@@ -10,18 +10,20 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Standard management interface support
$Id$
"""
import sys, Globals, ExtensionClass, urllib
from Dialogs import MessageDialog
from Globals import DTMLFile, HTMLFile
from zExceptions import Redirect
from AccessControl import getSecurityManager, Unauthorized
from cgi import escape
from zope.interface import implements
from interfaces import INavigation
class Tabs(ExtensionClass.Base):
"""Mix-in provides management folder tab support."""
......@@ -154,6 +156,8 @@ Globals.default__class_init__(Tabs)
class Navigation(ExtensionClass.Base):
"""Basic navigation UI support"""
implements(INavigation)
__ac_permissions__=(
('View management screens',
('manage', 'manage_menu', 'manage_top_frame',
......
......@@ -10,18 +10,27 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Patch for Persistent to support IPersistentExtra.
import ZODB
$Id$
"""
from class_init import default__class_init__
from Persistence import Persistent
import Globals
from DateTime import DateTime
from Persistence import Persistent
from zope.interface import classImplements
from zope.interface import implements
from class_init import default__class_init__
from interfaces import IPersistentExtra
Persistent.__class_init__ = default__class_init__
class PersistentUtil:
implements(IPersistentExtra)
def bobobase_modification_time(self):
jar=self._p_jar
oid=self._p_oid
......@@ -75,3 +84,4 @@ for k, v in PersistentUtil.__dict__.items():
if k[0] != '_':
setattr(Persistent, k, v)
classImplements(Persistent, IPersistentExtra)
......@@ -10,9 +10,10 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Undo support.
$Id$
"""
$Id$"""
__version__='$Revision: 1.34 $'[11:-2]
from Acquisition import aq_base, aq_parent, aq_inner
from AccessControl import getSecurityManager
......@@ -20,9 +21,15 @@ from DateTime import DateTime
import Globals, ExtensionClass
from ZopeUndo.Prefix import Prefix
import transaction
from zope.interface import implements
from interfaces import IUndoSupport
class UndoSupport(ExtensionClass.Base):
implements(IUndoSupport)
__ac_permissions__=(
('Undo changes', (
'manage_undo_transactions',
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""App z3 interfaces.
$Id$
"""
from zope.interface import Attribute
from zope.interface import Interface
# XXX: might contain non-API methods and outdated comments;
# not synced with ZopeBook API Reference;
# based on App.Management.Navigation
class INavigation(Interface):
"""Basic navigation UI support"""
manage = Attribute(""" """)
manage_menu = Attribute(""" """)
manage_top_frame = Attribute(""" """)
manage_page_header = Attribute(""" """)
manage_page_footer = Attribute(""" """)
manage_form_title = Attribute("""Add Form""")
zope_quick_start = Attribute(""" """)
manage_copyright = Attribute(""" """)
manage_zmi_prefs = Attribute(""" """)
def manage_zmi_logout(REQUEST, RESPONSE):
"""Logout current user"""
INavigation.setTaggedValue('manage_page_style.css', Attribute(""" """))
# XXX: might contain non-API methods and outdated comments;
# not synced with ZopeBook API Reference;
# based on App.PersistentExtra.PersistentUtil
class IPersistentExtra(Interface):
def bobobase_modification_time():
"""
"""
def locked_in_version():
"""Was the object modified in any version?
"""
def modified_in_version():
"""Was the object modified in this version?
"""
# XXX: might contain non-API methods and outdated comments;
# not synced with ZopeBook API Reference;
# based on App.Undo.UndoSupport
class IUndoSupport(Interface):
manage_UndoForm = Attribute("""Manage Undo form""")
def get_request_var_or_attr(name, default):
"""
"""
def undoable_transactions(first_transaction=None,
last_transaction=None,
PrincipiaUndoBatchSize=None):
"""
"""
def manage_undo_transactions(transaction_info=(), REQUEST=None):
"""
"""
import unittest
class TestNavigation(unittest.TestCase):
def test_z3interfaces(self):
from App.interfaces import INavigation
from App.Management import Navigation
from zope.interface.verify import verifyClass
verifyClass(INavigation, Navigation)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestNavigation),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
import unittest
import Testing
import Zope2
Zope2.startup()
class TestPersistentUtil(unittest.TestCase):
def test_z3interfaces(self):
from App.interfaces import IPersistentExtra
from App.PersistentExtra import PersistentUtil
from zope.interface.verify import verifyClass
verifyClass(IPersistentExtra, PersistentUtil)
class TestPersistent(unittest.TestCase):
def test_z3interfaces(self):
from App.interfaces import IPersistentExtra
from Persistence import Persistent
from zope.interface.verify import verifyClass
verifyClass(IPersistentExtra, Persistent)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestPersistentUtil),
unittest.makeSuite(TestPersistent),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
import unittest
class TestUndoSupport(unittest.TestCase):
def test_z3interfaces(self):
from App.interfaces import IUndoSupport
from App.Undo import UndoSupport
from zope.interface.verify import verifyClass
verifyClass(IUndoSupport, UndoSupport)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestUndoSupport),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
This diff is collapsed.
import unittest
class TestApplication(unittest.TestCase):
def test_z3interfaces(self):
from OFS.interfaces import IApplication
from OFS.Application import Application
from zope.interface.verify import verifyClass
verifyClass(IApplication, Application, 1)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestApplication),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
import unittest
import Testing
import Zope2
Zope2.startup()
import cStringIO
from mimetools import Message
from multifile import MultiFile
......@@ -131,6 +135,16 @@ class TestCopySupport( CopySupportTestBase ):
self._cleanApp()
def test_z3interfaces(self):
from OFS.CopySupport import CopyContainer
from OFS.CopySupport import CopySource
from OFS.interfaces import ICopyContainer
from OFS.interfaces import ICopySource
from zope.interface.verify import verifyClass
verifyClass(ICopyContainer, CopyContainer, 1)
verifyClass(ICopySource, CopySource, 1)
def testRename( self ):
self.failUnless( 'file' in self.folder1.objectIds() )
self.folder1.manage_renameObject( id='file', new_id='filex' )
......@@ -518,8 +532,5 @@ def test_suite():
suite.addTest( unittest.makeSuite( TestCopySupportSecurity ) )
return suite
def main():
unittest.TextTestRunner().run(test_suite())
if __name__ == '__main__':
main()
unittest.main(defaultTest='test_suite')
import unittest
class TestFTPInterface(unittest.TestCase):
def test_z3interfaces(self):
from OFS.interfaces import IFTPAccess
from OFS.FTPInterface import FTPInterface
from zope.interface.verify import verifyClass
verifyClass(IFTPAccess, FTPInterface, 1)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestFTPInterface),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
import unittest
class TestFindSupport(unittest.TestCase):
def test_z3interfaces(self):
from OFS.interfaces import IFindSupport
from OFS.FindSupport import FindSupport
from zope.interface.verify import verifyClass
verifyClass(IFindSupport, FindSupport, 1)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestFindSupport),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
......@@ -10,6 +10,15 @@ class TestFolder(unittest.TestCase):
verifyClass(WriteLockInterface, Folder)
def test_z3interfaces(self):
from OFS.Folder import Folder
from OFS.interfaces import IFolder
from webdav.interfaces import IWriteLock
from zope.interface.verify import verifyClass
verifyClass(IFolder, Folder, 1)
verifyClass(IWriteLock, Folder, 1)
def test_suite():
return unittest.TestSuite((
......
......@@ -70,6 +70,13 @@ class ObjectManagerTests( unittest.TestCase ):
return self._getTargetClass()( *args, **kw ).__of__( FauxRoot() )
def test_z3interfaces(self):
from OFS.interfaces import IObjectManager
from OFS.ObjectManager import ObjectManager
from zope.interface.verify import verifyClass
verifyClass(IObjectManager, ObjectManager, 1)
def test_setObject_set_owner_with_no_user( self ):
om = self._makeOne()
......
import unittest
import Testing
import Zope2
Zope2.startup()
......@@ -44,6 +43,20 @@ class TestOrderSupport(unittest.TestCase):
f.o4 = DummyObject('o4', 'mt2')
return f
def test_z2interfaces(self):
from Interface.Verify import verifyClass
from OFS.IOrderSupport import IOrderedContainer
from OFS.OrderSupport import OrderSupport
verifyClass(IOrderedContainer, OrderSupport)
def test_z3interfaces(self):
from OFS.interfaces import IOrderedContainer
from OFS.OrderSupport import OrderSupport
from zope.interface.verify import verifyClass
verifyClass(IOrderedContainer, OrderSupport, 1)
def _doCanonTest(self, methodname, table):
for args, order, rval in table:
f = self._makeOne()
......@@ -160,13 +173,6 @@ class TestOrderSupport(unittest.TestCase):
f.setDefaultSorting('position', True)
self.failUnlessEqual( f.tpValues(), [f.o4, f.o3, f.o2] )
def test_z2interfaces(self):
from Interface.Verify import verifyClass
from OFS.IOrderSupport import IOrderedContainer
from OFS.OrderSupport import OrderSupport
verifyClass(IOrderedContainer, OrderSupport)
def test_suite():
return unittest.TestSuite((
......
......@@ -12,6 +12,17 @@ class TestOrderedFolder(unittest.TestCase):
verifyClass(IOrderedContainer, OrderedFolder)
verifyClass(WriteLockInterface, OrderedFolder)
def test_z3interfaces(self):
from OFS.interfaces import IOrderedContainer
from OFS.interfaces import IOrderedFolder
from OFS.OrderedFolder import OrderedFolder
from webdav.interfaces import IWriteLock
from zope.interface.verify import verifyClass
verifyClass(IOrderedContainer, OrderedFolder, 1)
verifyClass(IOrderedFolder, OrderedFolder, 1)
verifyClass(IWriteLock, OrderedFolder, 1)
def test_suite():
return unittest.TestSuite((
......
......@@ -12,20 +12,26 @@
#
##############################################################################
import os, sys, unittest
from OFS.PropertyManager import PropertyManager
from OFS.PropertySheets import PropertySheet
import unittest
class TestObject(PropertyManager):
pass
class TestPropertyManager(unittest.TestCase):
"""Property management tests."""
def _makeOne(self, *args, **kw):
from OFS.PropertyManager import PropertyManager
class TestProperties( unittest.TestCase ):
"""Property management tests."""
return PropertyManager(*args, **kw)
def test_z3interfaces(self):
from OFS.interfaces import IPropertyManager
from OFS.PropertyManager import PropertyManager
from zope.interface.verify import verifyClass
verifyClass(IPropertyManager, PropertyManager, 1)
def testLinesPropertyIsTuple( self ):
inst = TestObject()
inst = self._makeOne()
inst._setProperty('prop', ['xxx', 'yyy'], 'lines')
self.failUnless(type(inst.getProperty('prop')) == type(()))
......@@ -44,8 +50,16 @@ class TestProperties( unittest.TestCase ):
self.failUnless(type(inst.prop2) == type(()))
class TestPropertySheet(unittest.TestCase):
"""Property management tests."""
def _makeOne(self, *args, **kw):
from OFS.PropertySheets import PropertySheet
return PropertySheet(*args, **kw)
def testPropertySheetLinesPropertyIsTuple(self):
inst = PropertySheet('foo')
inst = self._makeOne('foo')
inst._setProperty('prop', ['xxx', 'yyy'], 'lines')
self.failUnless(type(inst.getProperty('prop')) == type(()))
......@@ -60,14 +74,11 @@ class TestProperties( unittest.TestCase ):
self.failUnless(type(inst.prop2) == type(()))
def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestProperties ) )
return suite
def main():
unittest.main(defaultTest='test_suite')
return unittest.TestSuite((
unittest.makeSuite(TestPropertyManager),
unittest.makeSuite(TestPropertySheet),
))
if __name__ == '__main__':
main()
unittest.main(defaultTest='test_suite')
import unittest
class TestItem(unittest.TestCase):
def test_z3interfaces(self):
from OFS.interfaces import IItem
from OFS.interfaces import IManageable
from OFS.SimpleItem import Item
from zope.interface.verify import verifyClass
verifyClass(IItem, Item, 1)
verifyClass(IManageable, Item, 1)
class TestItem_w__name__(unittest.TestCase):
def test_z3interfaces(self):
from OFS.interfaces import IItemWithName
from OFS.SimpleItem import Item_w__name__
from zope.interface.verify import verifyClass
verifyClass(IItemWithName, Item_w__name__, 1)
class TestSimpleItem(unittest.TestCase):
def test_z3interfaces(self):
from OFS.interfaces import ISimpleItem
from OFS.SimpleItem import SimpleItem
from zope.interface.verify import verifyClass
verifyClass(ISimpleItem, SimpleItem, 1)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestItem),
unittest.makeSuite(TestItem_w__name__),
unittest.makeSuite(TestSimpleItem),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
......@@ -163,6 +163,13 @@ class TestTraverse( unittest.TestCase ):
del self.root
del self.connection
def test_z3interfaces(self):
from OFS.interfaces import ITraversable
from OFS.Traversable import Traversable
from zope.interface.verify import verifyClass
verifyClass(ITraversable, Traversable, 1)
def testTraversePath( self ):
self.failUnless( 'file' in self.folder1.objectIds() )
self.failUnless(
......@@ -269,8 +276,5 @@ def test_suite():
suite.addTest( unittest.makeSuite( TestTraverse ) )
return suite
def main():
unittest.main(defaultTest='test_suite')
if __name__ == '__main__':
main()
unittest.main(defaultTest='test_suite')
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""webdav z3 interfaces.
$Id$
"""
from zope.interface import Interface
from zope.schema import Bool, Tuple
# create IWriteLock
from Products.Five.fiveconfigure import createZope2Bridge
from webdav.WriteLockInterface import WriteLockInterface
import interfaces
createZope2Bridge(WriteLockInterface, interfaces, 'IWriteLock')
del createZope2Bridge
del WriteLockInterface
del interfaces
# XXX: might contain non-API methods and outdated comments;
# not synced with ZopeBook API Reference;
# based on webdav.Resource.Resource
class IDAVResource(IWriteLock):
"""Provide basic WebDAV support for non-collection objects."""
__dav_resource__ = Bool(
title=u"Is DAV resource"
)
__http_methods__ = Tuple(
title=u"HTTP methods",
description=u"Sequence of valid HTTP methods"
)
def dav__init(request, response):
"""Init expected HTTP 1.1 / WebDAV headers which are not
currently set by the base response object automagically.
Also, we sniff for a ZServer response object, because we don't
want to write duplicate headers (since ZS writes Date
and Connection itself).
"""
def dav__validate(object, methodname, REQUEST):
"""
"""
def dav__simpleifhandler(request, response, method='PUT',
col=0, url=None, refresh=0):
"""
"""
def HEAD(REQUEST, RESPONSE):
"""Retrieve resource information without a response body."""
def PUT(REQUEST, RESPONSE):
"""Replace the GET response entity of an existing resource.
Because this is often object-dependent, objects which handle
PUT should override the default PUT implementation with an
object-specific implementation. By default, PUT requests
fail with a 405 (Method Not Allowed)."""
def OPTIONS(REQUEST, RESPONSE):
"""Retrieve communication options."""
def TRACE(REQUEST, RESPONSE):
"""Return the HTTP message received back to the client as the
entity-body of a 200 (OK) response. This will often usually
be intercepted by the web server in use. If not, the TRACE
request will fail with a 405 (Method Not Allowed), since it
is not often possible to reproduce the HTTP request verbatim
from within the Zope environment."""
def DELETE(REQUEST, RESPONSE):
"""Delete a resource. For non-collection resources, DELETE may
return either 200 or 204 (No Content) to indicate success."""
def PROPFIND(REQUEST, RESPONSE):
"""Retrieve properties defined on the resource."""
def PROPPATCH(REQUEST, RESPONSE):
"""Set and/or remove properties defined on the resource."""
def MKCOL(REQUEST, RESPONSE):
"""Create a new collection resource. If called on an existing
resource, MKCOL must fail with 405 (Method Not Allowed)."""
def COPY(REQUEST, RESPONSE):
"""Create a duplicate of the source resource whose state
and behavior match that of the source resource as closely
as possible. Though we may later try to make a copy appear
seamless across namespaces (e.g. from Zope to Apache), COPY
is currently only supported within the Zope namespace."""
def MOVE(REQUEST, RESPONSE):
"""Move a resource to a new location. Though we may later try to
make a move appear seamless across namespaces (e.g. from Zope
to Apache), MOVE is currently only supported within the Zope
namespace."""
def LOCK(REQUEST, RESPONSE):
"""Lock a resource"""
def UNLOCK(REQUEST, RESPONSE):
"""Remove an existing lock on a resource."""
def manage_DAVget():
"""Gets the document source"""
def listDAVObjects():
"""
"""
# XXX: might contain non-API methods and outdated comments;
# not synced with ZopeBook API Reference;
# based on webdav.Collection.Collection
class IDAVCollection(IDAVResource):
"""The Collection class provides basic WebDAV support for
collection objects. It provides default implementations
for all supported WebDAV HTTP methods. The behaviors of some
WebDAV HTTP methods for collections are slightly different
than those for non-collection resources."""
__dav_collection__ = Bool(
title=u"Is a DAV collection",
description=u"Should be true",
)
def PUT(REQUEST, RESPONSE):
"""The PUT method has no inherent meaning for collection
resources, though collections are not specifically forbidden
to handle PUT requests. The default response to a PUT request
for collections is 405 (Method Not Allowed)."""
def DELETE(REQUEST, RESPONSE):
"""Delete a collection resource. For collection resources, DELETE
may return either 200 (OK) or 204 (No Content) to indicate total
success, or may return 207 (Multistatus) to indicate partial
success. Note that in Zope a DELETE currently never returns 207."""
import unittest
import Testing
import Zope2
Zope2.startup()
class TestCollection(unittest.TestCase):
def test_z3interfaces(self):
from webdav.Collection import Collection
from webdav.interfaces import IDAVCollection
from zope.interface.verify import verifyClass
verifyClass(IDAVCollection, Collection, 1)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestCollection),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
import unittest
import Testing
import Zope2
Zope2.startup()
class TestLockNullResource(unittest.TestCase):
......@@ -10,6 +13,13 @@ class TestLockNullResource(unittest.TestCase):
verifyClass(WriteLockInterface, LockNullResource)
def test_z3interfaces(self):
from webdav.interfaces import IWriteLock
from webdav.NullResource import LockNullResource
from zope.interface.verify import verifyClass
verifyClass(IWriteLock, LockNullResource, 1)
class TestNullResource(unittest.TestCase):
......@@ -20,6 +30,13 @@ class TestNullResource(unittest.TestCase):
verifyClass(WriteLockInterface, NullResource)
def test_z3interfaces(self):
from webdav.interfaces import IWriteLock
from webdav.NullResource import NullResource
from zope.interface.verify import verifyClass
verifyClass(IWriteLock, NullResource, 1)
def test_suite():
return unittest.TestSuite((
......
import unittest
import Testing
import Zope2
Zope2.startup()
class TestResource(unittest.TestCase):
def test_z3interfaces(self):
from webdav.interfaces import IDAVResource
from webdav.Resource import Resource
from zope.interface.verify import verifyClass
verifyClass(IDAVResource, Resource, 1)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestResource),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment