[1493] | 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 | import re |
---|
| 9 | from AccessControl.SecurityManagement import newSecurityManager |
---|
| 10 | |
---|
| 11 | from Products.Five import zcml |
---|
| 12 | from Products.Five import fiveconfigure |
---|
| 13 | |
---|
| 14 | from Testing import ZopeTestCase as ztc |
---|
| 15 | |
---|
[1877] | 16 | from Products.CMFCore.utils import getToolByName |
---|
| 17 | |
---|
| 18 | from Products.PloneTestCase.layer import onsetup |
---|
[1493] | 19 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
[1877] | 20 | from Products.PloneTestCase.PloneTestCase import portal_owner |
---|
| 21 | from Products.PloneTestCase.PloneTestCase import default_user |
---|
| 22 | from Products.PloneTestCase.PloneTestCase import default_password |
---|
[1493] | 23 | |
---|
[1877] | 24 | from quintagroup.seoptimizer.config import * |
---|
[1493] | 25 | |
---|
| 26 | # When ZopeTestCase configures Zope, it will *not* auto-load products |
---|
| 27 | # in Products/. Instead, we have to use a statement such as: |
---|
| 28 | # ztc.installProduct('SimpleAttachment') |
---|
| 29 | # This does *not* apply to products in eggs and Python packages (i.e. |
---|
| 30 | # not in the Products.*) namespace. For that, see below. |
---|
| 31 | # All of Plone's products are already set up by PloneTestCase. |
---|
| 32 | |
---|
| 33 | @onsetup |
---|
| 34 | def setup_product(): |
---|
| 35 | """Set up the package and its dependencies. |
---|
| 36 | |
---|
| 37 | The @onsetup decorator causes the execution of this body to be |
---|
| 38 | deferred until the setup of the Plone site testing layer. We could |
---|
| 39 | have created our own layer, but this is the easiest way for Plone |
---|
| 40 | integration tests. |
---|
| 41 | """ |
---|
| 42 | |
---|
| 43 | # Load the ZCML configuration for the example.tests package. |
---|
| 44 | # This can of course use <include /> to include other packages. |
---|
| 45 | |
---|
| 46 | fiveconfigure.debug_mode = True |
---|
| 47 | import quintagroup.seoptimizer |
---|
| 48 | zcml.load_config('configure.zcml', quintagroup.seoptimizer) |
---|
[1779] | 49 | #zcml.load_config('overrides.zcml', quintagroup.seoptimizer) |
---|
[1493] | 50 | fiveconfigure.debug_mode = False |
---|
| 51 | |
---|
| 52 | # We need to tell the testing framework that these products |
---|
| 53 | # should be available. This can't happen until after we have loaded |
---|
| 54 | # the ZCML. Thus, we do it here. Note the use of installPackage() |
---|
| 55 | # instead of installProduct(). |
---|
| 56 | # This is *only* necessary for packages outside the Products.* |
---|
| 57 | # namespace which are also declared as Zope 2 products, using |
---|
| 58 | # <five:registerPackage /> in ZCML. |
---|
| 59 | |
---|
| 60 | # We may also need to load dependencies, e.g.: |
---|
| 61 | # ztc.installPackage('borg.localrole') |
---|
| 62 | |
---|
[1833] | 63 | # installPackage - register package in Control_Panel.Products |
---|
| 64 | # and results to QI can correctly use install/uninstall external |
---|
| 65 | # methods |
---|
[1493] | 66 | ztc.installPackage(PROJECT_NAME) |
---|
| 67 | |
---|
| 68 | # The order here is important: We first call the (deferred) function |
---|
| 69 | # which installs the products we need for this product. Then, we let |
---|
| 70 | # PloneTestCase set up this product on installation. |
---|
| 71 | |
---|
| 72 | setup_product() |
---|
[1854] | 73 | # Use products to force QI install method usage |
---|
| 74 | ptc.setupPloneSite(products=[PROJECT_NAME,]) |
---|
[1493] | 75 | |
---|
[1792] | 76 | class MixinTestCase: |
---|
[1493] | 77 | |
---|
[1792] | 78 | def _getauth(self): |
---|
| 79 | # Fix authenticator for the form |
---|
| 80 | import re |
---|
| 81 | |
---|
| 82 | authenticator = self.portal.restrictedTraverse("@@authenticator") |
---|
| 83 | html = authenticator.authenticator() |
---|
| 84 | handle = re.search('value="(.*)"', html).groups()[0] |
---|
| 85 | return handle |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | class TestCase(MixinTestCase, ptc.PloneTestCase): |
---|
[1493] | 90 | """We use this base class for all the tests in this package. If |
---|
| 91 | necessary, we can put common utility or setup code in here. This |
---|
| 92 | applies to unit test cases. |
---|
| 93 | """ |
---|
| 94 | |
---|
[1792] | 95 | class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase): |
---|
[1493] | 96 | """We use this class for functional integration tests that use |
---|
| 97 | doctest syntax. Again, we can put basic common utility or setup |
---|
| 98 | code in here. |
---|
| 99 | """ |
---|
| 100 | |
---|
| 101 | #def afterSetUp(self): |
---|
| 102 | #roles = ('Member', 'Contributor') |
---|
| 103 | #self.portal.portal_membership.addMember('contributor', |
---|
| 104 | #'secret', |
---|
| 105 | #roles, []) |
---|
| 106 | |
---|
| 107 | #class TestErase(TestCase): |
---|
| 108 | ## we use here nested layer for not to make an impact on |
---|
| 109 | ## the rest test cases, this test case check uninstall procedure |
---|
| 110 | ## thus it has to uninstall package which will be required to |
---|
| 111 | ## be installed for other test cases |
---|
| 112 | #class layer(PloneSiteLayer): |
---|
| 113 | #@classmethod |
---|
| 114 | #def setUp(cls): |
---|
| 115 | #app = ztc.app() |
---|
| 116 | #portal = app.plone |
---|
| 117 | |
---|
| 118 | ## elevate permissions |
---|
| 119 | #user = portal.getWrappedOwner() |
---|
| 120 | #newSecurityManager(None, user) |
---|
| 121 | |
---|
| 122 | #tool = getToolByName(portal, 'portal_quickinstaller') |
---|
| 123 | #if tool.isProductInstalled(PROJECT_NAME): |
---|
| 124 | #tool.uninstallProducts([PROJECT_NAME,]) |
---|
| 125 | |
---|
| 126 | ## drop elevated perms |
---|
| 127 | #noSecurityManager() |
---|
| 128 | |
---|
| 129 | #transaction.commit() |
---|
| 130 | #ztc.close(app) |
---|
| 131 | |
---|