[Checkins] SVN: zope.app.testing/trunk/s fix of 599 error on
conflict error in request
Adam Groszer
agroszer at gmail.com
Fri Feb 1 08:26:01 EST 2008
Log message for revision 83372:
fix of 599 error on conflict error in request
see: http://mail.zope.org/pipermail/zope-dev/2008-January/030844.html
Changed:
U zope.app.testing/trunk/setup.py
U zope.app.testing/trunk/src/zope/app/testing/ftesting.zcml
U zope.app.testing/trunk/src/zope/app/testing/functional.py
U zope.app.testing/trunk/src/zope/app/testing/testing.py
U zope.app.testing/trunk/src/zope/app/testing/tests.py
-=-
Modified: zope.app.testing/trunk/setup.py
===================================================================
--- zope.app.testing/trunk/setup.py 2008-02-01 11:30:53 UTC (rev 83371)
+++ zope.app.testing/trunk/setup.py 2008-02-01 13:26:00 UTC (rev 83372)
@@ -56,7 +56,9 @@
namespace_packages=['zope', 'zope.app'],
extras_require=dict(test=['zope.app.zptpage',
'zope.app.securitypolicy',
- 'zope.app.zcmlfiles'
+ 'zope.app.zcmlfiles',
+ 'ZODB3',
+ 'zope.publisher'
]),
install_requires=['setuptools',
'zope.annotation',
Modified: zope.app.testing/trunk/src/zope/app/testing/ftesting.zcml
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/ftesting.zcml 2008-02-01 11:30:53 UTC (rev 83371)
+++ zope.app.testing/trunk/src/zope/app/testing/ftesting.zcml 2008-02-01 13:26:00 UTC (rev 83372)
@@ -52,5 +52,9 @@
<grant role="zope.Manager" principal="zope.globalmgr" />
+ <adapter
+ factory="zope.app.testing.testing.ConflictRaisingView"
+ name="test-conflict-raise-view.html" />
+
</configure>
Modified: zope.app.testing/trunk/src/zope/app/testing/functional.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/functional.py 2008-02-01 11:30:53 UTC (rev 83371)
+++ zope.app.testing/trunk/src/zope/app/testing/functional.py 2008-02-01 13:26:00 UTC (rev 83372)
@@ -320,7 +320,7 @@
# let's hope that the file is in our CWD. If not, we'll get an
# error anyways, but we can't just throw an error if we don't find
# that file. This module might be imported for other things as
- # well, not only starting up Zope from ftesting.zcml.
+ # well, not only starting up Zope from ftesting.zcml.
Functional = 'ftesting.zcml'
FunctionalNoDevMode = 'ftesting-base.zcml'
@@ -378,7 +378,7 @@
"""Save cookies from the response."""
# Urgh - need to play with the response's privates to extract
# cookies that have been set
- # TODO: extend the IHTTPRequest interface to allow access to all
+ # TODO: extend the IHTTPRequest interface to allow access to all
# cookies
# TODO: handle cookie expirations
for k,v in response._cookies.items():
@@ -449,10 +449,13 @@
del env['HTTP_COOKIE'] # Added again in makeRequest
request = self.makeRequest(path, basic=basic, form=form, env=env)
- response = ResponseWrapper(request.response, path)
if env.has_key('HTTP_COOKIE'):
self.loadCookies(env['HTTP_COOKIE'])
- publish(request, handle_errors=handle_errors)
+
+ request = publish(request, handle_errors=handle_errors)
+
+ response = ResponseWrapper(request.response, path)
+
self.saveCookies(response)
self.setSite(old_site)
return response
@@ -688,12 +691,13 @@
raise ValueError("only one set of form values can be provided")
request.form = form
+ request = publish(request, handle_errors=handle_errors)
+
response = ResponseWrapper(
request.response, path,
omit=('x-content-type-warning', 'x-powered-by'),
)
- publish(request, handle_errors=handle_errors)
self.saveCookies(response)
setSite(old_site)
Modified: zope.app.testing/trunk/src/zope/app/testing/testing.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/testing.py 2008-02-01 11:30:53 UTC (rev 83371)
+++ zope.app.testing/trunk/src/zope/app/testing/testing.py 2008-02-01 13:26:00 UTC (rev 83372)
@@ -19,8 +19,37 @@
__docformat__ = "reStructuredText"
import os
+from ZODB.POSException import ConflictError
+from zope import interface
+from zope import component
+import zope.publisher.interfaces.browser
from zope.app.testing.functional import ZCMLLayer
AppTestingLayer = ZCMLLayer(
os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
__name__, 'AppTestingLayer', allow_teardown=True)
+
+
+class IFailingKlass(interface.Interface):
+ pass
+
+class FailingKlass(object):
+ interface.implements(IFailingKlass)
+
+
+class ConflictRaisingView(object):
+ __used_for__ = IFailingKlass
+
+ interface.implements(zope.publisher.interfaces.browser.IBrowserPublisher)
+ component.adapts(interface.Interface,
+ zope.publisher.interfaces.browser.IBrowserRequest)
+
+
+ def __init__(self, context, request):
+ pass
+
+ def browserDefault(self, *_):
+ return self, ()
+
+ def __call__(self):
+ raise ConflictError
Modified: zope.app.testing/trunk/src/zope/app/testing/tests.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/tests.py 2008-02-01 11:30:53 UTC (rev 83371)
+++ zope.app.testing/trunk/src/zope/app/testing/tests.py 2008-02-01 13:26:00 UTC (rev 83372)
@@ -34,8 +34,10 @@
from zope.app.testing.functional import FunctionalTestCase
from zope.app.testing.testing import AppTestingLayer
+from zope.app.testing.testing import FailingKlass
+
HEADERS = """\
HTTP/1.1 200 OK
Content-Type: text/plain
@@ -139,7 +141,7 @@
class FunctionalHTTPDocTest(unittest.TestCase):
def test_dochttp(self):
- import sys, StringIO
+ import sys
old = sys.stdout
sys.stdout = StringIO.StringIO()
dochttp(['-p', 'test', directory])
@@ -244,7 +246,7 @@
class CookieFunctionalTest(BrowserTestCase):
"""Functional tests should handle cookies like a web browser
-
+
Multiple requests in the same test should acumulate cookies.
We also ensure that cookies with path values are only sent for
the correct URL's so we can test cookies don't 'leak'. Expiry,
@@ -349,8 +351,55 @@
response = http("GET /++skin++Basic HTTP/1.1\n\n")
self.assert_("zopetopBasic.css" in str(response))
+class RetryProblemFunctional(FunctionalTestCase):
+ def setUp(self):
+ super(RetryProblemFunctional, self).setUp()
+ root = self.getRootFolder()
+
+ root['fail'] = FailingKlass()
+
+ transaction.commit()
+
+ def tearDown(self):
+ root = self.getRootFolder()
+ del root['fail']
+ super(RetryProblemFunctional, self).tearDown()
+
+ def test_retryOnConflictErrorFunctional(self):
+ from zope.app.testing.functional import HTTPCaller
+
+ http = HTTPCaller()
+ response = http(r"""
+GET /@@test-conflict-raise-view.html HTTP/1.1
+Authorization: Basic mgr:mgrpw
+""")
+
+ self.assertNotEqual(response.getStatus(), 599)
+ self.assertEqual(response.getStatus(), 500)
+
+class RetryProblemBrowser(BrowserTestCase):
+ def setUp(self):
+ super(RetryProblemBrowser, self).setUp()
+
+ root = self.getRootFolder()
+
+ root['fail'] = FailingKlass()
+
+ transaction.commit()
+
+ def tearDown(self):
+ root = self.getRootFolder()
+ del root['fail']
+ super(RetryProblemBrowser, self).tearDown()
+
+ def test_retryOnConflictErrorBrowser(self):
+ response = self.publish('/@@test-conflict-raise-view.html',
+ handle_errors=True)
+ self.assertNotEqual(response.getStatus(), 599)
+ self.assertEqual(response.getStatus(), 500)
+
def test_suite():
checker = RENormalizing([
(re.compile(r'^HTTP/1.1 (\d{3}) .*?\n'), 'HTTP/1.1 \\1\n')
@@ -358,6 +407,9 @@
SampleFunctionalTest.layer = AppTestingLayer
CookieFunctionalTest.layer = AppTestingLayer
SkinsAndHTTPCaller.layer = AppTestingLayer
+ RetryProblemFunctional.layer = AppTestingLayer
+ RetryProblemBrowser.layer = AppTestingLayer
+
doc_test = FunctionalDocFileSuite('doctest.txt', checker=checker)
doc_test.layer = AppTestingLayer
@@ -370,6 +422,8 @@
unittest.makeSuite(SampleFunctionalTest),
unittest.makeSuite(CookieFunctionalTest),
unittest.makeSuite(SkinsAndHTTPCaller),
+ unittest.makeSuite(RetryProblemFunctional),
+ unittest.makeSuite(RetryProblemBrowser),
doc_test,
))
More information about the Checkins
mailing list