source: products/quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/base.py @ 2128

Last change on this file since 2128 was 2128, checked in by mylan, 14 years ago

#146: prevent tests breakage for plone, before plone.protect package added

File size: 2.9 KB
RevLine 
[1493]1"""Test setup for integration and functional tests.
2
3When we import PloneTestCase and then call setupPloneSite(), all of
4Plone's products are loaded, and a Plone site will be created. This
5happens at module level, which makes it faster to run each test, but
6slows down test runner startup.
7"""
8import re
[1896]9import transaction
[1908]10from zope.component import getUtility
11
[1938]12# Starting from plone.memoize v1.1a4 (used in plone4), global ram cache
13# utility provides other IRAMCache interface, than before
14try:
15    # In plone4 provides
16    from zope.ramcache.interfaces.ram import IRAMCache
17except ImportError:
18    # In plone3 provides
19    from zope.app.cache.interfaces.ram import IRAMCache
20
[1493]21from Products.Five import zcml
22from Products.Five import fiveconfigure
23
24from Testing import ZopeTestCase as ztc
25
[1877]26from Products.CMFCore.utils import getToolByName
27
[1958]28from Products.PloneTestCase.layer import PloneSite
[1493]29from Products.PloneTestCase import PloneTestCase as ptc
[1896]30from Products.PloneTestCase import setup as ptc_setup
31
[1877]32from Products.PloneTestCase.PloneTestCase import portal_owner
33from Products.PloneTestCase.PloneTestCase import default_password
[1493]34
[1958]35from quintagroup.seoptimizer.config import PROJECT_NAME
[2124]36from quintagroup.seoptimizer.config import SUPPORT_BLAYER
[1493]37
[1896]38ptc.setupPloneSite()
[1493]39
[1896]40class NotInstalled(PloneSite):
41    """ Only package register, without installation into portal
[1493]42    """
43
[1896]44    @classmethod
45    def setUp(cls):
46        fiveconfigure.debug_mode = True
47        import quintagroup.seoptimizer
48        zcml.load_config('configure.zcml', quintagroup.seoptimizer)
49        fiveconfigure.debug_mode = False
50        ztc.installPackage(PROJECT_NAME)
[1493]51
52
[1896]53class Installed(NotInstalled):
54    """ Install product into the portal
55    """
56    @classmethod
57    def setUp(cls):
58        app = ztc.app()
59        portal = app[ptc_setup.portal_name]
[1937]60
61        # Sets the local site/manager
62        ptc_setup._placefulSetUp(portal)
63        # Install PROJECT
[1896]64        qi = getattr(portal, 'portal_quickinstaller', None)
65        qi.installProduct(PROJECT_NAME)
66        transaction.commit()
[1493]67
[1937]68    @classmethod
69    def tearDown(cls):
70        ptc_setup._placefulTearDown()
71       
[1493]72
[1792]73class MixinTestCase:
[1493]74
[1792]75    def _getauth(self):
76        # Fix authenticator for the form
77        import re
[2128]78        try:
79            authenticator = self.portal.restrictedTraverse("@@authenticator")
80        except:
81            handle  = ""
82        else:
83            html = authenticator.authenticator()
84            handle = re.search('value="(.*)"', html).groups()[0]
[1792]85        return handle
86
[1908]87    def beforeTearDown(self):
88        getUtility(IRAMCache).invalidateAll()
[1792]89
[1908]90
[1792]91class TestCase(MixinTestCase, ptc.PloneTestCase):
[1896]92    layer = Installed
[1493]93
[1896]94class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase):
95    layer = NotInstalled
[1493]96
97
[1896]98class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase):
99    layer = Installed
[1493]100
[1896]101class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase):
102    layer = NotInstalled
Note: See TracBrowser for help on using the repository browser.