~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to tests/regressiontests/forms/util.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
Import upstream version 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
tests = r"""
7
7
>>> from django.forms.util import *
 
8
>>> from django.core.exceptions import ValidationError
8
9
>>> from django.utils.translation import ugettext_lazy
9
10
 
10
11
###########
24
25
###################
25
26
 
26
27
# Can take a string.
27
 
>>> print ValidationError("There was an error.").messages
 
28
>>> print ErrorList(ValidationError("There was an error.").messages)
28
29
<ul class="errorlist"><li>There was an error.</li></ul>
29
30
 
30
31
# Can take a unicode string.
31
 
>>> print ValidationError(u"Not \u03C0.").messages
 
32
>>> print ErrorList(ValidationError(u"Not \u03C0.").messages)
32
33
<ul class="errorlist"><li>Not π.</li></ul>
33
34
 
34
35
# Can take a lazy string.
35
 
>>> print ValidationError(ugettext_lazy("Error.")).messages
 
36
>>> print ErrorList(ValidationError(ugettext_lazy("Error.")).messages)
36
37
<ul class="errorlist"><li>Error.</li></ul>
37
38
 
38
39
# Can take a list.
39
 
>>> print ValidationError(["Error one.", "Error two."]).messages
 
40
>>> print ErrorList(ValidationError(["Error one.", "Error two."]).messages)
40
41
<ul class="errorlist"><li>Error one.</li><li>Error two.</li></ul>
41
42
 
42
43
# Can take a mixture in a list.
43
 
>>> print ValidationError(["First error.", u"Not \u03C0.", ugettext_lazy("Error.")]).messages
 
44
>>> print ErrorList(ValidationError(["First error.", u"Not \u03C0.", ugettext_lazy("Error.")]).messages)
44
45
<ul class="errorlist"><li>First error.</li><li>Not π.</li><li>Error.</li></ul>
45
46
 
46
47
>>> class VeryBadError:
47
48
...     def __unicode__(self): return u"A very bad error."
48
49
 
49
50
# Can take a non-string.
50
 
>>> print ValidationError(VeryBadError()).messages
 
51
>>> print ErrorList(ValidationError(VeryBadError()).messages)
51
52
<ul class="errorlist"><li>A very bad error.</li></ul>
52
53
 
53
54
# Escapes non-safe input but not input marked safe.
54
55
>>> example = 'Example of link: <a href="http://www.example.com/">example</a>'
55
 
>>> print ValidationError(example).messages
 
56
>>> print ErrorList([example])
56
57
<ul class="errorlist"><li>Example of link: &lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;</li></ul>
57
 
>>> print ValidationError(mark_safe(example)).messages
 
58
>>> print ErrorList([mark_safe(example)])
58
59
<ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul>
59
60
"""