Skip to content

Commit

Permalink
Rudimentary test for the invalid csrf token error view.
Browse files Browse the repository at this point in the history
  • Loading branch information
janwijbrand committed Nov 20, 2013
1 parent c440a42 commit c325af0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/zope/formlib/errors.py
Expand Up @@ -64,7 +64,11 @@ def update(self):
'Pragma', 'no-cache')

def render(self):
msg = self.context.doc
msg = self.context.args[0]
if isinstance(msg, Message):
msg = translate(msg, context=self.request)
return escape(msg)

def __call__(self):
self.update()
return self.render()
10 changes: 10 additions & 0 deletions src/zope/formlib/form.txt
Expand Up @@ -2182,3 +2182,13 @@ We can indeed submit data to the forms::
>>> multi = MultiForm(None, request)
>>> _ = multi()
Action: handle in Form Two

There is a view for the InvalidCSRFTokenError::

>>> from zope.component import getMultiAdapter
>>> from zope.formlib.interfaces import InvalidCSRFTokenError
>>> from zope.formlib.errors import InvalidCSRFTokenErrorView
>>> error = InvalidCSRFTokenError('Invalid CSRF token')
>>> request = TestRequest()
>>> print(InvalidCSRFTokenErrorView(error, request)())
Invalid CSRF token

0 comments on commit c325af0

Please sign in to comment.