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

Last change on this file since 1958 was 1958, checked in by liebster, 14 years ago

Clean-up code http://codereview.corp.quintagroup.com/40241/show

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
36
37ptc.setupPloneSite()
38
39class NotInstalled(PloneSite):
40    """ Only package register, without installation into portal
41    """
42
43    @classmethod
44    def setUp(cls):
45        fiveconfigure.debug_mode = True
46        import quintagroup.seoptimizer
47        zcml.load_config('configure.zcml', quintagroup.seoptimizer)
48        fiveconfigure.debug_mode = False
49        ztc.installPackage(PROJECT_NAME)
50
51
52class Installed(NotInstalled):
53    """ Install product into the portal
54    """
55    @classmethod
56    def setUp(cls):
57        app = ztc.app()
58        portal = app[ptc_setup.portal_name]
59
60        # Sets the local site/manager
61        ptc_setup._placefulSetUp(portal)
62        # Install PROJECT
63        qi = getattr(portal, 'portal_quickinstaller', None)
64        qi.installProduct(PROJECT_NAME)
65        transaction.commit()
66
67    @classmethod
68    def tearDown(cls):
69        ptc_setup._placefulTearDown()
70       
71
72class MixinTestCase:
73
74    def _getauth(self):
75        # Fix authenticator for the form
76        import re
77
78        authenticator = self.portal.restrictedTraverse("@@authenticator")
79        html = authenticator.authenticator()
80        handle = re.search('value="(.*)"', html).groups()[0]
81        return handle
82
83    def beforeTearDown(self):
84        getUtility(IRAMCache).invalidateAll()
85
86
87class TestCase(MixinTestCase, ptc.PloneTestCase):
88    layer = Installed
89
90class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase):
91    layer = NotInstalled
92
93
94class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase):
95    layer = Installed
96
97class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase):
98    layer = NotInstalled
Note: See TracBrowser for help on using the repository browser.