summaryrefslogtreecommitdiff
path: root/tests/regressiontests/forms
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-02-15 21:26:43 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-02-15 21:26:43 +0000
commit1d5e974a4f2e116a1530c24e6df54449b8ef3c98 (patch)
treec49fd08cc8a1dffa30f76daadc7714e46103e612 /tests/regressiontests/forms
parentc96d1555897997676eb7699b8a1752e57a7b1e57 (diff)
Fixed #3503 -- Added newforms UKPostcodeField in django.contrib.localflavor.uk. Thanks for the patch, Jonathan Buchanan
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4527 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms')
-rw-r--r--tests/regressiontests/forms/tests.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py
index 63cb2f927e..5bd56109a1 100644
--- a/tests/regressiontests/forms/tests.py
+++ b/tests/regressiontests/forms/tests.py
@@ -3327,6 +3327,50 @@ u''
>>> f.clean('')
u''
+# UKPostcodeField ##############################################################
+
+UKPostcodeField validates that the data is a valid UK postcode.
+>>> from django.contrib.localflavor.uk.forms import UKPostcodeField
+>>> f = UKPostcodeField()
+>>> f.clean('BT32 4PX')
+u'BT32 4PX'
+>>> f.clean('GIR 0AA')
+u'GIR 0AA'
+>>> f.clean('BT324PX')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.']
+>>> f.clean('1NV 4L1D')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.']
+>>> f.clean(None)
+Traceback (most recent call last):
+...
+ValidationError: [u'This field is required.']
+>>> f.clean('')
+Traceback (most recent call last):
+...
+ValidationError: [u'This field is required.']
+
+>>> f = UKPostcodeField(required=False)
+>>> f.clean('BT32 4PX')
+u'BT32 4PX'
+>>> f.clean('GIR 0AA')
+u'GIR 0AA'
+>>> f.clean('1NV 4L1D')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.']
+>>> f.clean('BT324PX')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a postcode. A space is required between the two postcode parts.']
+>>> f.clean(None)
+u''
+>>> f.clean('')
+u''
+
#################################
# Tests of underlying functions #
#################################