Fixed #15837. Consolidated all the locaflavor tests into a single, logical, place (regressiontests/localflavor/).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16680 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Julien Phalip 2011-08-24 12:30:59 +00:00
parent ec1226b83f
commit a3fd9cf288
87 changed files with 483 additions and 554 deletions

View File

@ -1,50 +0,0 @@
from django.contrib.localflavor.au.forms import (AUPostCodeField,
AUPhoneNumberField, AUStateSelect)
from django.test import SimpleTestCase
class AULocalFlavorTests(SimpleTestCase):
def test_AUStateSelect(self):
f = AUStateSelect()
out = u'''<select name="state">
<option value="ACT">Australian Capital Territory</option>
<option value="NSW" selected="selected">New South Wales</option>
<option value="NT">Northern Territory</option>
<option value="QLD">Queensland</option>
<option value="SA">South Australia</option>
<option value="TAS">Tasmania</option>
<option value="VIC">Victoria</option>
<option value="WA">Western Australia</option>
</select>'''
self.assertEqual(f.render('state', 'NSW'), out)
def test_AUPostCodeField(self):
error_format = [u'Enter a 4 digit postcode.']
valid = {
'1234': '1234',
'2000': '2000',
}
invalid = {
'abcd': error_format,
'20001': [u'Ensure this value has at most 4 characters (it has 5).'] + error_format,
}
self.assertFieldOutput(AUPostCodeField, valid, invalid)
def test_AUPhoneNumberField(self):
error_format = [u'Phone numbers must contain 10 digits.']
valid = {
'1234567890': '1234567890',
'0213456789': '0213456789',
'02 13 45 67 89': '0213456789',
'(02) 1345 6789': '0213456789',
'(02) 1345-6789': '0213456789',
'(02)1345-6789': '0213456789',
'0408 123 456': '0408123456',
}
invalid = {
'123': error_format,
'1800DJANGO': error_format,
}
self.assertFieldOutput(AUPhoneNumberField, valid, invalid)

View File

@ -1,131 +0,0 @@
from django.contrib.localflavor.mk.forms import (
MKIdentityCardNumberField, MKMunicipalitySelect, UMCNField)
from django.test import SimpleTestCase
class MKLocalFlavorTests(SimpleTestCase):
def test_MKIdentityCardNumberField(self):
error_invalid = [u'Identity card numbers must contain either 4 to 7 '
'digits or an uppercase letter and 7 digits.']
valid = {
'L0018077':'L0018077',
'A0078315' : 'A0078315',
}
invalid = {
'123': error_invalid,
'abcdf': error_invalid,
'234390a': error_invalid,
}
self.assertFieldOutput(MKIdentityCardNumberField, valid, invalid)
def test_MKMunicipalitySelect(self):
f = MKMunicipalitySelect()
out=u'''<select name="municipality">
<option value="AD">Aerodrom</option>
<option value="AR">Ara\u010dinovo</option>
<option value="BR">Berovo</option>
<option value="TL">Bitola</option>
<option value="BG">Bogdanci</option>
<option value="VJ">Bogovinje</option>
<option value="BS">Bosilovo</option>
<option value="BN">Brvenica</option>
<option value="BU">Butel</option>
<option value="VA">Valandovo</option>
<option value="VL">Vasilevo</option>
<option value="VV">Vev\u010dani</option>
<option value="VE">Veles</option>
<option value="NI">Vinica</option>
<option value="VC">Vrane\u0161tica</option>
<option value="VH">Vrap\u010di\u0161te</option>
<option value="GB">Gazi Baba</option>
<option value="GV">Gevgelija</option>
<option value="GT">Gostivar</option>
<option value="GR">Gradsko</option>
<option value="DB">Debar</option>
<option value="DA">Debarca</option>
<option value="DL" selected="selected">Del\u010devo</option>
<option value="DK">Demir Kapija</option>
<option value="DM">Demir Hisar</option>
<option value="DE">Dolneni</option>
<option value="DR">Drugovo</option>
<option value="GP">Gjor\u010de Petrov</option>
<option value="ZE">\u017delino</option>
<option value="ZA">Zajas</option>
<option value="ZK">Zelenikovo</option>
<option value="ZR">Zrnovci</option>
<option value="IL">Ilinden</option>
<option value="JG">Jegunovce</option>
<option value="AV">Kavadarci</option>
<option value="KB">Karbinci</option>
<option value="KX">Karpo\u0161</option>
<option value="VD">Kisela Voda</option>
<option value="KH">Ki\u010devo</option>
<option value="KN">Kon\u010de</option>
<option value="OC">Ko\u0107ani</option>
<option value="KY">Kratovo</option>
<option value="KZ">Kriva Palanka</option>
<option value="KG">Krivoga\u0161tani</option>
<option value="KS">Kru\u0161evo</option>
<option value="UM">Kumanovo</option>
<option value="LI">Lipkovo</option>
<option value="LO">Lozovo</option>
<option value="MR">Mavrovo i Rostu\u0161a</option>
<option value="MK">Makedonska Kamenica</option>
<option value="MD">Makedonski Brod</option>
<option value="MG">Mogila</option>
<option value="NG">Negotino</option>
<option value="NV">Novaci</option>
<option value="NS">Novo Selo</option>
<option value="OS">Oslomej</option>
<option value="OD">Ohrid</option>
<option value="PE">Petrovec</option>
<option value="PH">Peh\u010devo</option>
<option value="PN">Plasnica</option>
<option value="PP">Prilep</option>
<option value="PT">Probi\u0161tip</option>
<option value="RV">Radovi\u0161</option>
<option value="RN">Rankovce</option>
<option value="RE">Resen</option>
<option value="RO">Rosoman</option>
<option value="AJ">Saraj</option>
<option value="SL">Sveti Nikole</option>
<option value="SS">Sopi\u0161te</option>
<option value="SD">Star Dojran</option>
<option value="NA">Staro Nagori\u010dane</option>
<option value="UG">Struga</option>
<option value="RU">Strumica</option>
<option value="SU">Studeni\u010dani</option>
<option value="TR">Tearce</option>
<option value="ET">Tetovo</option>
<option value="CE">Centar</option>
<option value="CZ">Centar-\u017dupa</option>
<option value="CI">\u010cair</option>
<option value="CA">\u010ca\u0161ka</option>
<option value="CH">\u010ce\u0161inovo-Oble\u0161evo</option>
<option value="CS">\u010cu\u010der-Sandevo</option>
<option value="ST">\u0160tip</option>
<option value="SO">\u0160uto Orizari</option>
</select>'''
self.assertEqual(f.render('municipality', 'DL' ), out)
def test_UMCNField(self):
error_invalid = [u'This field should contain exactly 13 digits.']
error_checksum = [u'The UMCN is not valid.']
error_date = [u'The first 7 digits of the UMCN '
'must represent a valid past date.']
valid = {
'2402983450006': '2402983450006',
'2803984430038': '2803984430038',
'1909982045004': '1909982045004',
}
invalid = {
'240298345': error_invalid,
'abcdefghj': error_invalid,
'2402082450006': error_date,
'3002982450006': error_date,
'2402983450007': error_checksum,
'2402982450006': error_checksum,
}
self.assertFieldOutput(UMCNField, valid, invalid)

View File

@ -1,127 +0,0 @@
# -*- coding: utf-8 -*-
from django.contrib.localflavor.mx.forms import (MXZipCodeField, MXRFCField,
MXStateSelect, MXCURPField)
from django.test import SimpleTestCase
class MXLocalFlavorTests(SimpleTestCase):
def test_MXStateSelect(self):
f = MXStateSelect()
out = u'''<select name="state">
<option value="AGU">Aguascalientes</option>
<option value="BCN">Baja California</option>
<option value="BCS">Baja California Sur</option>
<option value="CAM">Campeche</option>
<option value="CHH">Chihuahua</option>
<option value="CHP">Chiapas</option>
<option value="COA">Coahuila</option>
<option value="COL">Colima</option>
<option value="DIF">Distrito Federal</option>
<option value="DUR">Durango</option>
<option value="GRO">Guerrero</option>
<option value="GUA">Guanajuato</option>
<option value="HID">Hidalgo</option>
<option value="JAL">Jalisco</option>
<option value="MEX">Estado de México</option>
<option value="MIC" selected="selected">Michoacán</option>
<option value="MOR">Morelos</option>
<option value="NAY">Nayarit</option>
<option value="NLE">Nuevo León</option>
<option value="OAX">Oaxaca</option>
<option value="PUE">Puebla</option>
<option value="QUE">Querétaro</option>
<option value="ROO">Quintana Roo</option>
<option value="SIN">Sinaloa</option>
<option value="SLP">San Luis Potosí</option>
<option value="SON">Sonora</option>
<option value="TAB">Tabasco</option>
<option value="TAM">Tamaulipas</option>
<option value="TLA">Tlaxcala</option>
<option value="VER">Veracruz</option>
<option value="YUC">Yucatán</option>
<option value="ZAC">Zacatecas</option>
</select>'''
self.assertEqual(f.render('state', 'MIC'), out)
def test_MXZipCodeField(self):
error_format = [u'Enter a valid zip code in the format XXXXX.']
valid = {
'58120': u'58120',
'58502': u'58502',
'59310': u'59310',
'99999': u'99999',
}
invalid = {
'17000': error_format,
'18000': error_format,
'19000': error_format,
'00000': error_format,
}
self.assertFieldOutput(MXZipCodeField, valid, invalid)
def test_MXRFCField(self):
error_format = [u'Enter a valid RFC.']
error_checksum = [u'Invalid checksum for RFC.']
valid = {
'MoFN641205eX5': u'MOFN641205EX5',
'ICa060120873': u'ICA060120873',
'eUcG751104rT0': u'EUCG751104RT0',
'GME08100195A': u'GME08100195A',
'AA&060524KX5': u'AA&060524KX5',
'CAÑ0708045P7': u'CAÑ0708045P7',
'aaa000101aa9': u'AAA000101AA9',
}
invalid = {
'MED0000000XA': error_format,
'0000000000XA': error_format,
'AAA000000AA6': error_format,
# Dates
'XXX880002XXX': error_format,
'XXX880200XXX': error_format,
'XXX880132XXX': error_format,
'XXX880230XXX': error_format,
'XXX880431XXX': error_format,
# Incorrect checksum
'MOGR650524E73': error_checksum,
'HVA7810058F1': error_checksum,
'MoFN641205eX2': error_checksum,
'ICa060120871': error_checksum,
'eUcG751104rT7': error_checksum,
'GME081001955': error_checksum,
'AA&060524KX9': error_checksum,
'CAÑ0708045P2': error_checksum,
}
self.assertFieldOutput(MXRFCField, valid, invalid)
def test_MXCURPField(self):
error_format = [u'Enter a valid CURP.']
error_checksum = [u'Invalid checksum for CURP.']
valid = {
'AaMG890608HDFLJL00': u'AAMG890608HDFLJL00',
'BAAd890419HMNRRV07': u'BAAD890419HMNRRV07',
'VIAA900930MMNClL08': u'VIAA900930MMNCLL08',
'HEGR891009HMNRRD09': u'HEGR891009HMNRRD09',
'MARR890512HMNRMN09': u'MARR890512HMNRMN09',
'MESJ890928HMNZNS00': u'MESJ890928HMNZNS00',
'BAAA890317HDFRLL03': u'BAAA890317HDFRLL03',
'TOMA880125HMNRRNO2': u'TOMA880125HMNRRNO2',
'OOMG890727HMNRSR06': u'OOMG890727HMNRSR06',
'AAAA000101HDFCCC09': u'AAAA000101HDFCCC09',
}
invalid = {
'AAAA000000HDFCCC09': error_format,
'AAAA000000HDFAAA03': error_format,
'AAAA000000HXXCCC08': error_format,
'AAAA000000XMNCCC02': error_format,
'HEGR891009HMNRRD0A': error_format,
'MARR890512HMNRMN0A': error_format,
'AaMG890608HDFLJL01': error_checksum,
'BAAd890419HMNRRV08': error_checksum,
'VIAA900930MMNClL09': error_checksum,
'MESJ890928HMNZNS01': error_checksum,
'BAAA890317HDFRLL04': error_checksum,
'TOMA880125HMNRRNO3': error_checksum,
'OOMG890727HMNRSR07': error_checksum,
}
self.assertFieldOutput(MXCURPField, valid, invalid)

View File

@ -1,129 +0,0 @@
from django.contrib.localflavor.us.forms import (USZipCodeField,
USPhoneNumberField, USStateField, USStateSelect, USSocialSecurityNumberField)
from django.test import SimpleTestCase
class USLocalFlavorTests(SimpleTestCase):
def test_USStateSelect(self):
f = USStateSelect()
out = u'''<select name="state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AS">American Samoa</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="AA">Armed Forces Americas</option>
<option value="AE">Armed Forces Europe</option>
<option value="AP">Armed Forces Pacific</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="GU">Guam</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL" selected="selected">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="MP">Northern Mariana Islands</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="PR">Puerto Rico</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VI">Virgin Islands</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>'''
self.assertEqual(f.render('state', 'IL'), out)
def test_USZipCodeField(self):
error_format = [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.']
valid = {
'60606': '60606',
60606: '60606',
'04000': '04000',
'60606-1234': '60606-1234',
}
invalid = {
'4000': error_format,
'6060-1234': error_format,
'60606-': error_format,
}
self.assertFieldOutput(USZipCodeField, valid, invalid)
def test_USPhoneNumberField(self):
error_format = [u'Phone numbers must be in XXX-XXX-XXXX format.']
valid = {
'312-555-1212': '312-555-1212',
'3125551212': '312-555-1212',
'312 555-1212': '312-555-1212',
'(312) 555-1212': '312-555-1212',
'312 555 1212': '312-555-1212',
'312.555.1212': '312-555-1212',
'312.555-1212': '312-555-1212',
' (312) 555.1212 ': '312-555-1212',
}
invalid = {
'555-1212': error_format,
'312-55-1212': error_format,
}
self.assertFieldOutput(USPhoneNumberField, valid, invalid)
def test_USStateField(self):
error_invalid = [u'Enter a U.S. state or territory.']
valid = {
'il': 'IL',
'IL': 'IL',
'illinois': 'IL',
' illinois ': 'IL',
}
invalid = {
60606: error_invalid,
}
self.assertFieldOutput(USStateField, valid, invalid)
def test_USSocialSecurityNumberField(self):
error_invalid = [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.']
valid = {
'987-65-4330': '987-65-4330',
'987654330': '987-65-4330',
}
invalid = {
'078-05-1120': error_invalid,
}
self.assertFieldOutput(USSocialSecurityNumberField, valid, invalid)

View File

@ -1,42 +0,0 @@
from localflavor.ar import ARLocalFlavorTests
from localflavor.at import ATLocalFlavorTests
from localflavor.au import AULocalFlavorTests
from localflavor.be import BELocalFlavorTests
from localflavor.br import BRLocalFlavorTests
from localflavor.ca import CALocalFlavorTests
from localflavor.ch import CHLocalFlavorTests
from localflavor.cl import CLLocalFlavorTests
from localflavor.cz import CZLocalFlavorTests
from localflavor.cn import CNLocalFlavorTests
from localflavor.co import COLocalFlavorTests
from localflavor.de import DELocalFlavorTests
from localflavor.es import ESLocalFlavorTests
from localflavor.ec import ECLocalFlavorTests
from localflavor.fi import FILocalFlavorTests
from localflavor.fr import FRLocalFlavorTests
from localflavor.gb import GBLocalFlavorTests
from localflavor.generic import GenericLocalFlavorTests
from localflavor.hr import HRLocalFlavorTests
from localflavor.id import IDLocalFlavorTests
from localflavor.ie import IELocalFlavorTests
from localflavor.il import ILLocalFlavorTests
from localflavor.is_ import ISLocalFlavorTests
from localflavor.in_ import INLocalFlavorTests
from localflavor.it import ITLocalFlavorTests
from localflavor.jp import JPLocalFlavorTests
from localflavor.kw import KWLocalFlavorTests
from localflavor.mk import MKLocalFlavorTests
from localflavor.mx import MXLocalFlavorTests
from localflavor.nl import NLLocalFlavorTests
from localflavor.pl import PLLocalFlavorTests
from localflavor.pt import PTLocalFlavorTests
from localflavor.py import PYLocalFlavorTests
from localflavor.ro import ROLocalFlavorTests
from localflavor.ru import RULocalFlavorTests
from localflavor.se import SELocalFlavorTests
from localflavor.sk import SKLocalFlavorTests
from localflavor.tr import TRLocalFlavorTests
from localflavor.us import USLocalFlavorTests
from localflavor.uy import UYLocalFlavorTests
from localflavor.za import ZALocalFlavorTests

View File

@ -10,47 +10,3 @@ from regressions import *
from util import * from util import *
from validators import TestFieldWithValidators from validators import TestFieldWithValidators
from widgets import * from widgets import *
from regressiontests.forms.localflavortests import (
ARLocalFlavorTests,
ATLocalFlavorTests,
AULocalFlavorTests,
BELocalFlavorTests,
BRLocalFlavorTests,
CALocalFlavorTests,
CHLocalFlavorTests,
CLLocalFlavorTests,
CNLocalFlavorTests,
COLocalFlavorTests,
CZLocalFlavorTests,
DELocalFlavorTests,
ECLocalFlavorTests,
ESLocalFlavorTests,
FILocalFlavorTests,
FRLocalFlavorTests,
GBLocalFlavorTests,
GenericLocalFlavorTests,
HRLocalFlavorTests,
IDLocalFlavorTests,
IELocalFlavorTests,
ILLocalFlavorTests,
ISLocalFlavorTests,
INLocalFlavorTests,
ITLocalFlavorTests,
JPLocalFlavorTests,
KWLocalFlavorTests,
MKLocalFlavorTests,
MXLocalFlavorTests,
NLLocalFlavorTests,
PLLocalFlavorTests,
PTLocalFlavorTests,
PYLocalFlavorTests,
ROLocalFlavorTests,
RULocalFlavorTests,
SELocalFlavorTests,
SKLocalFlavorTests,
TRLocalFlavorTests,
USLocalFlavorTests,
UYLocalFlavorTests,
ZALocalFlavorTests,
)

View File

@ -1,6 +1,9 @@
import re import re
from django.test import TestCase from django.test import SimpleTestCase
from django.contrib.localflavor.au.forms import (AUPostCodeField,
AUPhoneNumberField, AUStateSelect)
from forms import AustralianPlaceForm from forms import AustralianPlaceForm
SELECTED_OPTION_PATTERN = r'<option value="%s" selected="selected">' SELECTED_OPTION_PATTERN = r'<option value="%s" selected="selected">'
@ -8,7 +11,8 @@ BLANK_OPTION_PATTERN = r'<option value="">'
INPUT_VALUE_PATTERN = r'<input[^>]*value="%s"[^>]*>' INPUT_VALUE_PATTERN = r'<input[^>]*value="%s"[^>]*>'
class AULocalflavorTests(TestCase): class AULocalflavorTests(SimpleTestCase):
def setUp(self): def setUp(self):
self.form = AustralianPlaceForm( self.form = AustralianPlaceForm(
{'state':'WA', {'state':'WA',
@ -56,3 +60,46 @@ class AULocalflavorTests(TestCase):
str(self.form['postcode']))) str(self.form['postcode'])))
self.assertTrue(re.search(INPUT_VALUE_PATTERN % '4321', self.assertTrue(re.search(INPUT_VALUE_PATTERN % '4321',
str(self.form['postcode_required']))) str(self.form['postcode_required'])))
def test_AUStateSelect(self):
f = AUStateSelect()
out = u'''<select name="state">
<option value="ACT">Australian Capital Territory</option>
<option value="NSW" selected="selected">New South Wales</option>
<option value="NT">Northern Territory</option>
<option value="QLD">Queensland</option>
<option value="SA">South Australia</option>
<option value="TAS">Tasmania</option>
<option value="VIC">Victoria</option>
<option value="WA">Western Australia</option>
</select>'''
self.assertEqual(f.render('state', 'NSW'), out)
def test_AUPostCodeField(self):
error_format = [u'Enter a 4 digit postcode.']
valid = {
'1234': '1234',
'2000': '2000',
}
invalid = {
'abcd': error_format,
'20001': [u'Ensure this value has at most 4 characters (it has 5).'] + error_format,
}
self.assertFieldOutput(AUPostCodeField, valid, invalid)
def test_AUPhoneNumberField(self):
error_format = [u'Phone numbers must contain 10 digits.']
valid = {
'1234567890': '1234567890',
'0213456789': '0213456789',
'02 13 45 67 89': '0213456789',
'(02) 1345 6789': '0213456789',
'(02) 1345-6789': '0213456789',
'(02)1345-6789': '0213456789',
'0408 123 456': '0408123456',
}
invalid = {
'123': error_format,
'1800DJANGO': error_format,
}
self.assertFieldOutput(AUPhoneNumberField, valid, invalid)

View File

@ -72,4 +72,3 @@ class CHLocalFlavorTests(SimpleTestCase):
'2123456701': error_format, '2123456701': error_format,
} }
self.assertFieldOutput(CHIdentityCardNumberField, valid, invalid) self.assertFieldOutput(CHIdentityCardNumberField, valid, invalid)

View File

@ -110,4 +110,3 @@ class CNLocalFlavorTests(SimpleTestCase):
'14012345678': error_format '14012345678': error_format
} }
self.assertFieldOutput(CNCellNumberField, valid, invalid) self.assertFieldOutput(CNCellNumberField, valid, invalid)

View File

@ -169,5 +169,3 @@ class ESLocalFlavorTests(SimpleTestCase):
'2077-03-3879-3100254321': error_invalid, '2077-03-3879-3100254321': error_invalid,
} }
self.assertFieldOutput(ESCCCField, valid, invalid) self.assertFieldOutput(ESCCCField, valid, invalid)

View File

@ -379,4 +379,3 @@ class FILocalFlavorTests(SimpleTestCase):
'101010b0101': error_invalid, '101010b0101': error_invalid,
} }
self.assertFieldOutput(FISocialSecurityNumber, valid, invalid) self.assertFieldOutput(FISocialSecurityNumber, valid, invalid)

View File

@ -196,4 +196,3 @@ class ISLocalFlavorTests(SimpleTestCase):
' 12367 ': error_invalid ' 12367 ': error_invalid
} }
self.assertFieldOutput(ISPhoneNumberField, valid, invalid) self.assertFieldOutput(ISPhoneNumberField, valid, invalid)

View File

@ -67,4 +67,3 @@ class ITLocalFlavorTests(SimpleTestCase):
'A7973780013': error_invalid, 'A7973780013': error_invalid,
} }
self.assertFieldOutput(ITVatNumberField, valid, invalid) self.assertFieldOutput(ITVatNumberField, valid, invalid)

View File

@ -13,4 +13,3 @@ class KWLocalFlavorTests(SimpleTestCase):
'289332013455': error_invalid, '289332013455': error_invalid,
} }
self.assertFieldOutput(KWCivilIDNumberField, valid, invalid) self.assertFieldOutput(KWCivilIDNumberField, valid, invalid)

View File

@ -1,7 +1,11 @@
from django.test import TestCase from django.contrib.localflavor.mk.forms import (
MKIdentityCardNumberField, MKMunicipalitySelect, UMCNField)
from django.test import SimpleTestCase
from forms import MKPersonForm from forms import MKPersonForm
class MKLocalflavorTests(TestCase): class MKLocalflavorTests(SimpleTestCase):
def setUp(self): def setUp(self):
self.form = MKPersonForm({ self.form = MKPersonForm({
'first_name':'Someone', 'first_name':'Someone',
@ -174,3 +178,127 @@ class MKLocalflavorTests(TestCase):
<option value="SO">\xc5\xa0uto Orizari</option> <option value="SO">\xc5\xa0uto Orizari</option>
</select>""" </select>"""
self.assertEqual(str(self.form['municipality']), municipality_select_html) self.assertEqual(str(self.form['municipality']), municipality_select_html)
def test_MKIdentityCardNumberField(self):
error_invalid = [u'Identity card numbers must contain either 4 to 7 '
'digits or an uppercase letter and 7 digits.']
valid = {
'L0018077':'L0018077',
'A0078315' : 'A0078315',
}
invalid = {
'123': error_invalid,
'abcdf': error_invalid,
'234390a': error_invalid,
}
self.assertFieldOutput(MKIdentityCardNumberField, valid, invalid)
def test_MKMunicipalitySelect(self):
f = MKMunicipalitySelect()
out=u'''<select name="municipality">
<option value="AD">Aerodrom</option>
<option value="AR">Ara\u010dinovo</option>
<option value="BR">Berovo</option>
<option value="TL">Bitola</option>
<option value="BG">Bogdanci</option>
<option value="VJ">Bogovinje</option>
<option value="BS">Bosilovo</option>
<option value="BN">Brvenica</option>
<option value="BU">Butel</option>
<option value="VA">Valandovo</option>
<option value="VL">Vasilevo</option>
<option value="VV">Vev\u010dani</option>
<option value="VE">Veles</option>
<option value="NI">Vinica</option>
<option value="VC">Vrane\u0161tica</option>
<option value="VH">Vrap\u010di\u0161te</option>
<option value="GB">Gazi Baba</option>
<option value="GV">Gevgelija</option>
<option value="GT">Gostivar</option>
<option value="GR">Gradsko</option>
<option value="DB">Debar</option>
<option value="DA">Debarca</option>
<option value="DL" selected="selected">Del\u010devo</option>
<option value="DK">Demir Kapija</option>
<option value="DM">Demir Hisar</option>
<option value="DE">Dolneni</option>
<option value="DR">Drugovo</option>
<option value="GP">Gjor\u010de Petrov</option>
<option value="ZE">\u017delino</option>
<option value="ZA">Zajas</option>
<option value="ZK">Zelenikovo</option>
<option value="ZR">Zrnovci</option>
<option value="IL">Ilinden</option>
<option value="JG">Jegunovce</option>
<option value="AV">Kavadarci</option>
<option value="KB">Karbinci</option>
<option value="KX">Karpo\u0161</option>
<option value="VD">Kisela Voda</option>
<option value="KH">Ki\u010devo</option>
<option value="KN">Kon\u010de</option>
<option value="OC">Ko\u0107ani</option>
<option value="KY">Kratovo</option>
<option value="KZ">Kriva Palanka</option>
<option value="KG">Krivoga\u0161tani</option>
<option value="KS">Kru\u0161evo</option>
<option value="UM">Kumanovo</option>
<option value="LI">Lipkovo</option>
<option value="LO">Lozovo</option>
<option value="MR">Mavrovo i Rostu\u0161a</option>
<option value="MK">Makedonska Kamenica</option>
<option value="MD">Makedonski Brod</option>
<option value="MG">Mogila</option>
<option value="NG">Negotino</option>
<option value="NV">Novaci</option>
<option value="NS">Novo Selo</option>
<option value="OS">Oslomej</option>
<option value="OD">Ohrid</option>
<option value="PE">Petrovec</option>
<option value="PH">Peh\u010devo</option>
<option value="PN">Plasnica</option>
<option value="PP">Prilep</option>
<option value="PT">Probi\u0161tip</option>
<option value="RV">Radovi\u0161</option>
<option value="RN">Rankovce</option>
<option value="RE">Resen</option>
<option value="RO">Rosoman</option>
<option value="AJ">Saraj</option>
<option value="SL">Sveti Nikole</option>
<option value="SS">Sopi\u0161te</option>
<option value="SD">Star Dojran</option>
<option value="NA">Staro Nagori\u010dane</option>
<option value="UG">Struga</option>
<option value="RU">Strumica</option>
<option value="SU">Studeni\u010dani</option>
<option value="TR">Tearce</option>
<option value="ET">Tetovo</option>
<option value="CE">Centar</option>
<option value="CZ">Centar-\u017dupa</option>
<option value="CI">\u010cair</option>
<option value="CA">\u010ca\u0161ka</option>
<option value="CH">\u010ce\u0161inovo-Oble\u0161evo</option>
<option value="CS">\u010cu\u010der-Sandevo</option>
<option value="ST">\u0160tip</option>
<option value="SO">\u0160uto Orizari</option>
</select>'''
self.assertEqual(f.render('municipality', 'DL' ), out)
def test_UMCNField(self):
error_invalid = [u'This field should contain exactly 13 digits.']
error_checksum = [u'The UMCN is not valid.']
error_date = [u'The first 7 digits of the UMCN '
'must represent a valid past date.']
valid = {
'2402983450006': '2402983450006',
'2803984430038': '2803984430038',
'1909982045004': '1909982045004',
}
invalid = {
'240298345': error_invalid,
'abcdefghj': error_invalid,
'2402082450006': error_date,
'3002982450006': error_date,
'2402983450007': error_checksum,
'2402982450006': error_checksum,
}
self.assertFieldOutput(UMCNField, valid, invalid)

View File

@ -1,8 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.test import TestCase from django.contrib.localflavor.mx.forms import (MXZipCodeField, MXRFCField,
MXStateSelect, MXCURPField)
from django.test import SimpleTestCase
from forms import MXPersonProfileForm from forms import MXPersonProfileForm
class MXLocalFlavorTests(TestCase): class MXLocalFlavorTests(SimpleTestCase):
def setUp(self): def setUp(self):
self.form = MXPersonProfileForm({ self.form = MXPersonProfileForm({
'state': 'MIC', 'state': 'MIC',
@ -69,3 +73,123 @@ class MXLocalFlavorTests(TestCase):
<option value="ZAC">Zacatecas</option> <option value="ZAC">Zacatecas</option>
</select>""" </select>"""
self.assertEqual(str(self.form['state']), state_select_html) self.assertEqual(str(self.form['state']), state_select_html)
def test_MXStateSelect(self):
f = MXStateSelect()
out = u'''<select name="state">
<option value="AGU">Aguascalientes</option>
<option value="BCN">Baja California</option>
<option value="BCS">Baja California Sur</option>
<option value="CAM">Campeche</option>
<option value="CHH">Chihuahua</option>
<option value="CHP">Chiapas</option>
<option value="COA">Coahuila</option>
<option value="COL">Colima</option>
<option value="DIF">Distrito Federal</option>
<option value="DUR">Durango</option>
<option value="GRO">Guerrero</option>
<option value="GUA">Guanajuato</option>
<option value="HID">Hidalgo</option>
<option value="JAL">Jalisco</option>
<option value="MEX">Estado de México</option>
<option value="MIC" selected="selected">Michoacán</option>
<option value="MOR">Morelos</option>
<option value="NAY">Nayarit</option>
<option value="NLE">Nuevo León</option>
<option value="OAX">Oaxaca</option>
<option value="PUE">Puebla</option>
<option value="QUE">Querétaro</option>
<option value="ROO">Quintana Roo</option>
<option value="SIN">Sinaloa</option>
<option value="SLP">San Luis Potosí</option>
<option value="SON">Sonora</option>
<option value="TAB">Tabasco</option>
<option value="TAM">Tamaulipas</option>
<option value="TLA">Tlaxcala</option>
<option value="VER">Veracruz</option>
<option value="YUC">Yucatán</option>
<option value="ZAC">Zacatecas</option>
</select>'''
self.assertEqual(f.render('state', 'MIC'), out)
def test_MXZipCodeField(self):
error_format = [u'Enter a valid zip code in the format XXXXX.']
valid = {
'58120': u'58120',
'58502': u'58502',
'59310': u'59310',
'99999': u'99999',
}
invalid = {
'17000': error_format,
'18000': error_format,
'19000': error_format,
'00000': error_format,
}
self.assertFieldOutput(MXZipCodeField, valid, invalid)
def test_MXRFCField(self):
error_format = [u'Enter a valid RFC.']
error_checksum = [u'Invalid checksum for RFC.']
valid = {
'MoFN641205eX5': u'MOFN641205EX5',
'ICa060120873': u'ICA060120873',
'eUcG751104rT0': u'EUCG751104RT0',
'GME08100195A': u'GME08100195A',
'AA&060524KX5': u'AA&060524KX5',
'CAÑ0708045P7': u'CAÑ0708045P7',
'aaa000101aa9': u'AAA000101AA9',
}
invalid = {
'MED0000000XA': error_format,
'0000000000XA': error_format,
'AAA000000AA6': error_format,
# Dates
'XXX880002XXX': error_format,
'XXX880200XXX': error_format,
'XXX880132XXX': error_format,
'XXX880230XXX': error_format,
'XXX880431XXX': error_format,
# Incorrect checksum
'MOGR650524E73': error_checksum,
'HVA7810058F1': error_checksum,
'MoFN641205eX2': error_checksum,
'ICa060120871': error_checksum,
'eUcG751104rT7': error_checksum,
'GME081001955': error_checksum,
'AA&060524KX9': error_checksum,
'CAÑ0708045P2': error_checksum,
}
self.assertFieldOutput(MXRFCField, valid, invalid)
def test_MXCURPField(self):
error_format = [u'Enter a valid CURP.']
error_checksum = [u'Invalid checksum for CURP.']
valid = {
'AaMG890608HDFLJL00': u'AAMG890608HDFLJL00',
'BAAd890419HMNRRV07': u'BAAD890419HMNRRV07',
'VIAA900930MMNClL08': u'VIAA900930MMNCLL08',
'HEGR891009HMNRRD09': u'HEGR891009HMNRRD09',
'MARR890512HMNRMN09': u'MARR890512HMNRMN09',
'MESJ890928HMNZNS00': u'MESJ890928HMNZNS00',
'BAAA890317HDFRLL03': u'BAAA890317HDFRLL03',
'TOMA880125HMNRRNO2': u'TOMA880125HMNRRNO2',
'OOMG890727HMNRSR06': u'OOMG890727HMNRSR06',
'AAAA000101HDFCCC09': u'AAAA000101HDFCCC09',
}
invalid = {
'AAAA000000HDFCCC09': error_format,
'AAAA000000HDFAAA03': error_format,
'AAAA000000HXXCCC08': error_format,
'AAAA000000XMNCCC02': error_format,
'HEGR891009HMNRRD0A': error_format,
'MARR890512HMNRMN0A': error_format,
'AaMG890608HDFLJL01': error_checksum,
'BAAd890419HMNRRV08': error_checksum,
'VIAA900930MMNClL09': error_checksum,
'MESJ890928HMNZNS01': error_checksum,
'BAAA890317HDFRLL04': error_checksum,
'TOMA880125HMNRRNO3': error_checksum,
'OOMG890727HMNRSR07': error_checksum,
}
self.assertFieldOutput(MXCURPField, valid, invalid)

View File

@ -162,4 +162,3 @@ class SELocalFlavorTests(SimpleTestCase):
} }
self.assertFieldOutput(SEPostalCodeField, valid, invalid) self.assertFieldOutput(SEPostalCodeField, valid, invalid)

View File

@ -1,5 +1,41 @@
from ar.tests import *
from at.tests import *
from au.tests import * from au.tests import *
from be.tests import *
from br.tests import *
from ca.tests import *
from ch.tests import *
from cl.tests import *
from cn.tests import *
from co.tests import *
from cz.tests import *
from de.tests import *
from ec.tests import *
from es.tests import *
from fi.tests import *
from fr.tests import *
from gb.tests import *
from generic.tests import *
from hr.tests import *
from id.tests import *
from ie.tests import *
from il.tests import *
from in_.tests import *
from is_.tests import *
from it.tests import *
from jp.tests import *
from kw.tests import *
from mk.tests import * from mk.tests import *
from mx.tests import * from mx.tests import *
from nl.tests import *
from pl.tests import *
from pt.tests import *
from py.tests import *
from ro.tests import *
from ru.tests import *
from se.tests import *
from sk.tests import *
from tr.tests import *
from us.tests import * from us.tests import *
from uy.tests import *
from za.tests import *

View File

@ -1,7 +1,12 @@
from django.test import TestCase from django.contrib.localflavor.us.forms import (USZipCodeField,
USPhoneNumberField, USStateField, USStateSelect,
USSocialSecurityNumberField)
from django.test import SimpleTestCase
from forms import USPlaceForm from forms import USPlaceForm
class USLocalflavorTests(TestCase): class USLocalflavorTests(SimpleTestCase):
def setUp(self): def setUp(self):
self.form = USPlaceForm({'state':'GA', 'state_req':'NC', 'postal_code': 'GA', 'name':'impossible'}) self.form = USPlaceForm({'state':'GA', 'state_req':'NC', 'postal_code': 'GA', 'name':'impossible'})
@ -153,3 +158,126 @@ class USLocalflavorTests(TestCase):
<option value="WY">Wyoming</option> <option value="WY">Wyoming</option>
</select>""" </select>"""
self.assertEqual(str(self.form['postal_code']), usps_select_html) self.assertEqual(str(self.form['postal_code']), usps_select_html)
def test_USStateSelect(self):
f = USStateSelect()
out = u'''<select name="state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AS">American Samoa</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="AA">Armed Forces Americas</option>
<option value="AE">Armed Forces Europe</option>
<option value="AP">Armed Forces Pacific</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="GU">Guam</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL" selected="selected">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="MP">Northern Mariana Islands</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="PR">Puerto Rico</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VI">Virgin Islands</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>'''
self.assertEqual(f.render('state', 'IL'), out)
def test_USZipCodeField(self):
error_format = [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.']
valid = {
'60606': '60606',
60606: '60606',
'04000': '04000',
'60606-1234': '60606-1234',
}
invalid = {
'4000': error_format,
'6060-1234': error_format,
'60606-': error_format,
}
self.assertFieldOutput(USZipCodeField, valid, invalid)
def test_USPhoneNumberField(self):
error_format = [u'Phone numbers must be in XXX-XXX-XXXX format.']
valid = {
'312-555-1212': '312-555-1212',
'3125551212': '312-555-1212',
'312 555-1212': '312-555-1212',
'(312) 555-1212': '312-555-1212',
'312 555 1212': '312-555-1212',
'312.555.1212': '312-555-1212',
'312.555-1212': '312-555-1212',
' (312) 555.1212 ': '312-555-1212',
}
invalid = {
'555-1212': error_format,
'312-55-1212': error_format,
}
self.assertFieldOutput(USPhoneNumberField, valid, invalid)
def test_USStateField(self):
error_invalid = [u'Enter a U.S. state or territory.']
valid = {
'il': 'IL',
'IL': 'IL',
'illinois': 'IL',
' illinois ': 'IL',
}
invalid = {
60606: error_invalid,
}
self.assertFieldOutput(USStateField, valid, invalid)
def test_USSocialSecurityNumberField(self):
error_invalid = [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.']
valid = {
'987-65-4330': '987-65-4330',
'987654330': '987-65-4330',
}
invalid = {
'078-05-1120': error_invalid,
}
self.assertFieldOutput(USSocialSecurityNumberField, valid, invalid)

View File

@ -49,4 +49,3 @@ class UYLocalFlavorTests(SimpleTestCase):
self.assertFieldOutput(UYCIField, valid, invalid) self.assertFieldOutput(UYCIField, valid, invalid)
self.assertEqual(get_validation_digit(409805), 3) self.assertEqual(get_validation_digit(409805), 3)
self.assertEqual(get_validation_digit(1005411), 2) self.assertEqual(get_validation_digit(1005411), 2)