This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
pfwbged.policy/src/pfwbged/policy/testing.py

79 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
"""Base module for unittesting."""
from plone.app.testing import applyProfile
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import login
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.testing import z2
import unittest2 as unittest
import pfwbged.policy
class PfwbgedPolicyLayer(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE,)
def setUpZope(self, app, configurationContext):
"""Set up Zope."""
# Load ZCML
self.loadZCML(package=pfwbged.policy,
name='testing.zcml')
z2.installProduct(app, 'pfwbged.policy')
def setUpPloneSite(self, portal):
"""Set up Plone."""
# Install into Plone site using portal_setup
applyProfile(portal, 'pfwbged.policy:default')
# Login and create some test content
setRoles(portal, TEST_USER_ID, ['Manager'])
login(portal, TEST_USER_NAME)
portal.invokeFactory('Folder', 'folder')
# Commit so that the test browser sees these objects
portal.portal_catalog.clearFindAndRebuild()
import transaction
transaction.commit()
def tearDownZope(self, app):
"""Tear down Zope."""
z2.uninstallProduct(app, 'pfwbged.policy')
FIXTURE = PfwbgedPolicyLayer(
name="FIXTURE"
)
INTEGRATION = IntegrationTesting(
bases=(FIXTURE,),
name="INTEGRATION"
)
FUNCTIONAL = FunctionalTesting(
bases=(FIXTURE,),
name="FUNCTIONAL"
)
class IntegrationTestCase(unittest.TestCase):
"""Base class for integration tests."""
layer = INTEGRATION
def setUp(self):
super(IntegrationTestCase, self).setUp()
self.portal = self.layer['portal']
class FunctionalTestCase(unittest.TestCase):
"""Base class for functional tests."""
layer = FUNCTIONAL