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

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

#161: Add Installed and NotInstalled? layers

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