1 | import os, sys, re |
---|
2 | import unittest |
---|
3 | import transaction |
---|
4 | |
---|
5 | from Products.Five import zcml |
---|
6 | from Products.Five import fiveconfigure |
---|
7 | |
---|
8 | from Testing import ZopeTestCase as ztc |
---|
9 | |
---|
10 | from Products.PloneTestCase import setup as ptc_setup |
---|
11 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
12 | from Products.PloneTestCase.layer import onsetup, PloneSite |
---|
13 | from Products.PloneTestCase.PloneTestCase import portal_owner |
---|
14 | from Products.PloneTestCase.PloneTestCase import default_password |
---|
15 | |
---|
16 | from Products.CMFCore.utils import getToolByName |
---|
17 | |
---|
18 | from quintagroup.captcha.core.tests.base import testPatch |
---|
19 | from quintagroup.captcha.core.tests.testWidget import NOT_VALID |
---|
20 | from quintagroup.captcha.core.tests.testWidget import IMAGE_PATT |
---|
21 | from quintagroup.captcha.core.tests.testWidget import addTestLayer |
---|
22 | from quintagroup.captcha.core.utils import getWord, decrypt, parseKey |
---|
23 | |
---|
24 | from quintagroup.plonecaptchas.config import * |
---|
25 | |
---|
26 | # TESTING CONSTANTS |
---|
27 | CAPTCHA_KEY = 'captcha_key' |
---|
28 | CAPTCHAS_COUNT = 165 |
---|
29 | LAYERS = ['captchas_discussion', 'captchas_sendto_form', 'captchas_join_form'] |
---|
30 | |
---|
31 | TOOL_ICON = 'skins/plone_captchas/tool.gif' |
---|
32 | TOOL_ID = 'portal_captchas' |
---|
33 | CONFIGLET_ID = "qpc_tool" |
---|
34 | PROPERTY_SHEET = 'qPloneCaptchas' |
---|
35 | |
---|
36 | # join_form profile prefix |
---|
37 | JF_PROFILE_PREFIX = 'profile-quintagroup.plonecaptchas:join_form_plone_' |
---|
38 | |
---|
39 | ptc.setupPloneSite() |
---|
40 | |
---|
41 | class NotInstalled(PloneSite): |
---|
42 | """ Only package register, without installation into portal |
---|
43 | """ |
---|
44 | |
---|
45 | @classmethod |
---|
46 | def setUp(cls): |
---|
47 | fiveconfigure.debug_mode = True |
---|
48 | import quintagroup.captcha.core |
---|
49 | import quintagroup.plonecaptchas |
---|
50 | zcml.load_config('configure.zcml', quintagroup.captcha.core) |
---|
51 | zcml.load_config('configure.zcml', quintagroup.plonecaptchas) |
---|
52 | fiveconfigure.debug_mode = False |
---|
53 | ztc.installPackage('quintagroup.plonecaptchas') |
---|
54 | ztc.installPackage('quintagroup.captcha.core') |
---|
55 | |
---|
56 | |
---|
57 | class Installed(NotInstalled): |
---|
58 | """ Install product into the portal |
---|
59 | """ |
---|
60 | @classmethod |
---|
61 | def setUp(cls): |
---|
62 | app = ztc.app() |
---|
63 | portal = app[ptc_setup.portal_name] |
---|
64 | |
---|
65 | # Sets the local site/manager |
---|
66 | ptc_setup._placefulSetUp(portal) |
---|
67 | # Install PROJECT |
---|
68 | qi = getattr(portal, 'portal_quickinstaller', None) |
---|
69 | qi.installProduct(PRODUCT_NAME) |
---|
70 | |
---|
71 | # Install Join Form layer, depends on Plone version |
---|
72 | js_layer = None |
---|
73 | if getattr(ptc_setup, 'PLONE33', 0): |
---|
74 | js_layer = JF_PROFILE_PREFIX+'33' |
---|
75 | elif getattr(ptc_setup, 'PLONE32', 0): |
---|
76 | js_layer = JF_PROFILE_PREFIX+'31_32' |
---|
77 | elif getattr(ptc_setup, 'PLONE31', 0): |
---|
78 | js_layer = JF_PROFILE_PREFIX+'31_32' |
---|
79 | elif getattr(ptc_setup, 'PLONE30', 0): |
---|
80 | js_layer = JF_PROFILE_PREFIX+'30' |
---|
81 | if js_layer is not None: |
---|
82 | gs = getattr(portal, 'portal_setup', None) |
---|
83 | gs.runAllImportStepsFromProfile(js_layer) |
---|
84 | |
---|
85 | transaction.commit() |
---|
86 | |
---|
87 | @classmethod |
---|
88 | def tearDown(cls): |
---|
89 | ptc_setup._placefulTearDown() |
---|
90 | |
---|
91 | |
---|
92 | class TestCase(ptc.PloneTestCase): |
---|
93 | layer = Installed |
---|
94 | |
---|
95 | class TestCaseNotInstalled(ptc.PloneTestCase): |
---|
96 | layer = NotInstalled |
---|
97 | |
---|
98 | |
---|
99 | class FunctionalTestCase(ptc.FunctionalTestCase): |
---|
100 | layer = Installed |
---|
101 | |
---|
102 | class FunctionalTestCaseNotInstalled(ptc.FunctionalTestCase): |
---|
103 | layer = NotInstalled |
---|