1 | import unittest |
---|
2 | import doctest |
---|
3 | |
---|
4 | from zope.interface import Interface |
---|
5 | |
---|
6 | from Products.Five import zcml |
---|
7 | from Products.Five import fiveconfigure |
---|
8 | |
---|
9 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
10 | from Products.PloneTestCase.layer import PloneSite |
---|
11 | from Testing import ZopeTestCase as ztc |
---|
12 | |
---|
13 | from quintagroup.captcha.core.utils import * |
---|
14 | from quintagroup.captcha.core.tests.base import testPatch |
---|
15 | from quintagroup.captcha.core.tests.testWidget import addTestLayer |
---|
16 | |
---|
17 | |
---|
18 | class FormlibCaptchaLayer(PloneSite): |
---|
19 | @classmethod |
---|
20 | def setUp(cls): |
---|
21 | fiveconfigure.debug_mode = True |
---|
22 | import quintagroup.captcha.core |
---|
23 | import quintagroup.formlib.captcha |
---|
24 | zcml.load_config('configure.zcml', quintagroup.formlib.captcha) |
---|
25 | zcml.load_config('tests.zcml', quintagroup.formlib.captcha.tests) |
---|
26 | fiveconfigure.debug_mode = False |
---|
27 | ztc.installPackage('quintagroup.captcha.core') |
---|
28 | |
---|
29 | @classmethod |
---|
30 | def tearDown(cls): |
---|
31 | pass |
---|
32 | |
---|
33 | ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default', ]) |
---|
34 | |
---|
35 | |
---|
36 | class FormlibCaptchaTestCase(ptc.FunctionalTestCase): |
---|
37 | layer = FormlibCaptchaLayer |
---|
38 | |
---|
39 | def afterSetUp(self): |
---|
40 | # prepare context |
---|
41 | self.loginAsPortalOwner() |
---|
42 | testPatch() |
---|
43 | addTestLayer(self) |
---|
44 | # prepare captcha data |
---|
45 | captcha_key = self.portal.captcha_key |
---|
46 | self.hashkey = self.portal.getCaptcha() |
---|
47 | decrypted = decrypt(captcha_key, self.hashkey) |
---|
48 | self.captcha_word = getWord(int(parseKey(decrypted)['key']) - 1) |
---|
49 | |
---|
50 | |
---|
51 | def test_suite(): |
---|
52 | return unittest.TestSuite([ |
---|
53 | |
---|
54 | # Demonstrate the main content types |
---|
55 | ztc.ZopeDocFileSuite( |
---|
56 | 'README.txt', package='quintagroup.formlib.captcha', |
---|
57 | test_class=FormlibCaptchaTestCase, |
---|
58 | optionflags=doctest.REPORT_ONLY_FIRST_FAILURE | \ |
---|
59 | doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS), |
---|
60 | ]) |
---|
61 | |
---|
62 | if __name__ == '__main__': |
---|
63 | unittest.main(defaultTest='test_suite') |
---|