source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/base.py @ 3223

Last change on this file since 3223 was 3141, checked in by zidane, 13 years ago

fixes pyflakes

File size: 3.0 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"""
[2139]8import transaction
9from zope.component import getUtility
[1493]10
[2139]11# Starting from plone.memoize v1.1a4 (used in plone4), global ram cache
12# utility provides other IRAMCache interface, than before
13try:
14    # In plone4 provides
15    from zope.ramcache.interfaces.ram import IRAMCache
[3141]16    IRAMCache
[2139]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
[2139]26from Products.PloneTestCase.layer import PloneSite
[1493]27from Products.PloneTestCase import PloneTestCase as ptc
[2139]28from Products.PloneTestCase import setup as ptc_setup
[1493]29
[2139]30from quintagroup.seoptimizer.config import PROJECT_NAME
[1493]31
[2139]32ptc.setupPloneSite()
[1493]33
[3134]34
[2139]35class NotInstalled(PloneSite):
36    """ Only package register, without installation into portal
[1493]37    """
38
[2139]39    @classmethod
40    def setUp(cls):
41        fiveconfigure.debug_mode = True
42        import quintagroup.seoptimizer
43        zcml.load_config('configure.zcml', quintagroup.seoptimizer)
44        fiveconfigure.debug_mode = False
45        ztc.installPackage(PROJECT_NAME)
[1493]46
47
[2139]48class Installed(NotInstalled):
49    """ Install product into the portal
50    """
51    @classmethod
52    def setUp(cls):
53        app = ztc.app()
54        portal = app[ptc_setup.portal_name]
[1493]55
[2139]56        # Sets the local site/manager
57        ptc_setup._placefulSetUp(portal)
58        # Install PROJECT
59        qi = getattr(portal, 'portal_quickinstaller', None)
[2936]60        if not ptc.PLONE31:
61            qi.installProduct("plone.browserlayer")
[2139]62        qi.installProduct(PROJECT_NAME)
63        transaction.commit()
[1493]64
[2139]65    @classmethod
66    def tearDown(cls):
67        ptc_setup._placefulTearDown()
[1493]68
[3134]69
[2139]70class MixinTestCase:
[1493]71
[2139]72    def _getauth(self):
73        # Fix authenticator for the form
74        import re
75        try:
76            authenticator = self.portal.restrictedTraverse("@@authenticator")
77        except:
[3134]78            handle = ""
[2139]79        else:
80            html = authenticator.authenticator()
81            handle = re.search('value="(.*)"', html).groups()[0]
82        return handle
[1493]83
[2139]84    def beforeTearDown(self):
85        getUtility(IRAMCache).invalidateAll()
[1493]86
[3011]87    def installBrowserLayer(self):
88        if not ptc.PLONE31:
89            qi = getattr(self.portal, 'portal_quickinstaller', None)
90            qi.installProduct("plone.browserlayer")
[1493]91
[3011]92
[2139]93class TestCase(MixinTestCase, ptc.PloneTestCase):
94    layer = Installed
[1493]95
[3134]96
[2139]97class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase):
98    layer = NotInstalled
[1493]99
100
[2139]101class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase):
102    layer = Installed
[1493]103
[3011]104    def afterSetUp(self):
105        self.installBrowserLayer()
106
[3134]107
[2139]108class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase):
109    layer = NotInstalled
[2936]110
111    def afterSetUp(self):
[3011]112        self.installBrowserLayer()
Note: See TracBrowser for help on using the repository browser.