[Grok-dev] Integration testing with zope.testbrowser and fanstatic

Noe Nieto nnieto at noenieto.com
Tue Jan 3 03:01:44 UTC 2012


Hi.

I want to do some integration testing with gocept.selenium. I've ran into
some problems with fanstatic resources. I tought it was something to do
with the testing layers of gocept.selenium, but I layed out a test with
zope.testbrowser and even though fanstatic resources are being injected,
when I command zope.testbrowser to GET the resource, the result is a HTTP
404.

Why cannot fanstatic work fully on integration tests?

Here's the code of my test:

-----
import unittest

#ZTK & Grok
import transaction
from zope.app.wsgi.testlayer import Browser
from zope.component import getGlobalSiteManager
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.interface import Interface

#Fanstatic imports
import fanstatic
from zope.fanstatic.testing import ZopeFanstaticBrowserLayer
from zope.fanstatic.zcml import create_factory

#tzicatl namespace
from tzicatl.testselenium.resource import library
import tzicatl.testselenium
from tzicatl.testselenium.app import SampleApplication

class TestLayerWithInjector(ZopeFanstaticBrowserLayer):
    def testSetup(self):
        super(TestLayerWithInjector, self).testSetup()
        #Because is difficult to dynamically register an entry_point in
tests,
        #we do the setup by hand.
        resource_factory = create_factory(style)
        gsm = getGlobalSiteManager()
        gsm.registerAdapter(
            resource_factory,
            (IBrowserRequest, ),
            Interface,
            library.name
        )

layer_with_fanstatic_injector = TestLayerWithInjector(
    tzicatl.testselenium.tests
)

class SeleniumWithZopeTestBrowser(unittest.TestCase):
    layer = layer_with_fanstatic_injector

    def test_open_index(self):
        browser = Browser()
        browser.open('http://localhost/@@mygenericview')
        self.assertIn('Welcome to my sample application', browser.contents)
        self.assertIn('
http://localhost/fanstatic/tzicatl.testselenium/style.css',
                      browser.contents)

    def test_open_fanstatic_resource(self):
        browser = Browser()
        browser.open('
http://localhost/fanstatic/tzicatl.testselenium/style.css')
        self.assertFalse(browser.isHtml)
        self.assertEqual(browser.headers['content-type'], 'text/css')



-- 
---
Noe Nieto
NNieto Consulting Services
M: nnieto at noenieto.com
W: http://noenieto.com
T:  @tzicatl <https://twitter.com/#%21/tzicatl>
Li: Perfil en LinkedIn <http://www.linkedin.com/profile/view?id=84300665>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/grok-dev/attachments/20120102/c39aa59e/attachment.html>


More information about the Grok-dev mailing list