[2642] | 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 | |
---|
[2708] | 24 | PROJECT_NAME = 'quintagroup.gdocs.spreadsheet' |
---|
| 25 | |
---|
[2642] | 26 | @onsetup |
---|
| 27 | def 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 |
---|
[2708] | 41 | import quintagroup.gauth |
---|
| 42 | import Products.DataGridField |
---|
[2642] | 43 | zcml.load_config('configure.zcml', quintagroup.gdocs.spreadsheet) |
---|
[2708] | 44 | zcml.load_config('configure.zcml', quintagroup.gauth) |
---|
| 45 | zcml.load_config('configure.zcml', Products.DataGridField) |
---|
[2642] | 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 | |
---|
[2708] | 59 | ztc.installPackage(PROJECT_NAME) |
---|
[2642] | 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 | |
---|
| 65 | setup_product() |
---|
[2708] | 66 | ptc.setupPloneSite(products=[PROJECT_NAME]) |
---|
[2642] | 67 | |
---|
| 68 | class 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 | |
---|
| 74 | class 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, []) |
---|