On 30/12/2009, at 8:04 AM, René Pijlman wrote:

I'm developing a product for Plone 3.3 that transforms url's in the view of my content type, following Martin's book (which is now the most worn out book on my shelf :-). The unit tests work fine, but a functional test in zope.testbrowser failed. It turns out this is caused by the url's of pages in the testbrowser.

The test begins with the ususal:

   >>> from Products.Five.testbrowser import Browser
   >>> browser = Browser()
   >>> portal_url = self.portal.absolute_url()

Then it opens portal_url, adds folder 'ham', opens that folder and adds a page 'spam'. In the test runner (bin/instance test -s my.package) this results in the url:

   (Pdb) print browser.url
   http://nohost/plone/ham/spam
                ^^^^^^

When the site is accessed through Apache and VirtualHostBase, the same page would have the url:

   http://myhost/ham/spam

The difference is the extra '/plone' in the test runner, for the plone site object in Zope's root. This causes my test for a root- relative link to fail:

   >>> '<a href="/eggs">' in browser.contents
   True

... since in the test runner that link has become:

   (Pdb) print browser.contents[15650:15670]
       <a href="/plone/eggs">

Is there a way to have the test runner use VirtualHostBase, and get urls that are the same as with interactive use through Apache and VirtualHostBase?

Or is the custom solution to write the tests as if using Zope directly, without Apache and VirtualHostBase?

testbrowser is a zope level testing tool so it doesn't know about plone sites and it hooks in at a level after vhm.

I'd suggest just using

>>> print browser.contents
<html>
...'<a href=".../eggs">...

not as rigourous I know.

The more correct way would be to create a doctest normalizer that adjusts url for tests. I'm not sure if that exists yet or not.



--
René
http://www.applinet.nl

_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers


_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers

Reply via email to