PageRenderTime 530ms CodeModel.GetById 201ms app.highlight 146ms RepoModel.GetById 181ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/ro.py

https://code.google.com/p/mango-py/
Python | 140 lines | 136 code | 3 blank | 1 comment | 3 complexity | b64721bd2e9806d5117622e6e1724c5c MD5 | raw file
  1# -*- coding: utf-8 -*-
  2from django.contrib.localflavor.ro.forms import (ROCIFField, ROCNPField,
  3    ROCountyField, ROCountySelect, ROIBANField, ROPhoneNumberField,
  4    ROPostalCodeField)
  5
  6from utils import LocalFlavorTestCase
  7
  8
  9class ROLocalFlavorTests(LocalFlavorTestCase):
 10    def test_ROCountySelect(self):
 11        f = ROCountySelect()
 12        out = u'''<select name="county">
 13<option value="AB">Alba</option>
 14<option value="AR">Arad</option>
 15<option value="AG">Arge\u015f</option>
 16<option value="BC">Bac\u0103u</option>
 17<option value="BH">Bihor</option>
 18<option value="BN">Bistri\u0163a-N\u0103s\u0103ud</option>
 19<option value="BT">Boto\u015fani</option>
 20<option value="BV">Bra\u015fov</option>
 21<option value="BR">Br\u0103ila</option>
 22<option value="B">Bucure\u015fti</option>
 23<option value="BZ">Buz\u0103u</option>
 24<option value="CS">Cara\u015f-Severin</option>
 25<option value="CL">C\u0103l\u0103ra\u015fi</option>
 26<option value="CJ" selected="selected">Cluj</option>
 27<option value="CT">Constan\u0163a</option>
 28<option value="CV">Covasna</option>
 29<option value="DB">D\xe2mbovi\u0163a</option>
 30<option value="DJ">Dolj</option>
 31<option value="GL">Gala\u0163i</option>
 32<option value="GR">Giurgiu</option>
 33<option value="GJ">Gorj</option>
 34<option value="HR">Harghita</option>
 35<option value="HD">Hunedoara</option>
 36<option value="IL">Ialomi\u0163a</option>
 37<option value="IS">Ia\u015fi</option>
 38<option value="IF">Ilfov</option>
 39<option value="MM">Maramure\u015f</option>
 40<option value="MH">Mehedin\u0163i</option>
 41<option value="MS">Mure\u015f</option>
 42<option value="NT">Neam\u0163</option>
 43<option value="OT">Olt</option>
 44<option value="PH">Prahova</option>
 45<option value="SM">Satu Mare</option>
 46<option value="SJ">S\u0103laj</option>
 47<option value="SB">Sibiu</option>
 48<option value="SV">Suceava</option>
 49<option value="TR">Teleorman</option>
 50<option value="TM">Timi\u015f</option>
 51<option value="TL">Tulcea</option>
 52<option value="VS">Vaslui</option>
 53<option value="VL">V\xe2lcea</option>
 54<option value="VN">Vrancea</option>
 55</select>'''
 56        self.assertEqual(f.render('county', 'CJ'), out)
 57
 58    def test_ROCIFField(self):
 59        error_invalid = [u'Enter a valid CIF.']
 60        error_atmost = [u'Ensure this value has at most 10 characters (it has 11).']
 61        error_atleast = [u'Ensure this value has at least 2 characters (it has 1).']
 62        valid = {
 63            '21694681': u'21694681',
 64            'RO21694681': u'21694681',
 65        }
 66        invalid = {
 67            '21694680': error_invalid,
 68            '21694680000': error_atmost,
 69            '0': error_atleast,
 70        }
 71        self.assertFieldOutput(ROCIFField, valid, invalid)
 72
 73    def test_ROCNPField(self):
 74        error_invalid = [u'Enter a valid CNP.']
 75        error_atleast = [u'Ensure this value has at least 13 characters (it has 10).']
 76        error_atmost = [u'Ensure this value has at most 13 characters (it has 14).']
 77        valid = {
 78            '1981211204489': '1981211204489',
 79        }
 80        invalid = {
 81            '1981211204487': error_invalid,
 82            '1981232204489': error_invalid,
 83            '9981211204489': error_invalid,
 84            '9981211209': error_atleast,
 85            '19812112044891': error_atmost,
 86        }
 87        self.assertFieldOutput(ROCNPField, valid, invalid)
 88
 89    def test_ROCountyField(self):
 90        error_format = [u'Enter a Romanian county code or name.']
 91        valid = {
 92            'CJ': 'CJ',
 93            'cj': 'CJ',
 94            u'Arge?': 'AG',
 95            u'arge?': 'AG',
 96        }
 97        invalid = {
 98            'Arges': error_format,
 99        }
100        self.assertFieldOutput(ROCountyField, valid, invalid)
101
102    def test_ROIBANField(self):
103        error_invalid = [u'Enter a valid IBAN in ROXX-XXXX-XXXX-XXXX-XXXX-XXXX format']
104        error_atleast = [u'Ensure this value has at least 24 characters (it has 23).']
105        valid = {
106            'RO56RZBR0000060003291177': 'RO56RZBR0000060003291177',
107            'RO56-RZBR-0000-0600-0329-1177': 'RO56RZBR0000060003291177',
108        }
109        invalid = {
110            'RO56RZBR0000060003291176': error_invalid,
111            'AT61 1904 3002 3457 3201': error_invalid,
112            'RO56RZBR000006000329117': error_atleast,
113        }
114        self.assertFieldOutput(ROIBANField, valid, invalid)
115
116    def test_ROPhoneNumberField(self):
117        error_format = [u'Phone numbers must be in XXXX-XXXXXX format.']
118        error_atleast = [u'Ensure this value has at least 10 characters (it has 9).']
119        valid = {
120            '0264485936': '0264485936',
121            '(0264)-485936': '0264485936',
122        }
123        invalid = {
124            '02644859368': error_format,
125            '026448593': error_atleast,
126        }
127        self.assertFieldOutput(ROPhoneNumberField, valid, invalid)
128
129    def test_ROPostalCodeField(self):
130        error_atleast = [u'Ensure this value has at least 6 characters (it has 5).']
131        error_atmost = [u'Ensure this value has at most 6 characters (it has 7).']
132
133        valid = {
134            '400473': '400473',
135        }
136        invalid = {
137            '40047': error_atleast,
138            '4004731': error_atmost,
139        }
140        self.assertFieldOutput(ROPostalCodeField, valid, invalid)