diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-09-15 21:21:37 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-09-15 21:21:37 +0000 |
| commit | fb6a0c8ffa1cd74c63aaf4b011665e5952d449e7 (patch) | |
| tree | 4af2f7d6a2d1d91adf80243c67176effecf0c8b8 /tests/regressiontests/forms/tests.py | |
| parent | c8f6e485b8b7329418ca030421b9bde4ec164854 (diff) | |
queryset-refactor: Merged to [6155]
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6332 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms/tests.py')
| -rw-r--r-- | tests/regressiontests/forms/tests.py | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 0df3ee3858..b0a64a7854 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from localflavor import localflavor_tests from regressions import regression_tests +from util import util_tests form_tests = r""" >>> from django.newforms import * @@ -1606,10 +1607,18 @@ ValidationError: [u'This field is required.'] Traceback (most recent call last): ... ValidationError: [u'This field is required.'] +>>> f.clean('http://localhost') +u'http://localhost' >>> f.clean('http://example.com') u'http://example.com' >>> f.clean('http://www.example.com') u'http://www.example.com' +>>> f.clean('http://www.example.com:8000/test') +u'http://www.example.com:8000/test' +>>> f.clean('http://200.8.9.10') +u'http://200.8.9.10' +>>> f.clean('http://200.8.9.10:8000/test') +u'http://200.8.9.10:8000/test' >>> f.clean('foo') Traceback (most recent call last): ... @@ -3794,14 +3803,6 @@ u'1' >>> smart_unicode('foo') u'foo' -# flatatt tests ->>> from django.newforms.util import flatatt ->>> flatatt({'id': "header"}) -u' id="header"' ->>> flatatt({'class': "news", 'title': "Read this"}) -u' class="news" title="Read this"' ->>> flatatt({}) -u'' #################################### # Test accessing errors in clean() # @@ -3821,12 +3822,38 @@ u'' True >>> f.cleaned_data['username'] u'sirrobin' + +####################################### +# Test overriding ErrorList in a form # +####################################### + +>>> from django.newforms.util import ErrorList +>>> class DivErrorList(ErrorList): +... def __unicode__(self): +... return self.as_divs() +... def as_divs(self): +... if not self: return u'' +... return u'<div class="errorlist">%s</div>' % ''.join([u'<div class="error">%s</div>' % e for e in self]) +>>> class CommentForm(Form): +... name = CharField(max_length=50, required=False) +... email = EmailField() +... comment = CharField() +>>> data = dict(email='invalid') +>>> f = CommentForm(data, auto_id=False, error_class=DivErrorList) +>>> print f.as_p() +<p>Name: <input type="text" name="name" maxlength="50" /></p> +<div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div> +<p>Email: <input type="text" name="email" value="invalid" /></p> +<div class="errorlist"><div class="error">This field is required.</div></div> +<p>Comment: <input type="text" name="comment" /></p> + """ __test__ = { 'form_tests': form_tests, 'localflavor': localflavor_tests, 'regressions': regression_tests, + 'util_tests': util_tests, } if __name__ == "__main__": |
