can't use testbrowser to test redirects to remote sites
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 3 |
Won't Fix
|
Medium
|
Unassigned | ||
zope.testbrowser |
Fix Released
|
Medium
|
Unassigned |
Bug Description
I would like to be able to use zope.testbrowser to test a redirect to a remote site.
Currently this fails because testbrowser tries to get the zope publication code to render the remote site, which fails. It would be nice if I could tell testbrowser to not follow the redirect in this case, and be able to check the headers to verify that the redirect went to the appropriate web site.
Below is the traceback I get:
Failed example:
beta_
Exception raised:
Traceback (most recent call last):
File "lib/zope/
File "<doctest xx-beta-
File "lib/zope/
File "/usr/lib/
return self._mech_
File "/usr/lib/
File "urllib2.py", line 364, in open
response = meth(req, response)
File "/usr/lib/
response = self.parent.error(
File "urllib2.py", line 396, in error
result = self._call_
File "urllib2.py", line 337, in _call_chain
result = func(*args)
File "/usr/lib/
return self.parent.
File "/usr/lib/
return self._mech_
File "/usr/lib/
File "urllib2.py", line 358, in open
response = self._open(req, data)
File "urllib2.py", line 376, in _open
'_open', req)
File "urllib2.py", line 337, in _call_chain
result = func(*args)
File "lib/zope/
return self.do_
File "urllib2.py", line 993, in do_open
File "lib/zope/
File "lib/zope/
environment)
File "lib/zope/
return chooseClasses(
File "lib/zope/
TypeError: 'NoneType' object is not callable
Changed in zope.testing: | |
importance: | Undecided → Medium |
Changed in zope3: | |
status: | New → Won't Fix |
Changed in zope.testing: | |
status: | New → Triaged |
affects: | zope.testing → zope.testbrowser |
> = Request - Entry #1 by jamesh on Feb 7, 2007 6:35 am
>
> I would like to be able to use zope.testbrowser to test a redirect to a
> remote site.
I've wanted to do this myself, but there are a couple of downsides. First, I believe this will complicate the code somewhat for what is a pretty rare need.
The other is in the class of "you shouldn't want to do that anyway". Requiring network connectivity for a test should be avoided when possible, and you don't want to test that the other site is available, only that your app redirects properly.
Here are some options (in the order I would prefer if this were my test):
* create a custom testbrowser subclass that disables the redirection plugin that urllib2 (and therefore mechanize and testbrowser) uses and then inspect the headers to ensure the redirect happens as you expect
* for this part of your test use the "old style" functional tests to make sure you get a 301 redirect to the site you want to go to.
* use the non-Zope publisher version of testbrowser for this test (this means your test setup will have to start a "real" Zope instance to listen on a port)
Here's a rough implementation of the first option (only lightly tested):
from zope.testbrowse r.testing import PublisherMechan izeBrowser r.browser import Browser
from zope.testbrowse
my_features = PublisherMechan izeBrowser. default_ features[ :] remove( '_redirect' )
my_features.
class NonRedirectingM echanizeBrowser (PublisherMecha nizeBrowser) : features = my_features
default_
browser = Browser( mech_browser= NonRedirectingM echanizeBrowser ()) launchpad. dev/ubuntu') headers[ 'location' ] == 'redirected URL'
browser.open('http://
assert browser.