fix captcha doctest.
svn path=/plone.formwidget.captcha/trunk/; revision=28683
This commit is contained in:
parent
7b84594b31
commit
45f564e81f
|
@ -9,7 +9,7 @@ To use the captcha view, simply look up the view using the component architectur
|
|||
|
||||
Here, we'll just import the view directly to demonstrate it's use:
|
||||
|
||||
>>> from collective.captcha.browser.captcha import Captcha, COOKIE_ID
|
||||
>>> from plone.formwidget.captcha.browser.captcha import Captcha, COOKIE_ID
|
||||
>>> request = DummyRequest()
|
||||
>>> context = DummyContext()
|
||||
>>> view = Captcha(context, request)
|
||||
|
@ -25,7 +25,7 @@ The request now holds the state in a cookie:
|
|||
|
||||
>>> COOKIE_ID in request.response.cookies
|
||||
True
|
||||
|
||||
|
||||
Verification
|
||||
------------
|
||||
|
||||
|
@ -40,23 +40,23 @@ The verify method, then, tells you if the user entered the correct word:
|
|||
|
||||
>>> view.verify('DLXV4XV')
|
||||
True
|
||||
|
||||
|
||||
Note that the view immediately invalidates the cookie by expiring it:
|
||||
|
||||
>>> request.response.cookies[COOKIE_ID].get('expires', '')
|
||||
'Wed, 31-Dec-97 23:59:59 GMT'
|
||||
|
||||
|
||||
The verify method works case-insensitively:
|
||||
|
||||
>>> view.verify('dlxv4xv')
|
||||
True
|
||||
|
||||
|
||||
The words are valid for a 10 minute period, with a new word for the session every
|
||||
5 minutes. Thus, the word for the previous 5 minute period should still be valid:
|
||||
|
||||
>>> view.verify('YMFRQWT')
|
||||
True
|
||||
|
||||
|
||||
Verification will fail for both incorrect input and a missing cookie:
|
||||
|
||||
>>> view.verify('incorrect')
|
||||
|
@ -67,8 +67,8 @@ Verification will fail for both incorrect input and a missing cookie:
|
|||
>>> view.verify('DLXV4XV')
|
||||
False
|
||||
|
||||
To facilitate displaying a new captcha when verification fails or validation
|
||||
of a form fails for other reasons, the view makes sure to not expire the
|
||||
To facilitate displaying a new captcha when verification fails or validation
|
||||
of a form fails for other reasons, the view makes sure to not expire the
|
||||
cookie but to set a new value instead:
|
||||
|
||||
>>> request = DummyRequest()
|
||||
|
@ -89,7 +89,7 @@ cookie but to set a new value instead:
|
|||
Displaying
|
||||
----------
|
||||
|
||||
The point of course is that the end-user gets to view the captcha image or listen to the
|
||||
The point of course is that the end-user gets to view the captcha image or listen to the
|
||||
audio file:
|
||||
|
||||
>>> request = DummyRequest()
|
||||
|
|
|
@ -4,7 +4,7 @@ from zope.testing import doctest, cleanup
|
|||
from plone.keyring.interfaces import IKeyManager
|
||||
|
||||
# Set the secret and test time to constants to keep the tests workable
|
||||
import collective.captcha.browser.captcha as captcha
|
||||
import plone.formwidget.captcha.browser.captcha as captcha
|
||||
captcha._TEST_TIME = 5
|
||||
|
||||
# Use a real Request and Response; there are too many subtleties
|
||||
|
@ -17,7 +17,7 @@ class DummyRequest(Request):
|
|||
'SERVER_PORT': '80',
|
||||
'REQUEST_METHOD': 'GET'}
|
||||
Request.__init__(self, None, env, Response())
|
||||
|
||||
|
||||
class DummyContext(object):
|
||||
def absolute_url(self):
|
||||
return 'dummyurl'
|
||||
|
|
Reference in New Issue