[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 |
---|
[1896] | 9 | import transaction |
---|
[1908] | 10 | from zope.component import getUtility |
---|
| 11 | |
---|
[1938] | 12 | # Starting from plone.memoize v1.1a4 (used in plone4), global ram cache |
---|
| 13 | # utility provides other IRAMCache interface, than before |
---|
| 14 | try: |
---|
| 15 | # In plone4 provides |
---|
| 16 | from zope.ramcache.interfaces.ram import IRAMCache |
---|
| 17 | except ImportError: |
---|
| 18 | # In plone3 provides |
---|
| 19 | from zope.app.cache.interfaces.ram import IRAMCache |
---|
| 20 | |
---|
[1493] | 21 | from AccessControl.SecurityManagement import newSecurityManager |
---|
| 22 | |
---|
| 23 | from Products.Five import zcml |
---|
| 24 | from Products.Five import fiveconfigure |
---|
| 25 | |
---|
| 26 | from Testing import ZopeTestCase as ztc |
---|
| 27 | |
---|
[1877] | 28 | from Products.CMFCore.utils import getToolByName |
---|
| 29 | |
---|
[1896] | 30 | from Products.PloneTestCase.layer import onsetup, PloneSite |
---|
[1493] | 31 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
[1896] | 32 | from Products.PloneTestCase import setup as ptc_setup |
---|
| 33 | |
---|
[1877] | 34 | from Products.PloneTestCase.PloneTestCase import portal_owner |
---|
| 35 | from Products.PloneTestCase.PloneTestCase import default_user |
---|
| 36 | from Products.PloneTestCase.PloneTestCase import default_password |
---|
[1493] | 37 | |
---|
[1877] | 38 | from quintagroup.seoptimizer.config import * |
---|
[1493] | 39 | |
---|
[1896] | 40 | ptc.setupPloneSite() |
---|
[1493] | 41 | |
---|
[1896] | 42 | class NotInstalled(PloneSite): |
---|
| 43 | """ Only package register, without installation into portal |
---|
[1493] | 44 | """ |
---|
| 45 | |
---|
[1896] | 46 | @classmethod |
---|
| 47 | def setUp(cls): |
---|
| 48 | fiveconfigure.debug_mode = True |
---|
| 49 | import quintagroup.seoptimizer |
---|
| 50 | zcml.load_config('configure.zcml', quintagroup.seoptimizer) |
---|
| 51 | #zcml.load_config('overrides.zcml', quintagroup.seoptimizer) |
---|
| 52 | fiveconfigure.debug_mode = False |
---|
| 53 | ztc.installPackage(PROJECT_NAME) |
---|
[1493] | 54 | |
---|
| 55 | |
---|
[1896] | 56 | class Installed(NotInstalled): |
---|
| 57 | """ Install product into the portal |
---|
| 58 | """ |
---|
| 59 | @classmethod |
---|
| 60 | def setUp(cls): |
---|
| 61 | app = ztc.app() |
---|
| 62 | portal = app[ptc_setup.portal_name] |
---|
[1937] | 63 | |
---|
| 64 | # Sets the local site/manager |
---|
| 65 | ptc_setup._placefulSetUp(portal) |
---|
| 66 | # Install PROJECT |
---|
[1896] | 67 | qi = getattr(portal, 'portal_quickinstaller', None) |
---|
| 68 | qi.installProduct(PROJECT_NAME) |
---|
| 69 | transaction.commit() |
---|
[1493] | 70 | |
---|
[1937] | 71 | @classmethod |
---|
| 72 | def tearDown(cls): |
---|
| 73 | ptc_setup._placefulTearDown() |
---|
| 74 | |
---|
[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 | |
---|
[1908] | 87 | def beforeTearDown(self): |
---|
| 88 | getUtility(IRAMCache).invalidateAll() |
---|
[1792] | 89 | |
---|
[1908] | 90 | |
---|
[1792] | 91 | class TestCase(MixinTestCase, ptc.PloneTestCase): |
---|
[1896] | 92 | layer = Installed |
---|
[1493] | 93 | |
---|
[1896] | 94 | class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase): |
---|
| 95 | layer = NotInstalled |
---|
[1493] | 96 | |
---|
| 97 | |
---|
[1896] | 98 | class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase): |
---|
| 99 | layer = Installed |
---|
[1493] | 100 | |
---|
[1896] | 101 | class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase): |
---|
| 102 | layer = NotInstalled |
---|