2012-06-07 16:08:47 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2010-12-18 20:31:00 +00:00
|
|
|
import warnings
|
2010-01-01 21:34:50 +00:00
|
|
|
|
2010-12-18 20:31:00 +00:00
|
|
|
from django.contrib.localflavor.id.forms import (IDPhoneNumberField,
|
|
|
|
IDPostCodeField, IDNationalIdentityNumberField, IDLicensePlateField,
|
|
|
|
IDProvinceSelect, IDLicensePlatePrefixSelect)
|
2010-01-01 21:34:50 +00:00
|
|
|
|
2011-08-23 02:32:37 +00:00
|
|
|
from django.test import SimpleTestCase
|
2010-01-01 21:34:50 +00:00
|
|
|
|
|
|
|
|
2011-08-23 02:32:37 +00:00
|
|
|
class IDLocalFlavorTests(SimpleTestCase):
|
2010-12-18 20:31:00 +00:00
|
|
|
def setUp(self):
|
|
|
|
self.save_warnings_state()
|
|
|
|
warnings.filterwarnings(
|
|
|
|
"ignore",
|
|
|
|
category=RuntimeWarning,
|
|
|
|
module='django.contrib.localflavor.id.id_choices'
|
|
|
|
)
|
2010-01-01 21:34:50 +00:00
|
|
|
|
2010-12-18 20:31:00 +00:00
|
|
|
def tearDown(self):
|
|
|
|
self.restore_warnings_state()
|
2010-01-01 21:34:50 +00:00
|
|
|
|
2010-12-18 20:31:00 +00:00
|
|
|
def test_IDProvinceSelect(self):
|
|
|
|
f = IDProvinceSelect()
|
2012-06-07 16:08:47 +00:00
|
|
|
out = '''<select name="provinces">
|
2010-12-18 20:31:00 +00:00
|
|
|
<option value="ACE">Aceh</option>
|
|
|
|
<option value="BLI">Bali</option>
|
|
|
|
<option value="BTN">Banten</option>
|
|
|
|
<option value="BKL">Bengkulu</option>
|
|
|
|
<option value="DIY">Yogyakarta</option>
|
|
|
|
<option value="JKT">Jakarta</option>
|
|
|
|
<option value="GOR">Gorontalo</option>
|
|
|
|
<option value="JMB">Jambi</option>
|
|
|
|
<option value="JBR">Jawa Barat</option>
|
|
|
|
<option value="JTG">Jawa Tengah</option>
|
|
|
|
<option value="JTM">Jawa Timur</option>
|
|
|
|
<option value="KBR">Kalimantan Barat</option>
|
|
|
|
<option value="KSL">Kalimantan Selatan</option>
|
|
|
|
<option value="KTG">Kalimantan Tengah</option>
|
|
|
|
<option value="KTM">Kalimantan Timur</option>
|
|
|
|
<option value="BBL">Kepulauan Bangka-Belitung</option>
|
|
|
|
<option value="KRI">Kepulauan Riau</option>
|
|
|
|
<option value="LPG" selected="selected">Lampung</option>
|
|
|
|
<option value="MLK">Maluku</option>
|
|
|
|
<option value="MUT">Maluku Utara</option>
|
|
|
|
<option value="NTB">Nusa Tenggara Barat</option>
|
|
|
|
<option value="NTT">Nusa Tenggara Timur</option>
|
|
|
|
<option value="PPA">Papua</option>
|
|
|
|
<option value="PPB">Papua Barat</option>
|
|
|
|
<option value="RIU">Riau</option>
|
|
|
|
<option value="SLB">Sulawesi Barat</option>
|
|
|
|
<option value="SLS">Sulawesi Selatan</option>
|
|
|
|
<option value="SLT">Sulawesi Tengah</option>
|
|
|
|
<option value="SLR">Sulawesi Tenggara</option>
|
|
|
|
<option value="SLU">Sulawesi Utara</option>
|
|
|
|
<option value="SMB">Sumatera Barat</option>
|
|
|
|
<option value="SMS">Sumatera Selatan</option>
|
|
|
|
<option value="SMU">Sumatera Utara</option>
|
|
|
|
</select>'''
|
2012-01-31 20:36:11 +00:00
|
|
|
self.assertHTMLEqual(f.render('provinces', 'LPG'), out)
|
2010-01-01 21:34:50 +00:00
|
|
|
|
2010-12-18 20:31:00 +00:00
|
|
|
def test_IDLicensePlatePrefixSelect(self):
|
|
|
|
f = IDLicensePlatePrefixSelect()
|
2012-06-07 16:08:47 +00:00
|
|
|
out = '''<select name="codes">
|
2010-12-18 20:31:00 +00:00
|
|
|
<option value="A">Banten</option>
|
|
|
|
<option value="AA">Magelang</option>
|
|
|
|
<option value="AB">Yogyakarta</option>
|
|
|
|
<option value="AD">Surakarta - Solo</option>
|
|
|
|
<option value="AE">Madiun</option>
|
|
|
|
<option value="AG">Kediri</option>
|
|
|
|
<option value="B">Jakarta</option>
|
|
|
|
<option value="BA">Sumatera Barat</option>
|
|
|
|
<option value="BB">Tapanuli</option>
|
|
|
|
<option value="BD">Bengkulu</option>
|
|
|
|
<option value="BE" selected="selected">Lampung</option>
|
|
|
|
<option value="BG">Sumatera Selatan</option>
|
|
|
|
<option value="BH">Jambi</option>
|
|
|
|
<option value="BK">Sumatera Utara</option>
|
|
|
|
<option value="BL">Nanggroe Aceh Darussalam</option>
|
|
|
|
<option value="BM">Riau</option>
|
|
|
|
<option value="BN">Kepulauan Bangka Belitung</option>
|
|
|
|
<option value="BP">Kepulauan Riau</option>
|
|
|
|
<option value="CC">Corps Consulate</option>
|
|
|
|
<option value="CD">Corps Diplomatic</option>
|
|
|
|
<option value="D">Bandung</option>
|
|
|
|
<option value="DA">Kalimantan Selatan</option>
|
|
|
|
<option value="DB">Sulawesi Utara Daratan</option>
|
|
|
|
<option value="DC">Sulawesi Barat</option>
|
|
|
|
<option value="DD">Sulawesi Selatan</option>
|
|
|
|
<option value="DE">Maluku</option>
|
|
|
|
<option value="DG">Maluku Utara</option>
|
|
|
|
<option value="DH">NTT - Timor</option>
|
|
|
|
<option value="DK">Bali</option>
|
|
|
|
<option value="DL">Sulawesi Utara Kepulauan</option>
|
|
|
|
<option value="DM">Gorontalo</option>
|
|
|
|
<option value="DN">Sulawesi Tengah</option>
|
|
|
|
<option value="DR">NTB - Lombok</option>
|
|
|
|
<option value="DS">Papua dan Papua Barat</option>
|
|
|
|
<option value="DT">Sulawesi Tenggara</option>
|
|
|
|
<option value="E">Cirebon</option>
|
|
|
|
<option value="EA">NTB - Sumbawa</option>
|
|
|
|
<option value="EB">NTT - Flores</option>
|
|
|
|
<option value="ED">NTT - Sumba</option>
|
|
|
|
<option value="F">Bogor</option>
|
|
|
|
<option value="G">Pekalongan</option>
|
|
|
|
<option value="H">Semarang</option>
|
|
|
|
<option value="K">Pati</option>
|
|
|
|
<option value="KB">Kalimantan Barat</option>
|
|
|
|
<option value="KH">Kalimantan Tengah</option>
|
|
|
|
<option value="KT">Kalimantan Timur</option>
|
|
|
|
<option value="L">Surabaya</option>
|
|
|
|
<option value="M">Madura</option>
|
|
|
|
<option value="N">Malang</option>
|
|
|
|
<option value="P">Jember</option>
|
|
|
|
<option value="R">Banyumas</option>
|
|
|
|
<option value="RI">Federal Government</option>
|
|
|
|
<option value="S">Bojonegoro</option>
|
|
|
|
<option value="T">Purwakarta</option>
|
|
|
|
<option value="W">Sidoarjo</option>
|
|
|
|
<option value="Z">Garut</option>
|
|
|
|
</select>'''
|
2012-01-31 20:36:11 +00:00
|
|
|
self.assertHTMLEqual(f.render('codes', 'BE'), out)
|
2010-01-01 21:34:50 +00:00
|
|
|
|
2010-12-18 20:31:00 +00:00
|
|
|
def test_IDPhoneNumberField(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
error_invalid = ['Enter a valid phone number']
|
2010-12-18 20:31:00 +00:00
|
|
|
valid = {
|
2012-06-07 16:08:47 +00:00
|
|
|
'0812-3456789': '0812-3456789',
|
|
|
|
'081234567890': '081234567890',
|
|
|
|
'021 345 6789': '021 345 6789',
|
|
|
|
'0213456789': '0213456789',
|
|
|
|
'+62-21-3456789': '+62-21-3456789',
|
|
|
|
'(021) 345 6789': '(021) 345 6789',
|
2010-12-18 20:31:00 +00:00
|
|
|
}
|
|
|
|
invalid = {
|
|
|
|
'0123456789': error_invalid,
|
|
|
|
'+62-021-3456789': error_invalid,
|
|
|
|
'+62-0812-3456789': error_invalid,
|
|
|
|
'0812345678901': error_invalid,
|
|
|
|
'foo': error_invalid,
|
|
|
|
}
|
|
|
|
self.assertFieldOutput(IDPhoneNumberField, valid, invalid)
|
2010-01-01 21:34:50 +00:00
|
|
|
|
2010-12-18 20:31:00 +00:00
|
|
|
def test_IDPostCodeField(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
error_invalid = ['Enter a valid post code']
|
2010-12-18 20:31:00 +00:00
|
|
|
valid = {
|
2012-06-07 16:08:47 +00:00
|
|
|
'12340': '12340',
|
|
|
|
'25412': '25412',
|
|
|
|
' 12340 ': '12340',
|
2010-12-18 20:31:00 +00:00
|
|
|
}
|
|
|
|
invalid = {
|
|
|
|
'12 3 4 0': error_invalid,
|
|
|
|
'12345': error_invalid,
|
|
|
|
'10100': error_invalid,
|
|
|
|
'123456': error_invalid,
|
|
|
|
'foo': error_invalid,
|
|
|
|
}
|
|
|
|
self.assertFieldOutput(IDPostCodeField, valid, invalid)
|
2010-01-01 21:34:50 +00:00
|
|
|
|
2010-12-18 20:31:00 +00:00
|
|
|
def test_IDNationalIdentityNumberField(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
error_invalid = ['Enter a valid NIK/KTP number']
|
2010-12-18 20:31:00 +00:00
|
|
|
valid = {
|
2012-06-07 16:08:47 +00:00
|
|
|
' 12.3456.010178 3456 ': '12.3456.010178.3456',
|
|
|
|
'1234560101783456': '12.3456.010178.3456',
|
|
|
|
'12.3456.010101.3456': '12.3456.010101.3456',
|
2010-12-18 20:31:00 +00:00
|
|
|
}
|
|
|
|
invalid = {
|
|
|
|
'12.3456.310278.3456': error_invalid,
|
|
|
|
'00.0000.010101.0000': error_invalid,
|
|
|
|
'1234567890123456': error_invalid,
|
|
|
|
'foo': error_invalid,
|
|
|
|
}
|
|
|
|
self.assertFieldOutput(IDNationalIdentityNumberField, valid, invalid)
|
2010-01-01 21:34:50 +00:00
|
|
|
|
2010-12-18 20:31:00 +00:00
|
|
|
def test_IDLicensePlateField(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
error_invalid = ['Enter a valid vehicle license plate number']
|
2010-12-18 20:31:00 +00:00
|
|
|
valid = {
|
2012-06-07 16:08:47 +00:00
|
|
|
' b 1234 ab ': 'B 1234 AB',
|
|
|
|
'B 1234 ABC': 'B 1234 ABC',
|
|
|
|
'A 12': 'A 12',
|
|
|
|
'DK 12345 12': 'DK 12345 12',
|
|
|
|
'RI 10': 'RI 10',
|
|
|
|
'CD 12 12': 'CD 12 12',
|
2010-12-18 20:31:00 +00:00
|
|
|
}
|
|
|
|
invalid = {
|
|
|
|
'CD 10 12': error_invalid,
|
|
|
|
'CD 1234 12': error_invalid,
|
|
|
|
'RI 10 AB': error_invalid,
|
|
|
|
'B 12345 01': error_invalid,
|
|
|
|
'N 1234 12': error_invalid,
|
|
|
|
'A 12 XYZ': error_invalid,
|
|
|
|
'Q 1234 AB': error_invalid,
|
|
|
|
'foo': error_invalid,
|
|
|
|
}
|
|
|
|
self.assertFieldOutput(IDLicensePlateField, valid, invalid)
|