# -*- coding: utf-8 -*-
from django.contrib.localflavor.hr.forms import (HRCountySelect,
HRPhoneNumberPrefixSelect, HRLicensePlatePrefixSelect, HRPhoneNumberField,
HRLicensePlateField, HRPostalCodeField, HROIBField, HRJMBGField,
HRJMBAGField)
from django.test import SimpleTestCase
class HRLocalFlavorTests(SimpleTestCase):
def test_HRCountySelect(self):
f = HRCountySelect()
out = u''''''
self.assertEqual(f.render('county', 'GZG'), out)
def test_HRPhoneNumberPrefixSelect(self):
f = HRPhoneNumberPrefixSelect()
out = u''''''
self.assertEqual(f.render('phone', '1'), out)
def test_HRLicensePlatePrefixSelect(self):
f = HRLicensePlatePrefixSelect()
out = u''''''
self.assertEqual(f.render('license', 'BJ'), out)
def test_HRPhoneNumberField(self):
error_invalid = [u'Enter a valid phone number']
error_area = [u'Enter a valid area or mobile network code']
error_number = [u'The phone nubmer is too long']
valid = {
'+38511234567': '+38511234567',
'0038511234567': '+38511234567',
'011234567': '+38511234567',
'+38521123456': '+38521123456',
'0038521123456': '+38521123456',
'021123456': '+38521123456',
}
invalid = {
'123456789': error_invalid,
'0811234567': error_area,
'0111234567': error_number,
}
self.assertFieldOutput(HRPhoneNumberField, valid, invalid)
def test_HRLicensePlateField(self):
error_invalid = [u'Enter a valid vehicle license plate number']
error_area = [u'Enter a valid location code']
error_number = [u'Number part cannot be zero']
valid = {
'ZG 1234-AA': u'ZG 1234-AA',
'ZG 123-A': u'ZG 123-A',
}
invalid = {
'PV12345': error_invalid,
'PV1234AA': error_area,
'ZG0000CC': error_number,
}
self.assertFieldOutput(HRLicensePlateField, valid, invalid)
def test_HRPostalCodeField(self):
error_invalid = [u'Enter a valid 5 digit postal code']
valid = {
'10000': '10000',
'35410': '35410',
}
invalid = {
'ABCD': error_invalid,
'99999': error_invalid,
}
self.assertFieldOutput(HRPostalCodeField, valid, invalid)
def test_HROIBField(self):
error_invalid = [u'Enter a valid 11 digit OIB']
valid = {
'12345678901': '12345678901',
}
invalid = {
'1234567890': [u'Ensure this value has at least 11 characters (it has 10).'] + error_invalid,
'ABCDEFGHIJK': error_invalid,
}
self.assertFieldOutput(HROIBField, valid, invalid)
def test_HRJMBGField(self):
error_invalid = [u'Enter a valid 13 digit JMBG']
error_date = [u'Error in date segment']
valid = {
'1211984302155': '1211984302155',
'2701984307107': '2701984307107',
}
invalid = {
'1211984302156': error_invalid,
'ABCDEFG': error_invalid,
'9999999123456': error_date,
}
self.assertFieldOutput(HRJMBGField, valid, invalid)
def test_HRJMBAGField(self):
error_invalid = [u'Enter a valid 19 digit JMBAG starting with 601983']
error_copy = [u'Card issue number cannot be zero']
valid = {
'601983 11 0130185856 4': '6019831101301858564',
}
invalid = {
'601983 11 0130185856 5': error_invalid,
'601983 01 0130185856 4': error_copy,
}
self.assertFieldOutput(HRJMBAGField, valid, invalid)