Fetching contributors…
Cannot retrieve contributors at this time
109 lines (80 sloc) 3.18 KB
# -*- coding: utf-8 -*-
Base module for unittesting
import unittest2 as unittest
from import ControlPanelTestCase
from import applyProfile
from import FunctionalTesting
from import IntegrationTesting
from import login
from import PLONE_FIXTURE
from import PloneSandboxLayer
from import setRoles
from import TEST_USER_ID
from import TEST_USER_NAME
from plone.testing import z2
from Products.CMFPlone.tests.utils import MockMailHost
from Products.MailHost.interfaces import IMailHost
from import getSite
import logging
class MockedLoggingHandler(logging.Handler):
debug = []
warning = []
info = []
error = []
def emit(self, record):
getattr(self.__class__, record.levelname.lower()).append(record.getMessage())
def reset(cls):
for attr in dir(cls):
if isinstance(getattr(cls, attr), list):
setattr(cls, attr, [])
class NiteowebClick2sellLayer(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE,)
def setUpZope(self, app, configurationContext):
"""Set up Zope."""
# Load ZCML
import niteoweb.click2sell
z2.installProduct(app, 'niteoweb.click2sell')
def setUpPloneSite(self, portal):
"""Set up Plone."""
# Install into Plone site using portal_setup
applyProfile(portal, 'niteoweb.click2sell:default')
# Login as Manager
setRoles(portal, TEST_USER_ID, ['Manager'])
login(portal, TEST_USER_NAME)
# Mock mailhost
portal.email_from_address = ''
mockmailhost = MockMailHost('MailHost')
portal.MailHost = mockmailhost
sm = getSite().getSiteManager()
sm.registerUtility(component=mockmailhost, provided=IMailHost)
# Commit so that the test browser sees these objects
import transaction
# add a logging handler that stores everything in a list so we can
# later assert on it
logger = logging.getLogger('niteoweb.click2sell')
def tearDownZope(self, app):
"""Tear down Zope."""
z2.uninstallProduct(app, 'niteoweb.click2sell')
FIXTURE = NiteowebClick2sellLayer()
INTEGRATION_TESTING = IntegrationTesting(
bases=(FIXTURE,), name="NiteowebClick2sellLayer:Integration")
FUNCTIONAL_TESTING = FunctionalTesting(
bases=(FIXTURE,), name="NiteowebClick2sellLayer:Functional")
class IntegrationTestCase(unittest.TestCase):
"""Base class for integration tests."""
class FunctionalTestCase(unittest.TestCase):
"""Base class for functional tests."""
class Click2SellControlPanelTestCase(FunctionalTestCase, ControlPanelTestCase):
"""Test case used for control panel tests, with some convenience
methods from