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

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

#161: Fixed local SiteManager? loosing (tests breaks in plone4)

File size: 2.7 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
56        # Sets the local site/manager
57        ptc_setup._placefulSetUp(portal)
58        # Install PROJECT
59        qi = getattr(portal, 'portal_quickinstaller', None)
60        qi.installProduct(PROJECT_NAME)
61        transaction.commit()
62
63    @classmethod
64    def tearDown(cls):
65        ptc_setup._placefulTearDown()
66       
67
68class MixinTestCase:
69
70    def _getauth(self):
71        # Fix authenticator for the form
72        import re
73
74        authenticator = self.portal.restrictedTraverse("@@authenticator")
75        html = authenticator.authenticator()
76        handle = re.search('value="(.*)"', html).groups()[0]
77        return handle
78
79    def beforeTearDown(self):
80        getUtility(IRAMCache).invalidateAll()
81
82
83class TestCase(MixinTestCase, ptc.PloneTestCase):
84    layer = Installed
85
86class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase):
87    layer = NotInstalled
88
89
90class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase):
91    layer = Installed
92
93class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase):
94    layer = NotInstalled
Note: See TracBrowser for help on using the repository browser.