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