source: products/quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/tests/base.py @ 2642

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

Initial package import

File size: 3.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"""
8
9from Products.Five import zcml
10from Products.Five import fiveconfigure
11
12from Testing import ZopeTestCase as ztc
13
14from Products.PloneTestCase import PloneTestCase as ptc
15from Products.PloneTestCase.layer import onsetup
16
17# When ZopeTestCase configures Zope, it will *not* auto-load products
18# in Products/. Instead, we have to use a statement such as:
19#   ztc.installProduct('SimpleAttachment')
20# This does *not* apply to products in eggs and Python packages (i.e.
21# not in the Products.*) namespace. For that, see below.
22# All of Plone's products are already set up by PloneTestCase.
23
24@onsetup
25def setup_product():
26    """Set up the package and its dependencies.
27
28    The @onsetup decorator causes the execution of this body to be
29    deferred until the setup of the Plone site testing layer. We could
30    have created our own layer, but this is the easiest way for Plone
31    integration tests.
32    """
33
34    # Load the ZCML configuration for the example.tests package.
35    # This can of course use <include /> to include other packages.
36
37    fiveconfigure.debug_mode = True
38    import quintagroup.gdocs.spreadsheet
39    zcml.load_config('configure.zcml', quintagroup.gdocs.spreadsheet)
40    fiveconfigure.debug_mode = False
41
42    # We need to tell the testing framework that these products
43    # should be available. This can't happen until after we have loaded
44    # the ZCML. Thus, we do it here. Note the use of installPackage()
45    # instead of installProduct().
46    # This is *only* necessary for packages outside the Products.*
47    # namespace which are also declared as Zope 2 products, using
48    # <five:registerPackage /> in ZCML.
49
50    # We may also need to load dependencies, e.g.:
51    #   ztc.installPackage('borg.localrole')
52
53    ztc.installPackage('quintagroup.gdocs.spreadsheet')
54
55# The order here is important: We first call the (deferred) function
56# which installs the products we need for this product. Then, we let
57# PloneTestCase set up this product on installation.
58
59setup_product()
60ptc.setupPloneSite(products=['quintagroup.gdocs.spreadsheet'])
61
62class TestCase(ptc.PloneTestCase):
63    """We use this base class for all the tests in this package. If
64    necessary, we can put common utility or setup code in here. This
65    applies to unit test cases.
66    """
67
68class FunctionalTestCase(ptc.FunctionalTestCase):
69    """We use this class for functional integration tests that use
70    doctest syntax. Again, we can put basic common utility or setup
71    code in here.
72    """
73
74    def afterSetUp(self):
75        roles = ('Member', 'Contributor')
76        self.portal.portal_membership.addMember('contributor',
77                                                'secret',
78                                                roles, [])
Note: See TracBrowser for help on using the repository browser.