from __future__ import unicode_literals
import warnings
from django.contrib.localflavor.id.forms import (IDPhoneNumberField,
IDPostCodeField, IDNationalIdentityNumberField, IDLicensePlateField,
IDProvinceSelect, IDLicensePlatePrefixSelect)
from django.test import SimpleTestCase
class IDLocalFlavorTests(SimpleTestCase):
def setUp(self):
self.save_warnings_state()
warnings.filterwarnings(
"ignore",
category=RuntimeWarning,
module='django.contrib.localflavor.id.id_choices'
)
def tearDown(self):
self.restore_warnings_state()
def test_IDProvinceSelect(self):
f = IDProvinceSelect()
out = ''''''
self.assertHTMLEqual(f.render('provinces', 'LPG'), out)
def test_IDLicensePlatePrefixSelect(self):
f = IDLicensePlatePrefixSelect()
out = ''''''
self.assertHTMLEqual(f.render('codes', 'BE'), out)
def test_IDPhoneNumberField(self):
error_invalid = ['Enter a valid phone number']
valid = {
'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',
}
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)
def test_IDPostCodeField(self):
error_invalid = ['Enter a valid post code']
valid = {
'12340': '12340',
'25412': '25412',
' 12340 ': '12340',
}
invalid = {
'12 3 4 0': error_invalid,
'12345': error_invalid,
'10100': error_invalid,
'123456': error_invalid,
'foo': error_invalid,
}
self.assertFieldOutput(IDPostCodeField, valid, invalid)
def test_IDNationalIdentityNumberField(self):
error_invalid = ['Enter a valid NIK/KTP number']
valid = {
' 12.3456.010178 3456 ': '12.3456.010178.3456',
'1234560101783456': '12.3456.010178.3456',
'12.3456.010101.3456': '12.3456.010101.3456',
}
invalid = {
'12.3456.310278.3456': error_invalid,
'00.0000.010101.0000': error_invalid,
'1234567890123456': error_invalid,
'foo': error_invalid,
}
self.assertFieldOutput(IDNationalIdentityNumberField, valid, invalid)
def test_IDLicensePlateField(self):
error_invalid = ['Enter a valid vehicle license plate number']
valid = {
' 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',
}
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)