[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/tests - BaseTestIApplicationRequest.py:1.2 BaseTestIPublicationRequest.py:1.2 BaseTestIPublisherRequest.py:1.2 TestPublication.py:1.2 __init__.py:1.2 testBaseRequest.py:1.2 testIPublication.py:1.2 testMapply.py:1.2 testPublisher.py:1.2 testRequestDataProperty.py:1.2
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 19:30:06 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/tests
In directory cvs.zope.org:/tmp/cvs-serv20468/lib/python/Zope/Publisher/tests
Added Files:
BaseTestIApplicationRequest.py BaseTestIPublicationRequest.py
BaseTestIPublisherRequest.py TestPublication.py __init__.py
testBaseRequest.py testIPublication.py testMapply.py
testPublisher.py testRequestDataProperty.py
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.
=== Zope3/lib/python/Zope/Publisher/tests/BaseTestIApplicationRequest.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+import sys
+from Interface.Verify import verifyObject
+from Zope.Publisher.IApplicationRequest import IApplicationRequest
+
+from Interface.Common.tests.BaseTestMapping import BaseTestIEnumerableMapping
+
+from Interface.Common.tests.BaseTestMapping \
+ import testIEnumerableMapping, testIReadMapping
+
+class BaseTestIApplicationRequest(BaseTestIEnumerableMapping):
+
+
+ def testVerifyIApplicationRequest(self):
+ verifyObject(IApplicationRequest, self._Test__new())
+
+ def testHaveCustomTestsForIApplicationRequest(self):
+ "Make sure that tests are defined for things we can't test here"
+ self.test_IApplicationRequest_body
+
+ def testEnvironment(self):
+
+ request = self._Test__new(foo='Foo', bar='Bar')
+
+ try: request.environment = {}
+ except AttributeError: pass
+ else: raise "Shouldn't be able to set environment"
+
+ environment = request.environment
+
+ testIReadMapping(self, environment,
+ {'foo': 'Foo', 'bar': 'Bar'},
+ ['splat'])
+
=== Zope3/lib/python/Zope/Publisher/tests/BaseTestIPublicationRequest.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+import sys
+from Interface.Verify import verifyObject
+from Zope.Publisher.IPublicationRequest import IPublicationRequest
+
+class BaseTestIPublicationRequest:
+
+
+ def testVerifyIPublicationRequest(self):
+ verifyObject(IPublicationRequest, self._Test__new())
+
+ def testHaveCustomTestsForIPublicationRequest(self):
+ "Make sure that tests are defined for things we can't test here"
+ self.test_IPublicationRequest_getPositionalArguments
+
+ def testTraversalStack(self):
+ request = self._Test__new()
+ stack = ['Engineering', 'ZopeCorp']
+ request.setTraversalStack(stack)
+ self.assertEqual(list(request.getTraversalStack()), stack)
+
+ def testHoldCloseAndGetResponse(self):
+ request = self._Test__new()
+
+ response = request.getResponse()
+ rcresponse = sys.getrefcount(response)
+
+ resource = object()
+ rcresource = sys.getrefcount(resource)
+
+ request.hold(resource)
+
+ self.failUnless(sys.getrefcount(resource) > rcresource)
+
+ request.close()
+ self.failUnless(sys.getrefcount(response) < rcresponse)
+ self.assertEqual(sys.getrefcount(resource), rcresource)
+
+ def testSkinManagement(self):
+ request = self._Test__new()
+ self.assertEqual(request.getPresentationSkin(), '')
+ skin = 'terse'
+ request.setViewSkin(skin)
+ self.assertEqual(request.getPresentationSkin(), skin)
+
+ def test_getPresentationType(self):
+ type = self._Test__expectedViewType()
+ request = self._Test__new()
+ self.assertEqual(request.getPresentationType(), type)
+
=== Zope3/lib/python/Zope/Publisher/tests/BaseTestIPublisherRequest.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+import sys
+from Interface.Verify import verifyObject
+from Zope.Publisher.IPublisherRequest import IPublisherRequest
+
+class BaseTestIPublisherRequest:
+
+ def testVerifyIPublisherRequest(self):
+ verifyObject(IPublisherRequest, self._Test__new())
+
+ def testHaveCustomTestsForIPublisherRequest(self):
+ "Make sure that tests are defined for things we can't test here"
+ self.test_IPublisherRequest_retry
+ self.test_IPublisherRequest_traverse
+ self.test_IPublisherRequest_processInputs
+
+ def testPublicationManagement(self):
+ from TestPublication import TestPublication
+
+ request = self._Test__new()
+ publication = TestPublication()
+ request.setPublication(publication)
+ self.assertEqual(id(request.getPublication()), id(publication))
+
=== Zope3/lib/python/Zope/Publisher/tests/TestPublication.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+
+from Zope.Publisher.IPublication import IPublication
+
+class TestPublication:
+
+ __implements__ = IPublication
+
+ ############################################################
+ # Implementation methods for interface
+ # Zope.Publisher.IPublication.
+
+ def afterCall(self, request):
+ '''See interface IPublication'''
+ self._afterCall = getattr(self, '_afterCall', 0) + 1
+
+ def traverseName(self, request, ob, name, check_auth=1):
+ '''See interface IPublication'''
+ return getattr(ob, name, "%s value" % name)
+
+ def afterTraversal(self, request, ob):
+ '''See interface IPublication'''
+ self._afterTraversal = getattr(self, '_afterTraversal', 0) + 1
+
+ def beforeTraversal(self, request):
+ '''See interface IPublication'''
+ self._beforeTraversal = getattr(self, '_beforeTraversal', 0) + 1
+
+ def callObject(self, request, ob):
+ '''See interface IPublication'''
+ return ob(request)
+
+ def getApplication(self, request):
+ '''See interface IPublication'''
+ return app
+
+ def handleException(self, request, exc_info, retry_allowed=1):
+ '''See interface IPublication'''
+ try:
+ request.getResponse().setBody("%s: %s" % (exc_info[:2]))
+ finally:
+ exc_info = 0
+
+
+ def callTraversalHooks(self, request, ob):
+ '''See interface IPublication'''
+ self._callTraversalHooks = getattr(self, '_callTraversalHooks', 0) + 1
+
+ #
+ ############################################################
+
+class App:
+
+ def __init__(self, name):
+ self.name = name
+
+ def index_html(self, request):
+ return self
+
+app = App('')
+app.ZopeCorp = App('ZopeCorp')
+app.ZopeCorp.Engineering = App('Engineering')
+
=== Zope3/lib/python/Zope/Publisher/tests/__init__.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+""" Zope.Publisher unit tests. """
=== Zope3/lib/python/Zope/Publisher/tests/testBaseRequest.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+
+from Zope.Publisher.tests.BaseTestIPublicationRequest \
+ import BaseTestIPublicationRequest
+
+from Zope.Publisher.tests.BaseTestIPublisherRequest \
+ import BaseTestIPublisherRequest
+
+from Zope.Publisher.tests.BaseTestIApplicationRequest \
+ import BaseTestIApplicationRequest
+
+from StringIO import StringIO
+
+class TestBaseRequest(BaseTestIPublicationRequest,
+ BaseTestIApplicationRequest,
+ BaseTestIPublisherRequest,
+ TestCase):
+
+ def _Test__new(self, **kw):
+ from Zope.Publisher.BaseRequest import BaseRequest
+ return BaseRequest(StringIO(''), StringIO(), kw)
+
+ def _Test__expectedViewType(self):
+ return None # we don't expect
+
+ def test_IApplicationRequest_body(self):
+ from Zope.Publisher.BaseRequest import BaseRequest
+
+ request = BaseRequest(StringIO('spam'), StringIO(), {})
+ self.assertEqual(request.getBody(), 'spam')
+
+ request = BaseRequest(StringIO('spam'), StringIO(), {})
+ self.assertEqual(request.getBodyFile().read(), 'spam')
+
+ def test_IPublicationRequest_getPositionalArguments(self):
+ self.assertEqual(self._Test__new().getPositionalArguments(), ())
+
+ def test_IPublisherRequest_retry(self):
+ self.assertEqual(self._Test__new().supportsRetry(), 0)
+
+ def test_IPublisherRequest_traverse(self):
+ from Zope.Publisher.tests.TestPublication import TestPublication
+ request = self._Test__new()
+ request.setPublication(TestPublication())
+ app = request.getPublication().getApplication(request)
+
+ request.setTraversalStack([])
+ self.assertEqual(request.traverse(app).name, '')
+ request.setTraversalStack(['ZopeCorp'])
+ self.assertEqual(request.traverse(app).name, 'ZopeCorp')
+ request.setTraversalStack(['Engineering', 'ZopeCorp'])
+ self.assertEqual(request.traverse(app).name, 'Engineering')
+
+ def test_IPublisherRequest_processInputs(self):
+ self._Test__new().processInputs()
+
+
+ # Needed by BaseTestIEnumerableMapping tests:
+ def _IEnumerableMapping__stateDict(self):
+ return {'id': 'ZopeOrg', 'title': 'Zope Community Web Site',
+ 'greet': 'Welcome to the Zope Community Web site'}
+
+ def _IEnumerableMapping__sample(self):
+ return self._Test__new(**(self._IEnumerableMapping__stateDict()))
+
+ def _IEnumerableMapping__absentKeys(self):
+ return 'foo', 'bar'
+
+
+def test_suite():
+ return TestSuite((
+ makeSuite(TestBaseRequest),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
+
+
=== Zope3/lib/python/Zope/Publisher/tests/testIPublication.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+import sys
+from unittest import TestCase, TestSuite, main, makeSuite
+from StringIO import StringIO
+from Interface.Verify import verifyObject
+
+from Zope.Publisher.IPublication import IPublication
+
+class BaseIPublicationTest:
+
+ # This test isn't as interesting as we'd like it to be because we
+ # know too little about the semantics if a particular publication
+ # object.
+
+ def testVerifyIPublication(self):
+ verifyObject(IPublication, self._Test__new())
+
+ def setUp(self):
+ self._request = request = self._Test__request()
+ self._publication = request.getPublication()
+
+ def testgetApplication(self):
+ self._publication.getApplication(self._request)
+
+
+class Test(BaseIPublicationTest, TestCase):
+
+ def _Test__new(self):
+ from Zope.Publisher.tests.TestPublication import TestPublication
+ return TestPublication()
+
+ def _Test__request(self):
+ from Zope.Publisher.BaseRequest import BaseRequest
+ request = BaseRequest(StringIO(''), StringIO(), {})
+ request.setTraversalStack(['Engineering', 'ZopeCorp'])
+ publication = self._Test__new()
+ request.setPublication(publication)
+
+ return request
+
+ # The following are specific to our particular stub, but might be
+ # good examples of tests for other implementations.
+
+ def test_afterCall(self):
+ self._publication.afterCall(self._request)
+ self.assertEqual(self._publication._afterCall, 1)
+
+ def test_traverseName(self):
+ ob = self._publication.getApplication(self._request)
+ ob = self._publication.traverseName(self._request, ob, 'ZopeCorp')
+ self.assertEqual(ob.name, 'ZopeCorp')
+ ob = self._publication.traverseName(self._request, ob, 'Engineering')
+ self.assertEqual(ob.name, 'Engineering')
+
+ def test_afterTraversal(self):
+ self._publication.afterTraversal(self._request, None)
+ self.assertEqual(self._publication._afterTraversal, 1)
+
+ def test_beforeTraversal(self):
+ self._publication.beforeTraversal(self._request)
+ self.assertEqual(self._publication._beforeTraversal, 1)
+
+ def test_callObject(self):
+ result = self._publication.callObject(
+ self._request, lambda request: 42)
+ self.assertEqual(result, 42)
+
+ def test_getApplication(self):
+ from Zope.Publisher.tests.TestPublication import app
+ result = self._publication.getApplication(self._request)
+ self.assertEqual(id(result), id(app))
+
+ def test_handleException(self):
+ try:
+ raise ValueError, 1
+ except:
+ exc_info = sys.exc_info()
+
+ try:
+ self._publication.handleException(self._request, exc_info)
+ finally:
+ exc_info = 0
+
+ def test_callTraversalHooks(self):
+ self._publication.callTraversalHooks(self._request, None)
+ self.assertEqual(self._publication._callTraversalHooks, 1)
+
+def test_suite():
+ return TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
=== Zope3/lib/python/Zope/Publisher/tests/testMapply.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+import unittest
+
+from Zope.Publisher.mapply import mapply
+
+class MapplyTests(unittest.TestCase):
+ def testMethod(self):
+ def compute(a,b,c=4):
+ return '%d%d%d' % (a, b, c)
+ values = {'a':2, 'b':3, 'c':5}
+ v = mapply(compute, (), values)
+ self.failUnlessEqual(v, '235')
+
+ v = mapply(compute, (7,), values)
+ self.failUnlessEqual(v, '735')
+
+ def testClass(self):
+ values = {'a':2, 'b':3, 'c':5}
+ class c:
+ a = 3
+ def __call__(self, b, c=4):
+ return '%d%d%d' % (self.a, b, c)
+ compute = __call__
+ cc = c()
+ v = mapply(cc, (), values)
+ self.failUnlessEqual(v, '335')
+
+ del values['c']
+ v = mapply(cc.compute, (), values)
+ self.failUnlessEqual(v, '334')
+
+ class c2: pass
+ c2inst = c2()
+ c2inst.__call__ = cc
+ v = mapply(c2inst, (), values)
+ self.failUnlessEqual(v, '334')
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase(MapplyTests)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/Publisher/tests/testPublisher.py 1.1 => 1.2 ===
+#
+# 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest
+
+from Zope.Publisher.Publish import publish
+from Zope.Publisher.BaseRequest import BaseRequest
+from Zope.Publisher.DefaultPublication import DefaultPublication
+from Zope.Publisher.Exceptions import Retry, Unauthorized, NotFound, DebugError
+from Zope.Publisher.IPublication import IPublication
+
+from Interface.Verify import verifyClass
+from Interface.Implements import instancesOfObjectImplements
+
+from StringIO import StringIO
+
+class TestPublication(DefaultPublication):
+ # Override handleException to reraise for testing purposes
+ def handleException(self, request, exc_info, retry_allowed=1):
+ raise exc_info[0], exc_info[1], exc_info[2]
+
+class PublisherTests(unittest.TestCase):
+ def setUp(self):
+ class AppRoot:
+ " "
+
+ class Folder:
+ " "
+
+ class Item:
+ " "
+ def __call__(self):
+ return "item"
+
+ class NoDocstringItem:
+ def __call__(self):
+ return "Yo! No docstring!"
+
+ self.app = AppRoot()
+ self.app.folder = Folder()
+ self.app.folder.item = Item()
+
+ self.app._item = Item()
+ self.app.noDocString = NoDocstringItem()
+
+ def _createRequest(self, path, outstream=None, **kw):
+ if outstream is None:
+ outstream = StringIO()
+ publication = TestPublication(self.app)
+ path = path.split('/')
+ path.reverse()
+ request = BaseRequest(StringIO(''), outstream, kw)
+ request.setTraversalStack(path)
+ request.setPublication(publication)
+ return request
+
+ def _publisherResults(self, path, **kw):
+ outstream = StringIO()
+ request = self._createRequest(path, outstream=outstream, **kw)
+ publish(request)
+ return outstream.getvalue()
+
+ def testImplementsIPublication(self):
+ self.failUnless(IPublication.isImplementedBy(
+ DefaultPublication(self.app)))
+
+ def testInterfacesVerify(self):
+ for interface in instancesOfObjectImplements(DefaultPublication):
+ verifyClass(interface, DefaultPublication)
+
+ def testTraversalToItem(self):
+ res = self._publisherResults('/folder/item')
+ self.failUnlessEqual(res, 'item')
+ res = self._publisherResults('/folder/item/')
+ self.failUnlessEqual(res, 'item')
+ res = self._publisherResults('folder/item')
+ self.failUnlessEqual(res, 'item')
+
+ def testUnderscoreUnauthorizedException(self):
+ self.assertRaises(Unauthorized, self._publisherResults, '/_item')
+
+ def testNotFoundException(self):
+ self.assertRaises(NotFound, self._publisherResults, '/foo')
+
+ def testDebugError(self):
+ self.assertRaises(DebugError, self._publisherResults, '/noDocString')
+
+def test_suite():
+ loader = unittest.TestLoader()
+ return loader.loadTestsFromTestCase(PublisherTests)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run( test_suite() )
=== Zope3/lib/python/Zope/Publisher/tests/testRequestDataProperty.py 1.1 => 1.2 ===
+#
+# 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$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+
+from Interface.Common.tests.BaseTestMapping \
+ import testIEnumerableMapping, testIReadMapping
+
+from Zope.Publisher.RequestDataProperty \
+ import RequestDataProperty, RequestDataGetter, RequestDataMapper
+
+class TestDataGettr(RequestDataGetter): _gettrname = 'getSomething'
+class TestDataMapper(RequestDataMapper): _mapname = '_data'
+
+_marker = object()
+class Data(object):
+
+ def getSomething(self, name, default=_marker):
+ if name.startswith('Z'):
+ return "something %s" % name
+
+ if default is not _marker:
+ return default
+
+ raise KeyError, name
+
+ something = RequestDataProperty(TestDataGettr)
+ somedata = RequestDataProperty(TestDataMapper)
+
+class Test(TestCase):
+
+ def testRequestDataGettr(self):
+ testIReadMapping(self, Data().something,
+ {"Zope": "something Zope"}, ["spam"])
+
+ def testRequestDataMapper(self):
+ data = Data()
+ sample = {'foo': 'Foo', 'bar': 'Bar'}
+ data._data = sample
+ inst = data.somedata
+ testIReadMapping(self, inst, sample, ["spam"])
+ testIEnumerableMapping(self, inst, sample)
+
+ def testNoAssign(self):
+ data = Data()
+ try: data.something = {}
+ except AttributeError: pass
+ else: raise """Shouldn't be able to assign"""
+ try: data.somedata = {}
+ except AttributeError: pass
+ else: raise """Shouldn't be able to assign"""
+
+
+def test_suite():
+ return TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')