Skip to main content

Painless setup of Plone integration test layers

Project description

Introduction

plone.testlayers is supposed to make setting up test layers for Plone integration tests quick and painless. It’s main function, makeTestLayer will conveniently generate a test layer, which will load your packages ZCML and install them, apply a GenericSetup profile and help you set up sample content for speedier testing.

Usage

To make use of plone.testlayers you’d typically create a base test case for your package, somewhat like:

from Products.PloneTestCase import PloneTestCase as ptc
from plone.testlayers import makeTestLayer

def create(portal):
    """ create sample content for test runs """
    portal.invokeFactory('File', 'foo', title='foo', file='foo bar')

def destroy(portal):
    """ clean up sample content for test runs """
    portal.manage_delObjects(ids='foo')

ptc.setupPloneSite()
FooLayer = makeTestLayer(packages=('collective.foo', 'collective.bar'),
    profile='collective.foo:default', create=create, destroy=destroy)

class FooTestCase(ptc.PloneTestCase):
    """ base class for integration tests """
    layer = FooLayer

With that in place you can now set up your individual test cases like:

from unittest import defaultTestLoader
from collective.foo.tests.base import FooTestCase

class FooTests(FooTestCase):

    def testFoo(self):
        # the 'foo' object set up in the layer should already exist
        self.failUnless(self.portal['foo'])

def test_suite():
    return defaultTestLoader.loadTestsFromName(__name__)

Changelog

1.0a1 - Released April 23, 2009

  • Initial release [witsch]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plone.testlayers-1.0a1.zip (9.0 kB view details)

Uploaded Source

File details

Details for the file plone.testlayers-1.0a1.zip.

File metadata

File hashes

Hashes for plone.testlayers-1.0a1.zip
Algorithm Hash digest
SHA256 ac4d145e77350b162c5b958bec55baf7160332d0711217d73fa1c6dfcd25070f
MD5 200a87afd9b8fab0c8a2e6d1ec7d4229
BLAKE2b-256 fe9940f52df33c53792a8a5d85021fce45730531e4b06c4ccff86cee1dd29595

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page