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