source: products/quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/tests/test_doctests.py @ 2806

Last change on this file since 2806 was 2806, checked in by mylan, 14 years ago

#195: Added captcha field validation test in doctests

  • Property svn:eol-style set to native
File size: 1.9 KB
RevLine 
[2801]1import unittest
2import doctest
3
4from zope.interface import Interface
5
6from Products.Five import zcml
7from Products.Five import fiveconfigure
8
9from Products.PloneTestCase import PloneTestCase as ptc
10from Products.PloneTestCase.layer import PloneSite
11from Testing import ZopeTestCase as ztc
12
[2806]13from quintagroup.captcha.core.utils import *
14from quintagroup.captcha.core.tests.base import testPatch
15from quintagroup.captcha.core.tests.testWidget import addTestLayer
16
[2801]17class FormlibCaptchaLayer(PloneSite):
18    @classmethod
19    def setUp(cls):
20        fiveconfigure.debug_mode = True
21        import quintagroup.captcha.core
22        import quintagroup.formlib.captcha
23        zcml.load_config('configure.zcml', quintagroup.formlib.captcha)
24        zcml.load_config('tests.zcml', quintagroup.formlib.captcha.tests)
25        fiveconfigure.debug_mode = False
26        ztc.installPackage('quintagroup.captcha.core')
27
28    @classmethod
29    def tearDown(cls):
30        pass
31   
32ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default',])
33
34class 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)
46        self.captcha_word = getWord(int(parseKey(decrypted)['key'])-1 )
47
48
[2801]49def 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,
56            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE | doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS),
57           
58        ])
59
60if __name__ == '__main__':
61    unittest.main(defaultTest='test_suite')
Note: See TracBrowser for help on using the repository browser.