Layered Functional Tests in Zope3
Testlayers minimize setup costs for functional tests in zope3. One can specify a zcml file which is loaded when a specific suite is run. This reduces startup time for the test a lot compared to functional tests which use the site wide ftesting.zcml configuration file, which may include packages the test don’t need at all.
Steps to set up a layered functional test for your package:
create a ftests.py file in your package directory with the following contents:
from zope.app.testing import functional
functional.defineLayer('TestLayer', 'ftesting.zcml')
def test_suite():
suite = functional.FunctionalDocFileSuite(
'README.txt',
)
suite.layer = TestLayer
return suite
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
Where ‘README.txt’ is a normal REST file which contains the tests.
Then create the ‘ftesting.zcml’ file wher you can do your setup for the specific test.
Here is a basic example which sets up security etc.
<configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser" i18n_domain="zope"> <include package="zope.app" /> <include package="zope.app.server" /> <include package="zope.app.authentication" /> <include package="zope.app.securitypolicy" file="meta.zcml" /> <securityPolicy component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" /> <include package="zope.app.securitypolicy" /> <!-- we ought to use this for the tests <include package="zope.app.i18n.tests" /> --> <role id="zope.Anonymous" title="Everybody" description="All users have this role implicitly" /> <role id="zope.Manager" title="Site Manager" /> <role id="zope.Member" title="Site Member" /> <grantAll role="zope.Manager" /> <principal id="zope.manager" title="Administrator" login="mgr" password="mgrpw" /> <grant role="zope.Manager" principal="zope.manager" /> </configure>
You can now run the test from your instance_home:
./bin/test -fs your.package
Technorati Tags: programming, python, zope
Leave a Reply