parts/django/tests/regressiontests/forms/localflavor/br.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 from django.contrib.localflavor.br.forms import (BRZipCodeField,
       
     2     BRCNPJField, BRCPFField, BRPhoneNumberField, BRStateSelect,
       
     3     BRStateChoiceField)
       
     4 
       
     5 from utils import LocalFlavorTestCase
       
     6 
       
     7 
       
     8 class BRLocalFlavorTests(LocalFlavorTestCase):
       
     9     def test_BRZipCodeField(self):
       
    10         error_format = [u'Enter a zip code in the format XXXXX-XXX.']
       
    11         valid = {
       
    12             '12345-123': '12345-123',
       
    13         }
       
    14         invalid = {
       
    15             '12345_123': error_format,
       
    16             '1234-123': error_format,
       
    17             'abcde-abc': error_format,
       
    18             '12345-': error_format,
       
    19             '-123': error_format,
       
    20         }
       
    21         self.assertFieldOutput(BRZipCodeField, valid, invalid)
       
    22 
       
    23     def test_BRCNPJField(self):
       
    24         error_format = [u'Invalid CNPJ number.']
       
    25         error_numbersonly = [u'This field requires only numbers.']
       
    26         valid = {
       
    27             '64.132.916/0001-88': '64.132.916/0001-88',
       
    28             '64-132-916/0001-88': '64-132-916/0001-88',
       
    29             '64132916/0001-88': '64132916/0001-88',
       
    30         }
       
    31         invalid = {
       
    32             '12-345-678/9012-10': error_format,
       
    33             '12.345.678/9012-10': error_format,
       
    34             '12345678/9012-10': error_format,
       
    35             '64.132.916/0001-XX': error_numbersonly,
       
    36         }
       
    37         self.assertFieldOutput(BRCNPJField, valid, invalid)
       
    38 
       
    39     def test_BRCPFField(self):
       
    40         error_format = [u'Invalid CPF number.']
       
    41         error_numbersonly = [u'This field requires only numbers.']
       
    42         error_atmost_chars = [u'Ensure this value has at most 14 characters (it has 15).']
       
    43         error_atleast_chars = [u'Ensure this value has at least 11 characters (it has 10).']
       
    44         error_atmost = [u'This field requires at most 11 digits or 14 characters.']
       
    45         valid = {
       
    46             '663.256.017-26': '663.256.017-26',
       
    47             '66325601726': '66325601726',
       
    48             '375.788.573-20': '375.788.573-20',
       
    49             '84828509895': '84828509895',
       
    50         }
       
    51         invalid = {
       
    52             '489.294.654-54': error_format,
       
    53             '295.669.575-98': error_format,
       
    54             '539.315.127-22': error_format,
       
    55             '375.788.573-XX': error_numbersonly,
       
    56             '375.788.573-000': error_atmost_chars,
       
    57             '123.456.78': error_atleast_chars,
       
    58             '123456789555': error_atmost,
       
    59         }
       
    60         self.assertFieldOutput(BRCPFField, valid, invalid)
       
    61 
       
    62     def test_BRPhoneNumberField(self):
       
    63         # TODO: this doesn't test for any invalid inputs.
       
    64         valid = {
       
    65             '41-3562-3464': u'41-3562-3464',
       
    66             '4135623464': u'41-3562-3464',
       
    67             '41 3562-3464': u'41-3562-3464',
       
    68             '41 3562 3464': u'41-3562-3464',
       
    69             '(41) 3562 3464': u'41-3562-3464',
       
    70             '41.3562.3464': u'41-3562-3464',
       
    71             '41.3562-3464': u'41-3562-3464',
       
    72             ' (41) 3562.3464': u'41-3562-3464',
       
    73         }
       
    74         invalid = {}
       
    75         self.assertFieldOutput(BRPhoneNumberField, valid, invalid)
       
    76 
       
    77     def test_BRStateSelect(self):
       
    78         f = BRStateSelect()
       
    79         out = u'''<select name="states">
       
    80 <option value="AC">Acre</option>
       
    81 <option value="AL">Alagoas</option>
       
    82 <option value="AP">Amap\xe1</option>
       
    83 <option value="AM">Amazonas</option>
       
    84 <option value="BA">Bahia</option>
       
    85 <option value="CE">Cear\xe1</option>
       
    86 <option value="DF">Distrito Federal</option>
       
    87 <option value="ES">Esp\xedrito Santo</option>
       
    88 <option value="GO">Goi\xe1s</option>
       
    89 <option value="MA">Maranh\xe3o</option>
       
    90 <option value="MT">Mato Grosso</option>
       
    91 <option value="MS">Mato Grosso do Sul</option>
       
    92 <option value="MG">Minas Gerais</option>
       
    93 <option value="PA">Par\xe1</option>
       
    94 <option value="PB">Para\xedba</option>
       
    95 <option value="PR" selected="selected">Paran\xe1</option>
       
    96 <option value="PE">Pernambuco</option>
       
    97 <option value="PI">Piau\xed</option>
       
    98 <option value="RJ">Rio de Janeiro</option>
       
    99 <option value="RN">Rio Grande do Norte</option>
       
   100 <option value="RS">Rio Grande do Sul</option>
       
   101 <option value="RO">Rond\xf4nia</option>
       
   102 <option value="RR">Roraima</option>
       
   103 <option value="SC">Santa Catarina</option>
       
   104 <option value="SP">S\xe3o Paulo</option>
       
   105 <option value="SE">Sergipe</option>
       
   106 <option value="TO">Tocantins</option>
       
   107 </select>'''
       
   108         self.assertEqual(f.render('states', 'PR'), out)
       
   109 
       
   110     def test_BRStateChoiceField(self):
       
   111         error_invalid = [u'Select a valid brazilian state. That state is not one of the available states.']
       
   112         valid = {
       
   113             'AC': 'AC',
       
   114             'AL': 'AL',
       
   115             'AP': 'AP',
       
   116             'AM': 'AM',
       
   117             'BA': 'BA',
       
   118             'CE': 'CE',
       
   119             'DF': 'DF',
       
   120             'ES': 'ES',
       
   121             'GO': 'GO',
       
   122             'MA': 'MA',
       
   123             'MT': 'MT',
       
   124             'MS': 'MS',
       
   125             'MG': 'MG',
       
   126             'PA': 'PA',
       
   127             'PB': 'PB',
       
   128             'PR': 'PR',
       
   129             'PE': 'PE',
       
   130             'PI': 'PI',
       
   131             'RJ': 'RJ',
       
   132             'RN': 'RN',
       
   133             'RS': 'RS',
       
   134             'RO': 'RO',
       
   135             'RR': 'RR',
       
   136             'SC': 'SC',
       
   137             'SP': 'SP',
       
   138             'SE': 'SE',
       
   139             'TO': 'TO',
       
   140         }
       
   141         invalid = {
       
   142             'pr': error_invalid,
       
   143         }
       
   144         self.assertFieldOutput(BRStateChoiceField, valid, invalid)