PageRenderTime 66ms CodeModel.GetById 52ms app.highlight 11ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/regressiontests/forms/localflavor/id.py

https://code.google.com/p/mango-py/
Python | 194 lines | 188 code | 6 blank | 0 comment | 0 complexity | 65c6e0b0a083fa8d55019a9757f01b82 MD5 | raw file
  1import warnings
  2
  3from django.contrib.localflavor.id.forms import (IDPhoneNumberField,
  4    IDPostCodeField, IDNationalIdentityNumberField, IDLicensePlateField,
  5    IDProvinceSelect, IDLicensePlatePrefixSelect)
  6
  7from utils import LocalFlavorTestCase
  8
  9
 10class IDLocalFlavorTests(LocalFlavorTestCase):
 11    def setUp(self):
 12        self.save_warnings_state()
 13        warnings.filterwarnings(
 14            "ignore",
 15            category=RuntimeWarning,
 16            module='django.contrib.localflavor.id.id_choices'
 17        )
 18
 19    def tearDown(self):
 20        self.restore_warnings_state()
 21
 22    def test_IDProvinceSelect(self):
 23        f = IDProvinceSelect()
 24        out = u'''<select name="provinces">
 25<option value="ACE">Aceh</option>
 26<option value="BLI">Bali</option>
 27<option value="BTN">Banten</option>
 28<option value="BKL">Bengkulu</option>
 29<option value="DIY">Yogyakarta</option>
 30<option value="JKT">Jakarta</option>
 31<option value="GOR">Gorontalo</option>
 32<option value="JMB">Jambi</option>
 33<option value="JBR">Jawa Barat</option>
 34<option value="JTG">Jawa Tengah</option>
 35<option value="JTM">Jawa Timur</option>
 36<option value="KBR">Kalimantan Barat</option>
 37<option value="KSL">Kalimantan Selatan</option>
 38<option value="KTG">Kalimantan Tengah</option>
 39<option value="KTM">Kalimantan Timur</option>
 40<option value="BBL">Kepulauan Bangka-Belitung</option>
 41<option value="KRI">Kepulauan Riau</option>
 42<option value="LPG" selected="selected">Lampung</option>
 43<option value="MLK">Maluku</option>
 44<option value="MUT">Maluku Utara</option>
 45<option value="NTB">Nusa Tenggara Barat</option>
 46<option value="NTT">Nusa Tenggara Timur</option>
 47<option value="PPA">Papua</option>
 48<option value="PPB">Papua Barat</option>
 49<option value="RIU">Riau</option>
 50<option value="SLB">Sulawesi Barat</option>
 51<option value="SLS">Sulawesi Selatan</option>
 52<option value="SLT">Sulawesi Tengah</option>
 53<option value="SLR">Sulawesi Tenggara</option>
 54<option value="SLU">Sulawesi Utara</option>
 55<option value="SMB">Sumatera Barat</option>
 56<option value="SMS">Sumatera Selatan</option>
 57<option value="SMU">Sumatera Utara</option>
 58</select>'''
 59        self.assertEqual(f.render('provinces', 'LPG'), out)
 60
 61    def test_IDLicensePlatePrefixSelect(self):
 62        f = IDLicensePlatePrefixSelect()
 63        out = u'''<select name="codes">
 64<option value="A">Banten</option>
 65<option value="AA">Magelang</option>
 66<option value="AB">Yogyakarta</option>
 67<option value="AD">Surakarta - Solo</option>
 68<option value="AE">Madiun</option>
 69<option value="AG">Kediri</option>
 70<option value="B">Jakarta</option>
 71<option value="BA">Sumatera Barat</option>
 72<option value="BB">Tapanuli</option>
 73<option value="BD">Bengkulu</option>
 74<option value="BE" selected="selected">Lampung</option>
 75<option value="BG">Sumatera Selatan</option>
 76<option value="BH">Jambi</option>
 77<option value="BK">Sumatera Utara</option>
 78<option value="BL">Nanggroe Aceh Darussalam</option>
 79<option value="BM">Riau</option>
 80<option value="BN">Kepulauan Bangka Belitung</option>
 81<option value="BP">Kepulauan Riau</option>
 82<option value="CC">Corps Consulate</option>
 83<option value="CD">Corps Diplomatic</option>
 84<option value="D">Bandung</option>
 85<option value="DA">Kalimantan Selatan</option>
 86<option value="DB">Sulawesi Utara Daratan</option>
 87<option value="DC">Sulawesi Barat</option>
 88<option value="DD">Sulawesi Selatan</option>
 89<option value="DE">Maluku</option>
 90<option value="DG">Maluku Utara</option>
 91<option value="DH">NTT - Timor</option>
 92<option value="DK">Bali</option>
 93<option value="DL">Sulawesi Utara Kepulauan</option>
 94<option value="DM">Gorontalo</option>
 95<option value="DN">Sulawesi Tengah</option>
 96<option value="DR">NTB - Lombok</option>
 97<option value="DS">Papua dan Papua Barat</option>
 98<option value="DT">Sulawesi Tenggara</option>
 99<option value="E">Cirebon</option>
100<option value="EA">NTB - Sumbawa</option>
101<option value="EB">NTT - Flores</option>
102<option value="ED">NTT - Sumba</option>
103<option value="F">Bogor</option>
104<option value="G">Pekalongan</option>
105<option value="H">Semarang</option>
106<option value="K">Pati</option>
107<option value="KB">Kalimantan Barat</option>
108<option value="KH">Kalimantan Tengah</option>
109<option value="KT">Kalimantan Timur</option>
110<option value="L">Surabaya</option>
111<option value="M">Madura</option>
112<option value="N">Malang</option>
113<option value="P">Jember</option>
114<option value="R">Banyumas</option>
115<option value="RI">Federal Government</option>
116<option value="S">Bojonegoro</option>
117<option value="T">Purwakarta</option>
118<option value="W">Sidoarjo</option>
119<option value="Z">Garut</option>
120</select>'''
121        self.assertEqual(f.render('codes', 'BE'), out)
122
123    def test_IDPhoneNumberField(self):
124        error_invalid = [u'Enter a valid phone number']
125        valid = {
126            '0812-3456789': u'0812-3456789',
127            '081234567890': u'081234567890',
128            '021 345 6789': u'021 345 6789',
129            '0213456789': u'0213456789',
130            '+62-21-3456789': u'+62-21-3456789',
131            '(021) 345 6789': u'(021) 345 6789',
132        }
133        invalid = {
134            '0123456789': error_invalid,
135            '+62-021-3456789': error_invalid,
136            '+62-021-3456789': error_invalid,
137            '+62-0812-3456789': error_invalid,
138            '0812345678901': error_invalid,
139            'foo': error_invalid,
140        }
141        self.assertFieldOutput(IDPhoneNumberField, valid, invalid)
142
143    def test_IDPostCodeField(self):
144        error_invalid = [u'Enter a valid post code']
145        valid = {
146            '12340': u'12340',
147            '25412': u'25412',
148            ' 12340 ': u'12340',
149        }
150        invalid = {
151            '12 3 4 0': error_invalid,
152            '12345': error_invalid,
153            '10100': error_invalid,
154            '123456': error_invalid,
155            'foo': error_invalid,
156        }
157        self.assertFieldOutput(IDPostCodeField, valid, invalid)
158
159    def test_IDNationalIdentityNumberField(self):
160        error_invalid = [u'Enter a valid NIK/KTP number']
161        valid = {
162            ' 12.3456.010178 3456 ': u'12.3456.010178.3456',
163            '1234560101783456': u'12.3456.010178.3456',
164            '12.3456.010101.3456': u'12.3456.010101.3456',
165        }
166        invalid = {
167            '12.3456.310278.3456': error_invalid,
168            '00.0000.010101.0000': error_invalid,
169            '1234567890123456': error_invalid,
170            'foo': error_invalid,
171        }
172        self.assertFieldOutput(IDNationalIdentityNumberField, valid, invalid)
173
174    def test_IDLicensePlateField(self):
175        error_invalid = [u'Enter a valid vehicle license plate number']
176        valid = {
177            ' b 1234  ab ': u'B 1234 AB',
178            'B 1234 ABC': u'B 1234 ABC',
179            'A 12': u'A 12',
180            'DK 12345 12': u'DK 12345 12',
181            'RI 10': u'RI 10',
182            'CD 12 12': u'CD 12 12',
183        }
184        invalid = {
185            'CD 10 12': error_invalid,
186            'CD 1234 12': error_invalid,
187            'RI 10 AB': error_invalid,
188            'B 12345 01': error_invalid,
189            'N 1234 12': error_invalid,
190            'A 12 XYZ': error_invalid,
191            'Q 1234 AB': error_invalid,
192            'foo': error_invalid,
193        }
194        self.assertFieldOutput(IDLicensePlateField, valid, invalid)