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