Ticket #1203 (closed defect: fixed)
testutil.call_with_request unusable with "raise redirect()"
| Reported by: | Felix.Schwarz | Owned by: | Chris Arndt |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.0.x bugfix |
| Component: | TurboGears | Version: | 1.0b2 |
| Severity: | normal | Keywords: | needs review |
| Cc: |
Description
Calls with testutil.call_with_request(method, request) will always fail if method() raises redirects (e.g. 'raise redirect("login")').
File "/home/fs/workspace/junkkiller/junkkiller/quarantine/controllers.py", line 28, in login
raise redirect(forward_url)
File "/usr/lib/python2.4/site-packages/turbogears/controllers.py", line 540, in redirect
raise cherrypy.HTTPRedirect(
File "/usr/lib/python2.4/site-packages/cherrypy/_cperror.py", line 90, in init
if cherrypy.response.version >= "1.1":
File "/usr/lib/python2.4/site-packages/cherrypy/init.py", line 43, in getattr
return getattr(childobject, name)
AttributeError?: 'Response' object has no attribute 'version'
The version attribute is normally set by cherrypy but call_with_request does not call these methods (which is okay!). In order to make call_with_request usable again, I propose adding the line 'cherrypy.serving.response.version = "1.1"' just below 'cherrypy.serving.response = _cphttptools.Response()' in testutil.call_with_request.
Attachments
Change History
Changed 5 years ago by Felix.Schwarz
-
attachment
response_version.patch
added
Changed 5 years ago by Felix.Schwarz
-
attachment
test_reponse.py
added
some cleanup, removed wrong cherrypy.request assignments
comment:1 Changed 5 years ago by Felix.Schwarz
Actually, I found that DummyRequest? is a bit too simple. The updated test case will reveal that the TurboGears version is lacking several important attributes/functions such as browser_url. This is fixed by the patch attached as DummyRequest? inherits from cherrypy's Request now.
comment:2 Changed 5 years ago by jorge.vargas
- Component changed from unassigned to TurboGears
- Milestone set to 1.1
comment:3 Changed 5 years ago by jorge.vargas
from the mailing list
Note that CP 3 has a dummy request object in the main thread (actually, there's a single default object shared by all non-request threads) that you can play with to your heart's content. Ditto for Response. Robert Brewer System Architect Amor Ministries
comment:4 Changed 5 years ago by alberto
- Milestone changed from 1.1 to __unclassified__
Batch moved into unclassified from 1.1 to properly track progress on the later
comment:5 Changed 3 years ago by Chris Arndt
- Keywords needs re-test added
Can somebody check if this is still an issue or if testutil in 1.1 has been fixed in the meantime? If yes, please move into the "1.0-bugfix" milestone.
comment:6 Changed 3 years ago by Chris Arndt
- Owner changed from anonymous to Chris Arndt
- Status changed from new to assigned
- Keywords review added; re-test removed
- Milestone changed from __unclassified__ to 1.0.x bugfix
I tested this with the latest (r5365) 1.0 branch and teh issue still exists. But things have changed a bit with regard to request handling since this ticket was opened, so I adapted the patch by enhancing DummyRequest a little more and merging test_response.py into the existing test_testutils.py module. Before I apply this, I would like to get some feed back on the validity of the patch.
Changed 3 years ago by Chris Arndt
-
attachment
dummy-request.diff
added
Combined above two files into one patch and adapted it to work with latest 1.0 HEAD
updated patch: DummyRequest? is too simple, too