Ticket #15813: in_states_normalized_patch_with_better_tests.v3.diff
File in_states_normalized_patch_with_better_tests.v3.diff, 9.8 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/forms/tests/__init__.py
33 33 IELocalFlavorTests, 34 34 ILLocalFlavorTests, 35 35 ISLocalFlavorTests, 36 INLocalFlavorTests, 36 37 ITLocalFlavorTests, 37 38 JPLocalFlavorTests, 38 39 KWLocalFlavorTests, -
tests/regressiontests/forms/localflavor/in_.py
1 import warnings 2 3 from django.contrib.localflavor.in_.forms import (INZipCodeField, 4 INStateField, INStateSelect) 5 6 from utils import LocalFlavorTestCase 7 8 9 class INLocalFlavorTests(LocalFlavorTestCase): 10 def test_INPStateSelect(self): 11 f = INStateSelect() 12 out = u'''<select name="state"> 13 <option value="KA">Karnataka</option> 14 <option value="AP" selected="selected">Andhra Pradesh</option> 15 <option value="KL">Kerala</option> 16 <option value="TN">Tamil Nadu</option> 17 <option value="MH">Maharashtra</option> 18 <option value="UP">Uttar Pradesh</option> 19 <option value="GA">Goa</option> 20 <option value="GJ">Gujarat</option> 21 <option value="RJ">Rajasthan</option> 22 <option value="HP">Himachal Pradesh</option> 23 <option value="JK">Jammu and Kashmir</option> 24 <option value="AR">Arunachal Pradesh</option> 25 <option value="AS">Assam</option> 26 <option value="BR">Bihar</option> 27 <option value="CG">Chattisgarh</option> 28 <option value="HR">Haryana</option> 29 <option value="JH">Jharkhand</option> 30 <option value="MP">Madhya Pradesh</option> 31 <option value="MN">Manipur</option> 32 <option value="ML">Meghalaya</option> 33 <option value="MZ">Mizoram</option> 34 <option value="NL">Nagaland</option> 35 <option value="OR">Orissa</option> 36 <option value="PB">Punjab</option> 37 <option value="SK">Sikkim</option> 38 <option value="TR">Tripura</option> 39 <option value="UA">Uttarakhand</option> 40 <option value="WB">West Bengal</option> 41 <option value="AN">Andaman and Nicobar</option> 42 <option value="CH">Chandigarh</option> 43 <option value="DN">Dadra and Nagar Haveli</option> 44 <option value="DD">Daman and Diu</option> 45 <option value="DL">Delhi</option> 46 <option value="LD">Lakshadweep</option> 47 <option value="PY">Pondicherry</option> 48 </select>''' 49 self.assertEqual(f.render('state', 'AP'), out) 50 51 def test_INZipCodeField(self): 52 error_format = [u'Enter a zip code in the format XXXXXXX.'] 53 valid = { 54 '360311': '360311', 55 '360 311': '360311', 56 57 } 58 invalid = { 59 '36 0311': error_format, 60 '3603111': error_format, 61 '360 31': error_format, 62 '36031': error_format, 63 'O2B 2R3': error_format 64 } 65 self.assertFieldOutput(INZipCodeField, valid, invalid) 66 67 def test_INStateField(self): 68 error_format = [u'Enter an Indian state or territory.'] 69 valid = { 70 'an': 'AN', 71 'AN': 'AN', 72 'andaman and nicobar': 'AN', 73 'andra pradesh': 'AP', 74 'andrapradesh': 'AP', 75 'andhrapradesh': 'AP', 76 'ap': 'AP', 77 'andhra pradesh': 'AP', 78 'ar': 'AR', 79 'arunachal pradesh': 'AR', 80 'assam': 'AS', 81 'as': 'AS', 82 'bihar': 'BR', 83 'br': 'BR', 84 'cg': 'CG', 85 'chattisgarh': 'CG', 86 'ch': 'CH', 87 'chandigarh': 'CH', 88 'daman and diu': 'DD', 89 'dd': 'DD', 90 'dl': 'DL', 91 'delhi': 'DL', 92 'dn': 'DN', 93 'dadra and nagar haveli': 'DN', 94 'ga': 'GA', 95 'goa': 'GA', 96 'gj': 'GJ', 97 'gujarat': 'GJ', 98 'himachal pradesh': 'HP', 99 'hp': 'HP', 100 'hr': 'HR', 101 'haryana': 'HR', 102 'jharkhand': 'JH', 103 'jh': 'JH', 104 'jammu and kashmir': 'JK', 105 'jk': 'JK', 106 'karnataka': 'KA', 107 'karnatka': 'KA', 108 'ka': 'KA', 109 'kerala': 'KL', 110 'kl': 'KL', 111 'ld': 'LD', 112 'lakshadweep': 'LD', 113 'maharastra': 'MH', 114 'mh': 'MH', 115 'maharashtra': 'MH', 116 'meghalaya': 'ML', 117 'ml': 'ML', 118 'mn': 'MN', 119 'manipur': 'MN', 120 'madhya pradesh': 'MP', 121 'mp': 'MP', 122 'mizoram': 'MZ', 123 'mizo': 'MZ', 124 'mz': 'MZ', 125 'nl': 'NL', 126 'nagaland': 'NL', 127 'orissa': 'OR', 128 'odisa': 'OR', 129 'orisa': 'OR', 130 'or': 'OR', 131 'pb': 'PB', 132 'punjab': 'PB', 133 'py': 'PY', 134 'pondicherry': 'PY', 135 'rajasthan': 'RJ', 136 'rajastan': 'RJ', 137 'rj': 'RJ', 138 'sikkim': 'SK', 139 'sk': 'SK', 140 'tamil nadu': 'TN', 141 'tn': 'TN', 142 'tamilnadu': 'TN', 143 'tamilnad': 'TN', 144 'tr': 'TR', 145 'tripura': 'TR', 146 'ua': 'UA', 147 'uttarakhand': 'UA', 148 'up': 'UP', 149 'uttar pradesh': 'UP', 150 'westbengal': 'WB', 151 'bengal': 'WB', 152 'wb': 'WB', 153 'west bengal': 'WB' 154 } 155 invalid = { 156 'florida': error_format, 157 'FL': error_format, 158 } 159 self.assertFieldOutput(INStateField, valid, invalid) -
tests/regressiontests/forms/localflavortests.py
19 19 from localflavor.ie import IELocalFlavorTests 20 20 from localflavor.il import ILLocalFlavorTests 21 21 from localflavor.is_ import ISLocalFlavorTests 22 from localflavor.in_ import INLocalFlavorTests 22 23 from localflavor.it import ITLocalFlavorTests 23 24 from localflavor.jp import JPLocalFlavorTests 24 25 from localflavor.kw import KWLocalFlavorTests -
django/contrib/localflavor/in_/in_states.py
47 47 ) 48 48 49 49 STATES_NORMALIZED = { 50 'ka': 'KA', 51 'karnatka': 'KA', 52 'tn': 'TN', 53 'tamilnad': 'TN', 54 'tamilnadu': 'TN', 50 'an': 'AN', 51 'andaman and nicobar': 'AN', 55 52 'andra pradesh': 'AP', 56 53 'andrapradesh': 'AP', 57 54 'andhrapradesh': 'AP', 58 'maharastra': 'MH',59 'mh': 'MH',60 55 'ap': 'AP', 56 'andhra pradesh': 'AP', 57 'ar': 'AR', 58 'arunachal pradesh': 'AR', 59 'assam': 'AS', 60 'as': 'AS', 61 'bihar': 'BR', 62 'br': 'BR', 63 'cg': 'CG', 64 'chattisgarh': 'CG', 65 'ch': 'CH', 66 'chandigarh': 'CH', 67 'daman and diu': 'DD', 68 'dd': 'DD', 61 69 'dl': 'DL', 62 'dd': 'DD', 63 'br': 'BR', 64 'ar': 'AR', 65 'sk': 'SK', 66 'kl': 'KL', 70 'delhi': 'DL', 71 'dn': 'DN', 72 'dadra and nagar haveli': 'DN', 67 73 'ga': 'GA', 68 'rj': 'RJ', 69 'rajastan': 'RJ', 70 'rajasthan': 'RJ', 74 'goa': 'GA', 75 'gj': 'GJ', 76 'gujarat': 'GJ', 77 'himachal pradesh': 'HP', 71 78 'hp': 'HP', 72 'ua': 'UA', 73 'up': 'UP', 79 'hr': 'HR', 80 'haryana': 'HR', 81 'jharkhand': 'JH', 82 'jh': 'JH', 83 'jammu and kashmir': 'JK', 84 'jk': 'JK', 85 'karnataka': 'KA', 86 'karnatka': 'KA', 87 'ka': 'KA', 88 'kerala': 'KL', 89 'kl': 'KL', 90 'ld': 'LD', 91 'lakshadweep': 'LD', 92 'maharastra': 'MH', 93 'mh': 'MH', 94 'maharashtra': 'MH', 95 'meghalaya': 'ML', 96 'ml': 'ML', 97 'mn': 'MN', 98 'manipur': 'MN', 99 'madhya pradesh': 'MP', 74 100 'mp': 'MP', 101 'mizoram': 'MZ', 102 'mizo': 'MZ', 75 103 'mz': 'MZ', 76 'bengal': 'WB', 77 'westbengal': 'WB', 78 'mizo': 'MZ', 104 'nl': 'NL', 105 'nagaland': 'NL', 106 'orissa': 'OR', 107 'odisa': 'OR', 79 108 'orisa': 'OR', 80 'odisa': 'OR',81 109 'or': 'OR', 82 'ar': 'AR', 110 'pb': 'PB', 111 'punjab': 'PB', 112 'py': 'PY', 113 'pondicherry': 'PY', 114 'rajasthan': 'RJ', 115 'rajastan': 'RJ', 116 'rj': 'RJ', 117 'sikkim': 'SK', 118 'sk': 'SK', 119 'tamil nadu': 'TN', 120 'tn': 'TN', 121 'tamilnadu': 'TN', 122 'tamilnad': 'TN', 123 'tr': 'TR', 124 'tripura': 'TR', 125 'ua': 'UA', 126 'uttarakhand': 'UA', 127 'up': 'UP', 128 'uttar pradesh': 'UP', 129 'westbengal': 'WB', 130 'bengal': 'WB', 131 'wb': 'WB', 132 'west bengal': 'WB' 83 133 } 84 134 -
django/contrib/localflavor/in_/forms.py
16 16 } 17 17 18 18 def __init__(self, max_length=None, min_length=None, *args, **kwargs): 19 super(INZipCodeField, self).__init__(r'^\d{ 6}$',19 super(INZipCodeField, self).__init__(r'^\d{3}\s?\d{3}$', 20 20 max_length, min_length, *args, **kwargs) 21 22 def clean(self, value): 23 super(INZipCodeField, self).clean(value) 24 if value in EMPTY_VALUES: 25 return u'' 26 # Convert to "NNNNNN" if "NNN NNN" given 27 value = re.sub(r'^(\d{3})\s(\d{3})$', r'\1\2', value) 28 return value 21 29 22 30 class INStateField(Field): 23 31 """ … … 26 34 registration abbreviation for the given state or union territory 27 35 """ 28 36 default_error_messages = { 29 'invalid': u'Enter a Indian state or territory.',37 'invalid': u'Enter an Indian state or territory.', 30 38 } 31 39 32 40 def clean(self, value):