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

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

Edited doc tests created ZopeSkel?

File size: 3.1 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
24PROJECT_NAME = 'quintagroup.gdocs.spreadsheet'
25
26@onsetup
27def setup_product():
28    """Set up the package and its dependencies.
29
30    The @onsetup decorator causes the execution of this body to be
31    deferred until the setup of the Plone site testing layer. We could
32    have created our own layer, but this is the easiest way for Plone
33    integration tests.
34    """
35
36    # Load the ZCML configuration for the example.tests package.
37    # This can of course use <include /> to include other packages.
38
39    fiveconfigure.debug_mode = True
40    import quintagroup.gdocs.spreadsheet
41    import quintagroup.gauth
42    import Products.DataGridField
43    zcml.load_config('configure.zcml', quintagroup.gdocs.spreadsheet)
44    zcml.load_config('configure.zcml', quintagroup.gauth)
45    zcml.load_config('configure.zcml', Products.DataGridField)
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
68class TestCase(ptc.PloneTestCase):
69    """We use this base class for all the tests in this package. If
70    necessary, we can put common utility or setup code in here. This
71    applies to unit test cases.
72    """
73
74class FunctionalTestCase(ptc.FunctionalTestCase):
75    """We use this class for functional integration tests that use
76    doctest syntax. Again, we can put basic common utility or setup
77    code in here.
78    """
79
80    def afterSetUp(self):
81        roles = ('Member', 'Contributor')
82        self.portal.portal_membership.addMember('contributor',
83                                                'secret',
84                                                roles, [])
Note: See TracBrowser for help on using the repository browser.