Looking under the hood? Interested in a job? Send a mail....

infrae.testing

infrae.testing defines sanes tests layers for testing in Zope 2, to use in conjunction with zope.testing.

Contents

API

It defines:

If you use the ZCMLLayer or Zope2Layer, you have two different callbacks registry you can use:

Those callbacks registry have an add method that can be used in order to register a new cleanup function:

from infrae.testing import testCleanUp

testCleanUp.add(my_cleanup_function)

Examples

ZCMLLayer

A example to test a package called corp.testpackage. The package as a ftesting.zcml file which should mainly load its own configure.zcml:

import unittest

from infrae.testing import ZCMLLayer
import corp.testpackage

layer = ZCMLLayer(corp.testpackage)


class MyTestCase(unittest.TestCase):

    layer = layer

The layer provides you a grok() method that can be used to grok a module in your test later on.

Zope2Layer

Now our corp.testpackage is a Zope 2 extension providing some content. We want to test it installed:

import unittest

from infrae.testing import ZCMLLayer
import corp.testpackage


class CorpLayer(Zope2Layer):
    """Add some installation tasks to the Zope2Layer.
    """
   default_products = Zope2Layer.default_products + ['CMFCore']
   default_packages = Zope2Layer.default_packages + ['corp.testpackage']
   default_users = Zope2Layer.default_users + {'corp_user': 'CorpRole'}

   def _install_application(self, app):
      factory = app.manage_addProduct['corp.testpackage']
      factory.manage_addCorpPortal('portal')

layer = CorpLayer(corp.testpackage)


class MyTestCase(unittest.TestCase):

    layer = layer

    def setUp(self):
        self.root = self.layer.get_application()
        self.layer.login('corp_user')

Of course your ZCML must include the ZCML of your package dependencies. As well we don't recommend to add Five in the layer as a default_products, it goes crazy (but include it in your ZCML !).

The layer provides you the following useful methods:

login(username)
Log as a the given username.
logout()
Logout.
get_root_folder()
Return the root of the database, not wrapped in a request.
get_application()
Return the root of the database, wrapped in a request.

Code

The code is available through a Mercurial repository at: https://hg.infrae.com/infrae.testing

Available releases

Release version Release date Release files
infrae.testing 1.3 Sep 3, 2012 4:34:46 PM infrae.testing-1.3.tar.gz
infrae.testing 1.2 Nov 7, 2011 1:55:19 PM infrae.testing-1.2.tar.gz
infrae.testing 1.1 Oct 7, 2010 11:09:00 AM infrae.testing-1.1.tar.gz
infrae.testing 1.0 Jul 15, 2010 5:41:25 PM infrae.testing-1.0.tar.gz

License: New BSD