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 | import transaction |
---|
10 | from AccessControl.SecurityManagement import newSecurityManager |
---|
11 | |
---|
12 | from Products.Five import zcml |
---|
13 | from Products.Five import fiveconfigure |
---|
14 | |
---|
15 | from Testing import ZopeTestCase as ztc |
---|
16 | |
---|
17 | from Products.CMFCore.utils import getToolByName |
---|
18 | |
---|
19 | from Products.PloneTestCase.layer import onsetup, PloneSite |
---|
20 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
21 | from Products.PloneTestCase import setup as ptc_setup |
---|
22 | |
---|
23 | from Products.PloneTestCase.PloneTestCase import portal_owner |
---|
24 | from Products.PloneTestCase.PloneTestCase import default_user |
---|
25 | from Products.PloneTestCase.PloneTestCase import default_password |
---|
26 | |
---|
27 | from quintagroup.seoptimizer.config import * |
---|
28 | |
---|
29 | ptc.setupPloneSite() |
---|
30 | |
---|
31 | class NotInstalled(PloneSite): |
---|
32 | """ Only package register, without installation into portal |
---|
33 | """ |
---|
34 | |
---|
35 | @classmethod |
---|
36 | def setUp(cls): |
---|
37 | fiveconfigure.debug_mode = True |
---|
38 | import quintagroup.seoptimizer |
---|
39 | zcml.load_config('configure.zcml', quintagroup.seoptimizer) |
---|
40 | #zcml.load_config('overrides.zcml', quintagroup.seoptimizer) |
---|
41 | fiveconfigure.debug_mode = False |
---|
42 | ztc.installPackage(PROJECT_NAME) |
---|
43 | |
---|
44 | |
---|
45 | class Installed(NotInstalled): |
---|
46 | """ Install product into the portal |
---|
47 | """ |
---|
48 | @classmethod |
---|
49 | def setUp(cls): |
---|
50 | app = ztc.app() |
---|
51 | portal = app[ptc_setup.portal_name] |
---|
52 | qi = getattr(portal, 'portal_quickinstaller', None) |
---|
53 | qi.installProduct(PROJECT_NAME) |
---|
54 | transaction.commit() |
---|
55 | |
---|
56 | |
---|
57 | class MixinTestCase: |
---|
58 | |
---|
59 | def _getauth(self): |
---|
60 | # Fix authenticator for the form |
---|
61 | import re |
---|
62 | |
---|
63 | authenticator = self.portal.restrictedTraverse("@@authenticator") |
---|
64 | html = authenticator.authenticator() |
---|
65 | handle = re.search('value="(.*)"', html).groups()[0] |
---|
66 | return handle |
---|
67 | |
---|
68 | |
---|
69 | class TestCase(MixinTestCase, ptc.PloneTestCase): |
---|
70 | layer = Installed |
---|
71 | |
---|
72 | class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase): |
---|
73 | layer = NotInstalled |
---|
74 | |
---|
75 | |
---|
76 | class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase): |
---|
77 | layer = Installed |
---|
78 | |
---|
79 | class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase): |
---|
80 | layer = NotInstalled |
---|