Converted Japanese localflavor doctests to unittests. We have always been at war with doctests. Thanks to Idan Gazit.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14946 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f8caeefff1
commit
6e3be3b578
|
@ -1,60 +1,13 @@
|
||||||
# -*- coding: utf-8 -*-
|
from django.contrib.localflavor.jp.forms import (JPPostalCodeField,
|
||||||
# Tests for the contrib/localflavor/ JP form fields.
|
JPPrefectureSelect)
|
||||||
|
|
||||||
tests = r"""
|
from utils import LocalFlavorTestCase
|
||||||
# JPPostalCodeField ###############################################################
|
|
||||||
|
|
||||||
A form field that validates its input is a Japanese postcode.
|
|
||||||
|
|
||||||
Accepts 7 digits(with/out hyphen).
|
class JPLocalFlavorTests(LocalFlavorTestCase):
|
||||||
>>> from django.contrib.localflavor.jp.forms import JPPostalCodeField
|
def test_JPPrefectureSelect(self):
|
||||||
>>> f = JPPostalCodeField()
|
f = JPPrefectureSelect()
|
||||||
>>> f.clean('251-0032')
|
out = u'''<select name="prefecture">
|
||||||
u'2510032'
|
|
||||||
>>> f.clean('2510032')
|
|
||||||
u'2510032'
|
|
||||||
>>> f.clean('2510-032')
|
|
||||||
Traceback (most recent call last):
|
|
||||||
...
|
|
||||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
|
||||||
>>> f.clean('251a0032')
|
|
||||||
Traceback (most recent call last):
|
|
||||||
...
|
|
||||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
|
||||||
>>> f.clean('a51-0032')
|
|
||||||
Traceback (most recent call last):
|
|
||||||
...
|
|
||||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
|
||||||
>>> f.clean('25100321')
|
|
||||||
Traceback (most recent call last):
|
|
||||||
...
|
|
||||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
|
||||||
>>> f.clean('')
|
|
||||||
Traceback (most recent call last):
|
|
||||||
...
|
|
||||||
ValidationError: [u'This field is required.']
|
|
||||||
|
|
||||||
>>> f = JPPostalCodeField(required=False)
|
|
||||||
>>> f.clean('251-0032')
|
|
||||||
u'2510032'
|
|
||||||
>>> f.clean('2510032')
|
|
||||||
u'2510032'
|
|
||||||
>>> f.clean('2510-032')
|
|
||||||
Traceback (most recent call last):
|
|
||||||
...
|
|
||||||
ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
|
||||||
>>> f.clean('')
|
|
||||||
u''
|
|
||||||
>>> f.clean(None)
|
|
||||||
u''
|
|
||||||
|
|
||||||
# JPPrefectureSelect ###############################################################
|
|
||||||
|
|
||||||
A Select widget that uses a list of Japanese prefectures as its choices.
|
|
||||||
>>> from django.contrib.localflavor.jp.forms import JPPrefectureSelect
|
|
||||||
>>> w = JPPrefectureSelect()
|
|
||||||
>>> print w.render('prefecture', 'kanagawa')
|
|
||||||
<select name="prefecture">
|
|
||||||
<option value="hokkaido">Hokkaido</option>
|
<option value="hokkaido">Hokkaido</option>
|
||||||
<option value="aomori">Aomori</option>
|
<option value="aomori">Aomori</option>
|
||||||
<option value="iwate">Iwate</option>
|
<option value="iwate">Iwate</option>
|
||||||
|
@ -102,5 +55,19 @@ A Select widget that uses a list of Japanese prefectures as its choices.
|
||||||
<option value="miyazaki">Miyazaki</option>
|
<option value="miyazaki">Miyazaki</option>
|
||||||
<option value="kagoshima">Kagoshima</option>
|
<option value="kagoshima">Kagoshima</option>
|
||||||
<option value="okinawa">Okinawa</option>
|
<option value="okinawa">Okinawa</option>
|
||||||
</select>
|
</select>'''
|
||||||
"""
|
self.assertEqual(f.render('prefecture', 'kanagawa'), out)
|
||||||
|
|
||||||
|
def test_JPPostalCodeField(self):
|
||||||
|
error_format = [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.']
|
||||||
|
valid = {
|
||||||
|
'251-0032': '2510032',
|
||||||
|
'2510032': '2510032',
|
||||||
|
}
|
||||||
|
invalid = {
|
||||||
|
'2510-032': error_format,
|
||||||
|
'251a0032': error_format,
|
||||||
|
'a51-0032': error_format,
|
||||||
|
'25100321': error_format,
|
||||||
|
}
|
||||||
|
self.assertFieldOutput(JPPostalCodeField, valid, invalid)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from localflavor.cz import tests as localflavor_cz_tests
|
from localflavor.cz import tests as localflavor_cz_tests
|
||||||
from localflavor.jp import tests as localflavor_jp_tests
|
|
||||||
from localflavor.kw import tests as localflavor_kw_tests
|
from localflavor.kw import tests as localflavor_kw_tests
|
||||||
from localflavor.nl import tests as localflavor_nl_tests
|
from localflavor.nl import tests as localflavor_nl_tests
|
||||||
from localflavor.pl import tests as localflavor_pl_tests
|
from localflavor.pl import tests as localflavor_pl_tests
|
||||||
|
@ -31,12 +30,12 @@ from localflavor.ie import IELocalFlavorTests
|
||||||
from localflavor.il import ILLocalFlavorTests
|
from localflavor.il import ILLocalFlavorTests
|
||||||
from localflavor.is_ import ISLocalFlavorTests
|
from localflavor.is_ import ISLocalFlavorTests
|
||||||
from localflavor.it import ITLocalFlavorTests
|
from localflavor.it import ITLocalFlavorTests
|
||||||
|
from localflavor.jp import JPLocalFlavorTests
|
||||||
from localflavor.tr import TRLocalFlavorTests
|
from localflavor.tr import TRLocalFlavorTests
|
||||||
|
|
||||||
|
|
||||||
__test__ = {
|
__test__ = {
|
||||||
'localflavor_cz_tests': localflavor_cz_tests,
|
'localflavor_cz_tests': localflavor_cz_tests,
|
||||||
'localflavor_jp_tests': localflavor_jp_tests,
|
|
||||||
'localflavor_kw_tests': localflavor_kw_tests,
|
'localflavor_kw_tests': localflavor_kw_tests,
|
||||||
'localflavor_nl_tests': localflavor_nl_tests,
|
'localflavor_nl_tests': localflavor_nl_tests,
|
||||||
'localflavor_pl_tests': localflavor_pl_tests,
|
'localflavor_pl_tests': localflavor_pl_tests,
|
||||||
|
|
|
@ -31,5 +31,6 @@ from regressiontests.forms.localflavortests import (
|
||||||
ILLocalFlavorTests,
|
ILLocalFlavorTests,
|
||||||
ISLocalFlavorTests,
|
ISLocalFlavorTests,
|
||||||
ITLocalFlavorTests,
|
ITLocalFlavorTests,
|
||||||
|
JPLocalFlavorTests,
|
||||||
TRLocalFlavorTests,
|
TRLocalFlavorTests,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue