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

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

#146: Fix browserlayer operations for Plone < 3.1.1

File size: 2.8 KB
Line 
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
9import transaction
10from zope.component import getUtility
11
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
21from Products.Five import zcml
22from Products.Five import fiveconfigure
23
24from Testing import ZopeTestCase as ztc
25
26from Products.CMFCore.utils import getToolByName
27
28from Products.PloneTestCase.layer import PloneSite
29from Products.PloneTestCase import PloneTestCase as ptc
30from Products.PloneTestCase import setup as ptc_setup
31
32from Products.PloneTestCase.PloneTestCase import portal_owner
33from Products.PloneTestCase.PloneTestCase import default_password
34
35from quintagroup.seoptimizer.config import PROJECT_NAME
36from quintagroup.seoptimizer.config import SUPPORT_BLAYER
37
38ptc.setupPloneSite()
39
40class NotInstalled(PloneSite):
41    """ Only package register, without installation into portal
42    """
43
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)
51
52
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]
60
61        # Sets the local site/manager
62        ptc_setup._placefulSetUp(portal)
63        # Install PROJECT
64        qi = getattr(portal, 'portal_quickinstaller', None)
65        qi.installProduct(PROJECT_NAME)
66        transaction.commit()
67
68    @classmethod
69    def tearDown(cls):
70        ptc_setup._placefulTearDown()
71       
72
73class MixinTestCase:
74
75    def _getauth(self):
76        # Fix authenticator for the form
77        import re
78
79        authenticator = self.portal.restrictedTraverse("@@authenticator")
80        html = authenticator.authenticator()
81        handle = re.search('value="(.*)"', html).groups()[0]
82        return handle
83
84    def beforeTearDown(self):
85        getUtility(IRAMCache).invalidateAll()
86
87
88class TestCase(MixinTestCase, ptc.PloneTestCase):
89    layer = Installed
90
91class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase):
92    layer = NotInstalled
93
94
95class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase):
96    layer = Installed
97
98class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase):
99    layer = NotInstalled
Note: See TracBrowser for help on using the repository browser.