2010-12-27 07:41:26 +00:00
|
|
|
import warnings
|
2009-02-22 07:51:57 +00:00
|
|
|
|
2010-12-27 07:41:26 +00:00
|
|
|
from django.contrib.localflavor.cz.forms import (CZPostalCodeField,
|
|
|
|
CZRegionSelect, CZBirthNumberField, CZICNumberField)
|
2009-02-22 07:51:57 +00:00
|
|
|
|
2010-12-27 07:41:26 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from utils import LocalFlavorTestCase
|
2009-02-22 07:51:57 +00:00
|
|
|
|
|
|
|
|
2010-12-27 07:41:26 +00:00
|
|
|
class CZLocalFlavorTests(LocalFlavorTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.save_warnings_state()
|
|
|
|
warnings.filterwarnings(
|
|
|
|
"ignore",
|
2011-04-02 08:44:47 +00:00
|
|
|
category=DeprecationWarning,
|
2010-12-27 07:41:26 +00:00
|
|
|
module='django.contrib.localflavor.cz.forms'
|
|
|
|
)
|
2009-02-22 07:51:57 +00:00
|
|
|
|
2010-12-27 07:41:26 +00:00
|
|
|
def tearDown(self):
|
|
|
|
self.restore_warnings_state()
|
2009-02-22 07:51:57 +00:00
|
|
|
|
2010-12-27 07:41:26 +00:00
|
|
|
def test_CZRegionSelect(self):
|
|
|
|
f = CZRegionSelect()
|
|
|
|
out = u'''<select name="regions">
|
|
|
|
<option value="PR">Prague</option>
|
|
|
|
<option value="CE">Central Bohemian Region</option>
|
|
|
|
<option value="SO">South Bohemian Region</option>
|
|
|
|
<option value="PI">Pilsen Region</option>
|
|
|
|
<option value="CA">Carlsbad Region</option>
|
|
|
|
<option value="US">Usti Region</option>
|
|
|
|
<option value="LB">Liberec Region</option>
|
|
|
|
<option value="HK">Hradec Region</option>
|
|
|
|
<option value="PA">Pardubice Region</option>
|
|
|
|
<option value="VY">Vysocina Region</option>
|
|
|
|
<option value="SM">South Moravian Region</option>
|
|
|
|
<option value="OL">Olomouc Region</option>
|
|
|
|
<option value="ZL">Zlin Region</option>
|
|
|
|
<option value="MS">Moravian-Silesian Region</option>
|
|
|
|
</select>'''
|
|
|
|
self.assertEqual(f.render('regions', 'TT'), out)
|
2009-02-22 07:51:57 +00:00
|
|
|
|
2010-12-27 07:41:26 +00:00
|
|
|
def test_CZPostalCodeField(self):
|
|
|
|
error_format = [u'Enter a postal code in the format XXXXX or XXX XX.']
|
|
|
|
valid = {
|
|
|
|
'91909': '91909',
|
|
|
|
'917 01': '91701',
|
|
|
|
'12345': '12345',
|
|
|
|
}
|
|
|
|
invalid = {
|
|
|
|
'84545x': error_format,
|
|
|
|
'123456': error_format,
|
|
|
|
'1234': error_format,
|
|
|
|
'123 4': error_format,
|
|
|
|
}
|
|
|
|
self.assertFieldOutput(CZPostalCodeField, valid, invalid)
|
2009-02-22 07:51:57 +00:00
|
|
|
|
2010-12-27 07:41:26 +00:00
|
|
|
def test_CZBirthNumberField(self):
|
|
|
|
error_format = [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
|
|
|
|
error_invalid = [u'Enter a valid birth number.']
|
|
|
|
valid = {
|
|
|
|
'880523/1237': '880523/1237',
|
|
|
|
'8805231237': '8805231237',
|
|
|
|
'880523/000': '880523/000',
|
|
|
|
'880523000': '880523000',
|
|
|
|
'882101/0011': '882101/0011',
|
|
|
|
}
|
|
|
|
invalid = {
|
|
|
|
'123456/12': error_format,
|
|
|
|
'123456/12345': error_format,
|
|
|
|
'12345612': error_format,
|
|
|
|
'12345612345': error_format,
|
|
|
|
'880523/1239': error_invalid,
|
|
|
|
'8805231239': error_invalid,
|
|
|
|
'990101/0011': error_invalid,
|
|
|
|
}
|
|
|
|
self.assertFieldOutput(CZBirthNumberField, valid, invalid)
|
|
|
|
|
|
|
|
# These tests should go away in 1.4.
|
|
|
|
# http://code.djangoproject.com/ticket/14593
|
|
|
|
f = CZBirthNumberField()
|
|
|
|
self.assertEqual(f.clean('880523/1237', 'm'), '880523/1237'),
|
|
|
|
self.assertEqual(f.clean('885523/1231', 'f'), '885523/1231')
|
|
|
|
self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
|
|
|
|
f.clean, '881523/0000', 'm')
|
|
|
|
self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
|
|
|
|
f.clean, '885223/0000', 'm')
|
|
|
|
self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
|
|
|
|
f.clean, '881523/0000', 'f')
|
|
|
|
self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
|
|
|
|
f.clean, '885223/0000', 'f')
|
|
|
|
|
|
|
|
def test_CZICNumberField(self):
|
|
|
|
error_invalid = [u'Enter a valid IC number.']
|
|
|
|
valid ={
|
|
|
|
'12345679': '12345679',
|
|
|
|
'12345601': '12345601',
|
|
|
|
'12345661': '12345661',
|
|
|
|
'12345610': '12345610',
|
|
|
|
}
|
|
|
|
invalid = {
|
|
|
|
'1234567': error_invalid,
|
|
|
|
'12345660': error_invalid,
|
|
|
|
'12345600': error_invalid,
|
|
|
|
}
|
|
|
|
self.assertFieldOutput(CZICNumberField, valid, invalid)
|