| [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 |
|---|
| [2139] | 9 | import transaction |
|---|
| 10 | from zope.component import getUtility |
|---|
| [1493] | 11 | |
|---|
| [2139] | 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 Products.Five import zcml |
|---|
| 22 | from Products.Five import fiveconfigure |
|---|
| 23 | |
|---|
| 24 | from Testing import ZopeTestCase as ztc |
|---|
| 25 | |
|---|
| [2139] | 26 | from Products.CMFCore.utils import getToolByName |
|---|
| 27 | |
|---|
| 28 | from Products.PloneTestCase.layer import PloneSite |
|---|
| [1493] | 29 | from Products.PloneTestCase import PloneTestCase as ptc |
|---|
| [2139] | 30 | from Products.PloneTestCase import setup as ptc_setup |
|---|
| [1493] | 31 | |
|---|
| [2139] | 32 | from Products.PloneTestCase.PloneTestCase import portal_owner |
|---|
| 33 | from Products.PloneTestCase.PloneTestCase import default_password |
|---|
| [1493] | 34 | |
|---|
| [2139] | 35 | from quintagroup.seoptimizer.config import PROJECT_NAME |
|---|
| 36 | from quintagroup.seoptimizer.config import SUPPORT_BLAYER |
|---|
| [1493] | 37 | |
|---|
| [2139] | 38 | ptc.setupPloneSite() |
|---|
| [1493] | 39 | |
|---|
| [2139] | 40 | class NotInstalled(PloneSite): |
|---|
| 41 | """ Only package register, without installation into portal |
|---|
| [1493] | 42 | """ |
|---|
| 43 | |
|---|
| [2139] | 44 | @classmethod |
|---|
| 45 | def setUp(cls): |
|---|
| 46 | fiveconfigure.debug_mode = True |
|---|
| 47 | import quintagroup.seoptimizer |
|---|
| 48 | zcml.load_config('configure.zcml', quintagroup.seoptimizer) |
|---|
| 49 | fiveconfigure.debug_mode = False |
|---|
| 50 | ztc.installPackage(PROJECT_NAME) |
|---|
| [1493] | 51 | |
|---|
| 52 | |
|---|
| [2139] | 53 | class Installed(NotInstalled): |
|---|
| 54 | """ Install product into the portal |
|---|
| 55 | """ |
|---|
| 56 | @classmethod |
|---|
| 57 | def setUp(cls): |
|---|
| 58 | app = ztc.app() |
|---|
| 59 | portal = app[ptc_setup.portal_name] |
|---|
| [1493] | 60 | |
|---|
| [2139] | 61 | # Sets the local site/manager |
|---|
| 62 | ptc_setup._placefulSetUp(portal) |
|---|
| 63 | # Install PROJECT |
|---|
| 64 | qi = getattr(portal, 'portal_quickinstaller', None) |
|---|
| [2936] | 65 | if not ptc.PLONE31: |
|---|
| 66 | qi.installProduct("plone.browserlayer") |
|---|
| [2139] | 67 | qi.installProduct(PROJECT_NAME) |
|---|
| 68 | transaction.commit() |
|---|
| [1493] | 69 | |
|---|
| [2139] | 70 | @classmethod |
|---|
| 71 | def tearDown(cls): |
|---|
| 72 | ptc_setup._placefulTearDown() |
|---|
| 73 | |
|---|
| [1493] | 74 | |
|---|
| [2139] | 75 | class MixinTestCase: |
|---|
| [1493] | 76 | |
|---|
| [2139] | 77 | def _getauth(self): |
|---|
| 78 | # Fix authenticator for the form |
|---|
| 79 | import re |
|---|
| 80 | try: |
|---|
| 81 | authenticator = self.portal.restrictedTraverse("@@authenticator") |
|---|
| 82 | except: |
|---|
| 83 | handle = "" |
|---|
| 84 | else: |
|---|
| 85 | html = authenticator.authenticator() |
|---|
| 86 | handle = re.search('value="(.*)"', html).groups()[0] |
|---|
| 87 | return handle |
|---|
| [1493] | 88 | |
|---|
| [2139] | 89 | def beforeTearDown(self): |
|---|
| 90 | getUtility(IRAMCache).invalidateAll() |
|---|
| [1493] | 91 | |
|---|
| [3011] | 92 | def installBrowserLayer(self): |
|---|
| 93 | if not ptc.PLONE31: |
|---|
| 94 | qi = getattr(self.portal, 'portal_quickinstaller', None) |
|---|
| 95 | qi.installProduct("plone.browserlayer") |
|---|
| [1493] | 96 | |
|---|
| [3011] | 97 | |
|---|
| [2139] | 98 | class TestCase(MixinTestCase, ptc.PloneTestCase): |
|---|
| 99 | layer = Installed |
|---|
| [1493] | 100 | |
|---|
| [2139] | 101 | class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase): |
|---|
| 102 | layer = NotInstalled |
|---|
| [1493] | 103 | |
|---|
| 104 | |
|---|
| [2139] | 105 | class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase): |
|---|
| 106 | layer = Installed |
|---|
| [1493] | 107 | |
|---|
| [3011] | 108 | def afterSetUp(self): |
|---|
| 109 | self.installBrowserLayer() |
|---|
| 110 | |
|---|
| [2139] | 111 | class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase): |
|---|
| 112 | layer = NotInstalled |
|---|
| [2936] | 113 | |
|---|
| 114 | def afterSetUp(self): |
|---|
| [3011] | 115 | self.installBrowserLayer() |
|---|