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

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

#167: Prevent recalculation global meta-tags for every page - use ram cache. Update tests

File size: 2.5 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
11from zope.app.cache.interfaces.ram import IRAMCache
12
13from AccessControl.SecurityManagement import newSecurityManager
14
15from Products.Five import zcml
16from Products.Five import fiveconfigure
17
18from Testing import ZopeTestCase as ztc
19
20from Products.CMFCore.utils import getToolByName
21
22from Products.PloneTestCase.layer import onsetup, PloneSite
23from Products.PloneTestCase import PloneTestCase as ptc
24from Products.PloneTestCase import setup as ptc_setup
25
26from Products.PloneTestCase.PloneTestCase import portal_owner
27from Products.PloneTestCase.PloneTestCase import default_user
28from Products.PloneTestCase.PloneTestCase import default_password
29
30from quintagroup.seoptimizer.config import *
31
32ptc.setupPloneSite()
33
34class NotInstalled(PloneSite):
35    """ Only package register, without installation into portal
36    """
37
38    @classmethod
39    def setUp(cls):
40        fiveconfigure.debug_mode = True
41        import quintagroup.seoptimizer
42        zcml.load_config('configure.zcml', quintagroup.seoptimizer)
43        #zcml.load_config('overrides.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        qi = getattr(portal, 'portal_quickinstaller', None)
56        qi.installProduct(PROJECT_NAME)
57        transaction.commit()
58
59
60class MixinTestCase:
61
62    def _getauth(self):
63        # Fix authenticator for the form
64        import re
65
66        authenticator = self.portal.restrictedTraverse("@@authenticator")
67        html = authenticator.authenticator()
68        handle = re.search('value="(.*)"', html).groups()[0]
69        return handle
70
71    def beforeTearDown(self):
72        getUtility(IRAMCache).invalidateAll()
73
74
75class TestCase(MixinTestCase, ptc.PloneTestCase):
76    layer = Installed
77
78class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase):
79    layer = NotInstalled
80
81
82class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase):
83    layer = Installed
84
85class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase):
86    layer = NotInstalled
Note: See TracBrowser for help on using the repository browser.