[Zope3-checkins] CVS: Zope3/src/zope/app/container/tests - placelesssetup.py:1.1 test_zopecontainer.py:1.1

Steve Alexander steve@cat-box.net
Wed, 4 Jun 2003 10:57:58 -0400


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

Added Files:
	placelesssetup.py test_zopecontainer.py 
Log Message:
Installed and registered ZopeContainerDecorator.
For new code, it is now unnecessary to adapt a context-wrapped container
to ZopeContainerAdapter. The context-wrapper will do all the correct
wrapping and unwrapping, and will send the correct events.

Existing calls to getAdapter(container, IZopeContainer) are harmless, as
a context-wrapped container provides IZopeContainer. So, the getAdapter
call will simply return the already-wrapped container.
I'll be changing existing code to avoid using ZopeContainerAdapter.



=== Added File Zope3/src/zope/app/container/tests/placelesssetup.py ===
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
"""Unit test logic for setting up and tearing down basic infrastructure

$Id: placelesssetup.py,v 1.1 2003/06/04 14:57:57 stevea Exp $
"""
from zope.component.adapter import provideAdapter
from zope.app.container.zopecontainer import ZopeContainerDecorator
from zope.app.container.zopecontainer import ZopeContainerAdapter
from zope.app.interfaces.context import IZopeContextWrapper
from zope.app.interfaces.container import IContainer, IZopeContainer

class PlacelessSetup:

    def setUp(self):
        provideAdapter(
            IContainer, IZopeContextWrapper, ZopeContainerDecorator)
        provideAdapter(
            IContainer, IZopeContainer, ZopeContainerAdapter)


=== Added File Zope3/src/zope/app/container/tests/test_zopecontainer.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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: test_zopecontainer.py,v 1.1 2003/06/04 14:57:57 stevea Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.interfaces.container import IAddNotifiable
from zope.app.interfaces.container import IDeleteNotifiable
from zope.app.container.tests.baseizopeitemcontainer import \
     BaseTestIZopeSimpleReadContainer, BaseTestIZopeReadContainer,\
     BaseTestIZopeWriteContainer
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.interface import implements

class C:
    pass

class H:
    implements(IAddNotifiable, IDeleteNotifiable)
    notified = 0
    def beforeDeleteHook(self, object, container):
        self.notified -= 1
    def afterAddHook(self, object, container):
        self.notified += 1

class Test(PlacelessSetup,
           BaseTestIZopeSimpleReadContainer,
           BaseTestIZopeReadContainer,
           BaseTestIZopeWriteContainer,
           TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        from zope.app.container.sample import SampleContainer
        self.__container = SampleContainer()

    def _sampleMapping(self):
        from zope.app.container.zopecontainer import ZopeContainerDecorator
        container = self.__container
        for k, v in self._sampleDict().items():
            container.setObject(k, v)
        return ZopeContainerDecorator(container)

    def _sampleContainer(self):
        return self.__container

    __sample = {'Z': C(), 'O': C(),'P': C()}
    def _sampleDict(self):
        return self.__sample


    def _absentKeys(self):
        return 'zc', 'ny'

    __newItem = {'A': C(), 'B':C()}
    def _sample_newItem(self):
        return self.__newItem

    __newItemHooked = {'B': H(), 'E':H()}
    def _sample_newItemHooked(self):
        return self.__newItemHooked


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

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