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

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

fixes pyflakes

File size: 3.0 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 transaction
9from zope.component import getUtility
10
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
16    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.PloneTestCase.layer import PloneSite
27from Products.PloneTestCase import PloneTestCase as ptc
28from Products.PloneTestCase import setup as ptc_setup
29
30from quintagroup.seoptimizer.config import PROJECT_NAME
31
32ptc.setupPloneSite()
33
34
35class NotInstalled(PloneSite):
36    """ Only package register, without installation into portal
37    """
38
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)
46
47
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]
55
56        # Sets the local site/manager
57        ptc_setup._placefulSetUp(portal)
58        # Install PROJECT
59        qi = getattr(portal, 'portal_quickinstaller', None)
60        if not ptc.PLONE31:
61            qi.installProduct("plone.browserlayer")
62        qi.installProduct(PROJECT_NAME)
63        transaction.commit()
64
65    @classmethod
66    def tearDown(cls):
67        ptc_setup._placefulTearDown()
68
69
70class MixinTestCase:
71
72    def _getauth(self):
73        # Fix authenticator for the form
74        import re
75        try:
76            authenticator = self.portal.restrictedTraverse("@@authenticator")
77        except:
78            handle = ""
79        else:
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    def installBrowserLayer(self):
88        if not ptc.PLONE31:
89            qi = getattr(self.portal, 'portal_quickinstaller', None)
90            qi.installProduct("plone.browserlayer")
91
92
93class TestCase(MixinTestCase, ptc.PloneTestCase):
94    layer = Installed
95
96
97class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase):
98    layer = NotInstalled
99
100
101class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase):
102    layer = Installed
103
104    def afterSetUp(self):
105        self.installBrowserLayer()
106
107
108class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase):
109    layer = NotInstalled
110
111    def afterSetUp(self):
112        self.installBrowserLayer()
Note: See TracBrowser for help on using the repository browser.