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

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

#161: Clarify, fix installation/uninstallation tests overheads

File size: 4.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
9from AccessControl.SecurityManagement import newSecurityManager
10
11from Products.Five import zcml
12from Products.Five import fiveconfigure
13
14from Testing import ZopeTestCase as ztc
15
16from Products.PloneTestCase import PloneTestCase as ptc
17from Products.PloneTestCase.layer import onsetup
18
19from Products.CMFCore.utils import getToolByName
20from config import PROJECT_NAME
21
22# When ZopeTestCase configures Zope, it will *not* auto-load products
23# in Products/. Instead, we have to use a statement such as:
24#   ztc.installProduct('SimpleAttachment')
25# This does *not* apply to products in eggs and Python packages (i.e.
26# not in the Products.*) namespace. For that, see below.
27# All of Plone's products are already set up by PloneTestCase.
28
29@onsetup
30def setup_product():
31    """Set up the package and its dependencies.
32
33    The @onsetup decorator causes the execution of this body to be
34    deferred until the setup of the Plone site testing layer. We could
35    have created our own layer, but this is the easiest way for Plone
36    integration tests.
37    """
38
39    # Load the ZCML configuration for the example.tests package.
40    # This can of course use <include /> to include other packages.
41
42    fiveconfigure.debug_mode = True
43    import quintagroup.seoptimizer
44    zcml.load_config('configure.zcml', quintagroup.seoptimizer)
45    #zcml.load_config('overrides.zcml', quintagroup.seoptimizer)
46    fiveconfigure.debug_mode = False
47
48    # We need to tell the testing framework that these products
49    # should be available. This can't happen until after we have loaded
50    # the ZCML. Thus, we do it here. Note the use of installPackage()
51    # instead of installProduct().
52    # This is *only* necessary for packages outside the Products.*
53    # namespace which are also declared as Zope 2 products, using
54    # <five:registerPackage /> in ZCML.
55
56    # We may also need to load dependencies, e.g.:
57    #   ztc.installPackage('borg.localrole')
58
59    # installPackage - register package in Control_Panel.Products
60    # and results to QI can correctly use install/uninstall external
61    # methods
62    ztc.installPackage(PROJECT_NAME)
63
64# The order here is important: We first call the (deferred) function
65# which installs the products we need for this product. Then, we let
66# PloneTestCase set up this product on installation.
67
68setup_product()
69# Use products to force QI install method usage
70ptc.setupPloneSite(products=[PROJECT_NAME,])
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
84
85class TestCase(MixinTestCase, ptc.PloneTestCase):
86    """We use this base class for all the tests in this package. If
87    necessary, we can put common utility or setup code in here. This
88    applies to unit test cases.
89    """
90
91class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase):
92    """We use this class for functional integration tests that use
93    doctest syntax. Again, we can put basic common utility or setup
94    code in here.
95    """
96
97    #def afterSetUp(self):
98        #roles = ('Member', 'Contributor')
99        #self.portal.portal_membership.addMember('contributor',
100                                                #'secret',
101                                                #roles, [])
102
103#class TestErase(TestCase):
104    ## we use here nested layer for not to make an impact on
105    ## the rest test cases, this test case check uninstall procedure
106    ## thus it has to uninstall package which will be required to
107    ## be installed for other test cases
108    #class layer(PloneSiteLayer):
109        #@classmethod
110        #def setUp(cls):
111            #app = ztc.app()
112            #portal = app.plone
113
114            ## elevate permissions
115            #user = portal.getWrappedOwner()
116            #newSecurityManager(None, user)
117
118            #tool = getToolByName(portal, 'portal_quickinstaller')
119            #if tool.isProductInstalled(PROJECT_NAME):
120                #tool.uninstallProducts([PROJECT_NAME,])
121
122            ## drop elevated perms
123            #noSecurityManager()
124
125            #transaction.commit()
126            #ztc.close(app)
127
Note: See TracBrowser for help on using the repository browser.