Ticket #1203 (closed defect: fixed)

Opened 3 years ago

Last modified 1 year ago

testutil.call_with_request unusable with "raise redirect()"

Reported by: Felix.Schwarz Assigned to: 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

response_version.patch (1.1 kB) - added by Felix.Schwarz on 12/14/06 06:12:42.
updated patch: DummyRequest? is too simple, too
test_reponse.py (1.0 kB) - added by Felix.Schwarz on 12/14/06 06:13:26.
some cleanup, removed wrong cherrypy.request assignments
dummy-request.diff (5.0 kB) - added by Chris Arndt on 09/09/08 04:47:45.
Combined above two files into one patch and adapted it to work with latest 1.0 HEAD

Change History

12/14/06 06:12:42 changed by Felix.Schwarz

  • attachment response_version.patch added.

updated patch: DummyRequest? is too simple, too

12/14/06 06:13:26 changed by Felix.Schwarz

  • attachment test_reponse.py added.

some cleanup, removed wrong cherrypy.request assignments

12/14/06 06:15:26 changed 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.

01/30/07 21:28:20 changed by jorge.vargas

  • component changed from unassigned to TurboGears.
  • milestone set to 1.1.

01/31/07 23:24:10 changed 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

03/28/07 12:42:17 changed by alberto

  • milestone changed from 1.1 to __unclassified__.

Batch moved into unclassified from 1.1 to properly track progress on the later

08/30/08 11:58:30 changed by Chris Arndt

  • keywords set to needs re-test.

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.

09/09/08 04:46:44 changed by Chris Arndt

  • keywords changed from needs re-test to needs review.
  • owner changed from anonymous to Chris Arndt.
  • status changed from new to assigned.
  • 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.

09/09/08 04:47:45 changed 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

09/11/08 06:29:20 changed by faide

This patch seems pretty good to me. Let's apply this so that it's present in 1.0.7

09/11/08 08:05:46 changed by Chris Arndt

  • status changed from assigned to closed.
  • resolution set to fixed.

Applied in r5385.