Boilerplate testsΒΆ

These are test snippets useful for common use cases.

See http://plone.org/documentation/manual/developer-manual/testing/writing-a-plonetestcase-unit-integration-test to learn about PloneTestCase helper methods.

Test portal title:

def test_portal_title(self):
    self.assertEquals("Plone site", self.portal.getProperty('title'))

Test if view is protected:

def test_view_is_protected(self):
    from AccessControl import Unauthorized
    self.logout()
    self.assertRaises(
        Unauthorized,
        self.portal.restrictedTraverse,
        '@@view-name')

Test if object exists in folder:

def test_object_in_folder(self):
    self.failIf('object_id' in self.portal.objectIds())

Javascript registered:

def test_js_available(self):
    jsreg = getattr(self.portal, 'portal_javascripts')
    script_ids = jsreg.getResourceIds()
    self.failUnless('my-js-file.js' in script_ids)

CSS registered:

def test_css_available(self):
    cssreg = getattr(self.portal, 'portal_css')
    stylesheets_ids = cssreg.getResourceIds()
    self.failUnless('MyCSS.css' in stylesheets_ids)

Test that a certain skin layer is present in portal_skins:

def test_skin_layer_installed(self):
    self.failUnless('my-skin-layer' in self.skins.objectIds())
    self.failUnless('attachment_widgets' in self.skins.objectIds())

About Plone

This is documentation for Plone®. Plone is a popular, open source, content management system written in Python programming language.




Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Go to Boilerplate tests on GitHub.
  2. Press Fork and edit this file button.
  3. Edit file contents using GitHub's text editor in your web browserm
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on Github.

For basic information about updating this manual and Sphinx format please see Writing and updating the manual guide.