[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/tests - testPublisher.py:1.1.2.5
Martijn Pieters
mj@zope.com
Wed, 28 Nov 2001 11:27:22 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/tests
In directory cvs.zope.org:/tmp/cvs-serv28657/lib/python/Zope/Publisher/tests
Modified Files:
Tag: Zope-3x-branch
testPublisher.py
Log Message:
Add exception tests.
=== Zope3/lib/python/Zope/Publisher/tests/testPublisher.py 1.1.2.4 => 1.1.2.5 ===
from Zope.Publisher.BaseResponse import BaseResponse
from Zope.Publisher.DefaultPublication import DefaultPublication
-from Zope.Publisher.Exceptions import Retry
+from Zope.Publisher.Exceptions import Retry, Unauthorized, NotFound, DebugError
from Zope.Publisher.IPublication import IPublication
from Interface import verify, 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):
@@ -34,12 +38,19 @@
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):
- publication = DefaultPublication(self.app)
+ publication = TestPublication(self.app)
outstream = StringIO()
response = BaseResponse(outstream)
instream = StringIO("")
@@ -70,6 +81,15 @@
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()