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

Last change on this file since 1877 was 1877, checked in by mylan, 10 years ago

Remove config module from tests, move all constants into testInstallation and testResponce modules

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