source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/base.py @ 1493

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

Modified structure tests

File size: 4.0 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    ztc.installPackage(PROJECT_NAME)
60
61# The order here is important: We first call the (deferred) function
62# which installs the products we need for this product. Then, we let
63# PloneTestCase set up this product on installation.
64
65setup_product()
66ptc.setupPloneSite(products=[PROJECT_NAME])
67
68
69class TestCase(ptc.PloneTestCase):
70    """We use this base class for all the tests in this package. If
71    necessary, we can put common utility or setup code in here. This
72    applies to unit test cases.
73    """
74
75class FunctionalTestCase(ptc.FunctionalTestCase):
76    """We use this class for functional integration tests that use
77    doctest syntax. Again, we can put basic common utility or setup
78    code in here.
79    """
80
81    #def afterSetUp(self):
82        #roles = ('Member', 'Contributor')
83        #self.portal.portal_membership.addMember('contributor',
84                                                #'secret',
85                                                #roles, [])
86
87#class TestErase(TestCase):
88    ## we use here nested layer for not to make an impact on
89    ## the rest test cases, this test case check uninstall procedure
90    ## thus it has to uninstall package which will be required to
91    ## be installed for other test cases
92    #class layer(PloneSiteLayer):
93        #@classmethod
94        #def setUp(cls):
95            #app = ztc.app()
96            #portal = app.plone
97
98            ## elevate permissions
99            #user = portal.getWrappedOwner()
100            #newSecurityManager(None, user)
101
102            #tool = getToolByName(portal, 'portal_quickinstaller')
103            #if tool.isProductInstalled(PROJECT_NAME):
104                #tool.uninstallProducts([PROJECT_NAME,])
105
106            ## drop elevated perms
107            #noSecurityManager()
108
109            #transaction.commit()
110            #ztc.close(app)
111
Note: See TracBrowser for help on using the repository browser.