PageRenderTime 15ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/cz.py

https://code.google.com/p/mango-py/
Python | 105 lines | 99 code | 6 blank | 0 comment | 4 complexity | a0fd7affbadc8853388b5499c1e63431 MD5 | raw file
  1import warnings
  2
  3from django.contrib.localflavor.cz.forms import (CZPostalCodeField,
  4    CZRegionSelect, CZBirthNumberField, CZICNumberField)
  5
  6from django.core.exceptions import ValidationError
  7from utils import LocalFlavorTestCase
  8
  9
 10class CZLocalFlavorTests(LocalFlavorTestCase):
 11    def setUp(self):
 12        self.save_warnings_state()
 13        warnings.filterwarnings(
 14            "ignore",
 15            category=PendingDeprecationWarning,
 16            module='django.contrib.localflavor.cz.forms'
 17        )
 18
 19    def tearDown(self):
 20        self.restore_warnings_state()
 21
 22    def test_CZRegionSelect(self):
 23        f = CZRegionSelect()
 24        out = u'''<select name="regions">
 25<option value="PR">Prague</option>
 26<option value="CE">Central Bohemian Region</option>
 27<option value="SO">South Bohemian Region</option>
 28<option value="PI">Pilsen Region</option>
 29<option value="CA">Carlsbad Region</option>
 30<option value="US">Usti Region</option>
 31<option value="LB">Liberec Region</option>
 32<option value="HK">Hradec Region</option>
 33<option value="PA">Pardubice Region</option>
 34<option value="VY">Vysocina Region</option>
 35<option value="SM">South Moravian Region</option>
 36<option value="OL">Olomouc Region</option>
 37<option value="ZL">Zlin Region</option>
 38<option value="MS">Moravian-Silesian Region</option>
 39</select>'''
 40        self.assertEqual(f.render('regions', 'TT'), out)
 41
 42    def test_CZPostalCodeField(self):
 43        error_format = [u'Enter a postal code in the format XXXXX or XXX XX.']
 44        valid = {
 45            '91909': '91909',
 46            '917 01': '91701',
 47            '12345': '12345',
 48        }
 49        invalid = {
 50            '84545x': error_format,
 51            '123456': error_format,
 52            '1234': error_format,
 53            '123 4': error_format,
 54        }
 55        self.assertFieldOutput(CZPostalCodeField, valid, invalid)
 56
 57    def test_CZBirthNumberField(self):
 58        error_format = [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
 59        error_invalid = [u'Enter a valid birth number.']
 60        valid = {
 61            '880523/1237': '880523/1237',
 62            '8805231237': '8805231237',
 63            '880523/000': '880523/000',
 64            '880523000': '880523000',
 65            '882101/0011': '882101/0011',
 66        }
 67        invalid = {
 68            '123456/12': error_format,
 69            '123456/12345': error_format,
 70            '12345612': error_format,
 71            '12345612345': error_format,
 72            '880523/1239': error_invalid,
 73            '8805231239': error_invalid,
 74            '990101/0011': error_invalid,
 75        }
 76        self.assertFieldOutput(CZBirthNumberField, valid, invalid)
 77
 78        # These tests should go away in 1.4.
 79        # http://code.djangoproject.com/ticket/14593
 80        f = CZBirthNumberField()
 81        self.assertEqual(f.clean('880523/1237', 'm'), '880523/1237'),
 82        self.assertEqual(f.clean('885523/1231', 'f'), '885523/1231')
 83        self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
 84            f.clean, '881523/0000', 'm')
 85        self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
 86            f.clean, '885223/0000', 'm')
 87        self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
 88            f.clean, '881523/0000', 'f')
 89        self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
 90            f.clean, '885223/0000', 'f')
 91
 92    def test_CZICNumberField(self):
 93        error_invalid = [u'Enter a valid IC number.']
 94        valid ={
 95            '12345679': '12345679',
 96            '12345601': '12345601',
 97            '12345661': '12345661',
 98            '12345610': '12345610',
 99        }
100        invalid = {
101            '1234567': error_invalid,
102            '12345660': error_invalid,
103            '12345600': error_invalid,
104        }
105        self.assertFieldOutput(CZICNumberField, valid, invalid)