source: products/quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/base.py @ 2983

Last change on this file since 2983 was 2983, checked in by kroman0, 13 years ago

Merged last fixes from branches/jquery

File size: 2.5 KB
Line 
1import transaction
2
3from Products.Five import zcml, fiveconfigure
4
5from Testing import ZopeTestCase as ztc
6from AccessControl.SecurityManagement import newSecurityManager, \
7    noSecurityManager
8
9from Products.PloneTestCase import PloneTestCase as ptc
10from Products.PloneTestCase.layer import onsetup, PloneSiteLayer
11from Products.CMFCore.utils import getToolByName
12
13from config import PRODUCT
14
15
16@onsetup
17def setup_product():
18    """Set up additional products and ZCML required to test this product.
19
20    The @onsetup decorator causes the execution of this body to be deferred
21    until the setup of the Plone site testing layer.
22    """
23
24    # Load the ZCML configuration for this package and its dependencies
25
26    fiveconfigure.debug_mode = True
27    import quintagroup.plonecomments
28    zcml.load_config('configure.zcml', quintagroup.plonecomments)
29    zcml.load_config('overrides.zcml', quintagroup.plonecomments)
30    fiveconfigure.debug_mode = False
31
32    # We need to tell the testing framework that these products
33    # should be available. This can't happen until after we have loaded
34    # the ZCML.
35    if not ptc.PLONE31:
36        ztc.installPackage("plone.browserlayer")
37    ztc.installPackage(PRODUCT)
38    transaction.commit()
39
40
41# The order here is important: We first call the deferred function and then
42# let PloneTestCase install it during Plone site setup
43
44setup_product()
45if not ptc.PLONE31:
46    ptc.setupPloneSite(products=["plone.browserlayer", PRODUCT])
47else:
48    ptc.setupPloneSite(products=[PRODUCT])
49
50
51class TestCase(ptc.PloneTestCase):
52    """Base class used for test cases
53    """
54
55
56class FunctionalTestCase(ptc.FunctionalTestCase):
57    """Test case class used for functional (doc-)tests
58    """
59
60
61class TestErase(TestCase):
62    # we use here nested layer for not to make an impact on
63    # the rest test cases, this test case check uninstall procedure
64    # thus it has to uninstall package which will be required to
65    # be installed for other test cases
66    class layer(PloneSiteLayer):
67        @classmethod
68        def setUp(cls):
69            app = ztc.app()
70            portal = app.plone
71
72            # elevate permissions
73            user = portal.getWrappedOwner()
74            newSecurityManager(None, user)
75
76            tool = getToolByName(portal, 'portal_quickinstaller')
77            if tool.isProductInstalled(PRODUCT):
78                tool.uninstallProducts([PRODUCT,])
79
80            # drop elevated perms
81            noSecurityManager()
82
83            transaction.commit()
84            ztc.close(app)
85
Note: See TracBrowser for help on using the repository browser.