Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…rectly and ZAPostCodeField didn't respect *args or **kwargs (such as required=False). Also converted South African localflavor doctests into unittests. We have always been at war with doctests. Thanks to Idan Gazit. Fixing ZA localflavor clean() #14872 git-svn-id: http://code.djangoproject.com/svn/django/trunk@14956 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
Showing
5 changed files
with
32 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
# -*- coding: utf-8 -*- | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,29 @@ | ||
tests = r""" | ||
# ZAIDField ################################################################# | ||
from django.contrib.localflavor.za.forms import ZAIDField, ZAPostCodeField | ||
|
||
ZAIDField validates that the date is a valid birthdate and that the value | ||
has a valid checksum. It allows spaces and dashes, and returns a plain | ||
string of digits. | ||
>>> from django.contrib.localflavor.za.forms import ZAIDField | ||
>>> f = ZAIDField() | ||
>>> f.clean('0002290001003') | ||
'0002290001003' | ||
>>> f.clean('000229 0001 003') | ||
'0002290001003' | ||
>>> f.clean('0102290001001') | ||
Traceback (most recent call last): | ||
... | ||
ValidationError: [u'Enter a valid South African ID number'] | ||
>>> f.clean('811208') | ||
Traceback (most recent call last): | ||
... | ||
ValidationError: [u'Enter a valid South African ID number'] | ||
>>> f.clean('0002290001004') | ||
Traceback (most recent call last): | ||
... | ||
ValidationError: [u'Enter a valid South African ID number'] | ||
from utils import LocalFlavorTestCase | ||
|
||
# ZAPostCodeField ########################################################### | ||
>>> from django.contrib.localflavor.za.forms import ZAPostCodeField | ||
>>> f = ZAPostCodeField() | ||
>>> f.clean('abcd') | ||
Traceback (most recent call last): | ||
... | ||
ValidationError: [u'Enter a valid South African postal code'] | ||
>>> f.clean('0000') | ||
u'0000' | ||
>>> f.clean(' 7530') | ||
Traceback (most recent call last): | ||
... | ||
ValidationError: [u'Enter a valid South African postal code'] | ||
|
||
""" | ||
class ZALocalFlavorTests(LocalFlavorTestCase): | ||
def test_ZAIDField(self): | ||
error_invalid = [u'Enter a valid South African ID number'] | ||
valid = { | ||
'0002290001003': '0002290001003', | ||
'000229 0001 003': '0002290001003', | ||
} | ||
invalid = { | ||
'0102290001001': error_invalid, | ||
'811208': error_invalid, | ||
'0002290001004': error_invalid, | ||
} | ||
self.assertFieldOutput(ZAIDField, valid, invalid) | ||
|
||
def test_ZAPostCodeField(self): | ||
error_invalid = [u'Enter a valid South African postal code'] | ||
valid = { | ||
'0000': '0000', | ||
} | ||
invalid = { | ||
'abcd': error_invalid, | ||
' 7530': error_invalid, | ||
} | ||
self.assertFieldOutput(ZAPostCodeField, valid, invalid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,5 @@ | |
UKLocalFlavorTests, | ||
USLocalFlavorTests, | ||
UYLocalFlavorTests, | ||
ZALocalFlavorTests, | ||
) |