[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/tests - BaseTestIApplicationRequest.py:1.1.4.1 BaseTestIPublicationRequest.py:1.1.4.1 BaseTestIPublisherRequest.py:1.1.4.1 TestPublication.py:1.1.4.1 testBaseRequest.py:1.1.4.1 testIPublication.py:1.1.4.1 testRequestDataProperty.py:1.1.4.1 testPublisher.py:1.1.2.8
Jim Fulton
jim@zope.com
Tue, 26 Mar 2002 16:26:01 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/tests
In directory cvs.zope.org:/tmp/cvs-serv7731/Zope/Publisher/tests
Modified Files:
Tag: Zope-3x-branch
testPublisher.py
Added Files:
Tag: Zope-3x-branch
BaseTestIApplicationRequest.py BaseTestIPublicationRequest.py
BaseTestIPublisherRequest.py TestPublication.py
testBaseRequest.py testIPublication.py
testRequestDataProperty.py
Log Message:
Merged the publication refactoring branch into the main branch.
Also renamed:
browser_reaverse -> publishTraverse
browser_default -> browserDefault
=== Added File Zope3/lib/python/Zope/Publisher/tests/BaseTestIApplicationRequest.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: BaseTestIApplicationRequest.py,v 1.1.4.1 2002/03/26 21:25:59 jim Exp $
"""
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'])
=== Added File Zope3/lib/python/Zope/Publisher/tests/BaseTestIPublicationRequest.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: BaseTestIPublicationRequest.py,v 1.1.4.1 2002/03/26 21:25:59 jim Exp $
"""
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.getViewSkin(), '')
skin = 'terse'
request.setViewSkin(skin)
self.assertEqual(request.getViewSkin(), skin)
def test_getViewType(self):
type = self._Test__expectedViewType()
request = self._Test__new()
self.assertEqual(request.getViewType(), type)
=== Added File Zope3/lib/python/Zope/Publisher/tests/BaseTestIPublisherRequest.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: BaseTestIPublisherRequest.py,v 1.1.4.1 2002/03/26 21:25:59 jim Exp $
"""
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))
=== Added File Zope3/lib/python/Zope/Publisher/tests/TestPublication.py ===
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')
=== Added File Zope3/lib/python/Zope/Publisher/tests/testBaseRequest.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: testBaseRequest.py,v 1.1.4.1 2002/03/26 21:25:59 jim Exp $
"""
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')
=== Added File Zope3/lib/python/Zope/Publisher/tests/testIPublication.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: testIPublication.py,v 1.1.4.1 2002/03/26 21:25:59 jim Exp $
"""
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')
=== Added File Zope3/lib/python/Zope/Publisher/tests/testRequestDataProperty.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: testRequestDataProperty.py,v 1.1.4.1 2002/03/26 21:25:59 jim Exp $
"""
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')
=== Zope3/lib/python/Zope/Publisher/tests/testPublisher.py 1.1.2.7 => 1.1.2.8 ===
from Zope.Publisher.Publish import publish
from Zope.Publisher.BaseRequest import BaseRequest
-from Zope.Publisher.BaseResponse import BaseResponse
from Zope.Publisher.DefaultPublication import DefaultPublication
from Zope.Publisher.Exceptions import Retry, Unauthorized, NotFound, DebugError
from Zope.Publisher.IPublication import IPublication
@@ -57,19 +56,22 @@
self.app._item = Item()
self.app.noDocString = NoDocstringItem()
- def _createRequest(self, path):
+ def _createRequest(self, path, outstream=None, **kw):
+ if outstream is None:
+ outstream = StringIO()
publication = TestPublication(self.app)
- outstream = StringIO()
- response = BaseResponse(outstream)
- instream = StringIO("")
- request = BaseRequest(response, instream, publication)
- request.other['PATH_INFO'] = path
+ path = path.split('/')
+ path.reverse()
+ request = BaseRequest(StringIO(''), outstream, kw)
+ request.setTraversalStack(path)
+ request.setPublication(publication)
return request
- def _publisherResults(self, path):
- request = self._createRequest(path)
+ def _publisherResults(self, path, **kw):
+ outstream = StringIO()
+ request = self._createRequest(path, outstream=outstream, **kw)
publish(request)
- return request.response.outstream.getvalue()
+ return outstream.getvalue()
def testImplementsIPublication(self):
self.failUnless(IPublication.isImplementedBy(
@@ -83,10 +85,6 @@
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')
- res = self._publisherResults('/folder/../folder/item/../item')
self.failUnlessEqual(res, 'item')
res = self._publisherResults('folder/item')
self.failUnlessEqual(res, 'item')