Op 30-12-2009 2:39, Martin Aspeli schreef:
Virtual hosting is done by Zope, when it sees a "magic" URL. So you
could construct your testbrowser URLs like
http://nohost/VirtualHostBase/http/nohost:80/plone/VirtualHostRoot/<whatever>
Ah yes, http://nohost/ - I tried http://localhost:port/VirtualHostBase
and that doesn't make sense in the testbrowser context.
But unfortunately, this also doesn't work:
>>> from Products.Five.testbrowser import Browser
>>> browser = Browser()
>>> browser.open('http://nohost/VirtualHostBase/'
... 'http/nohost:80/plone/VirtualHostRoot/')
I get:
Failed example:
browser.open('http://nohost/VirtualHostBase/'
'http/nohost:80/plone/VirtualHostRoot/')
Exception raised:
Traceback (most recent call last):
File
"/home/applinet/scratch/project-x/plone/Zope-2.10.9-final-py2.4/lib/python/zope/testing/doctest.py",
line 1348, in __run
compileflags, 1) in test.globs
File "<doctest README2.txt[2]>", line 1, in ?
browser.open('http://nohost/VirtualHostBase/'
File
"/home/applinet/scratch/project-x/plone/Zope-2.10.9-final-py2.4/lib/python/zope/testbrowser/browser.py",
line 224, in open
self.mech_browser.open(url, data)
File
"/home/applinet/scratch/project-x/plone/Zope-2.10.9-final-py2.4/lib/python/mechanize/_mechanize.py",
line 177, in open
return self._mech_open(url, data)
File
"/home/applinet/scratch/project-x/plone/Zope-2.10.9-final-py2.4/lib/python/mechanize/_mechanize.py",
line 219, in _mech_open
raise error
HTTPError: HTTP Error 404: Not Found
It looks like Dylan is right:
testbrowser [...] hooks in at a level after vhm.
Or perhaps testbrowser's zope instance doesn't have a VHM installed in
the root.
You should use things like absolute_url() or request.physicalPathToURL() to
generate URLs that adequately take virtual hosting into account.
Yes, I use absolute_url(), parse it and chop off the protocol and host
to get a root-relative url. When accessed through the VirtualHostBase,
this produces url's like '/ham', when accessing Zope directly it
produces '/Plone/ham', which is fine.
It's just that the url in the testbrowser surprised me. But I guess
testing for '/plone/ham' in the functional test is an acceptable solution.
--
René
http://www.applinet.nl
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers