| 1 | # -*- coding: utf-8 -*- |
| 2 | # Tests for the contrib/localflavor/ BE form fields. |
| 3 | |
| 4 | tests = r""" |
| 5 | # BEPostalCodeField ############################################################## |
| 6 | |
| 7 | BEPostalCodeField validates that data is a four-digit belgium postal code following the regex ^[1-9](/d){3}$. |
| 8 | >>> from django.contrib.localflavor.be.forms import BEPostalCodeField |
| 9 | >>> f = BEPostalCodeField() |
| 10 | >>> f.clean('1451') |
| 11 | u'1451' |
| 12 | >>> f.clean('2540') |
| 13 | u'2540' |
| 14 | >>> f.clean('0287') |
| 15 | Traceback (most recent call last): |
| 16 | ... |
| 17 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 18 | >>> f.clean('14309') |
| 19 | Traceback (most recent call last): |
| 20 | ... |
| 21 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 22 | >>> f.clean('873') |
| 23 | Traceback (most recent call last): |
| 24 | ... |
| 25 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 26 | >>> f.clean('35 74') |
| 27 | Traceback (most recent call last): |
| 28 | ... |
| 29 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 30 | >>> f.clean('859A') |
| 31 | Traceback (most recent call last): |
| 32 | ... |
| 33 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 34 | >>> f.clean('') |
| 35 | Traceback (most recent call last): |
| 36 | ... |
| 37 | ValidationError: [u'This field is required.'] |
| 38 | |
| 39 | >>> f = BEPostalCodeField(required=False) |
| 40 | >>> f.clean('1451') |
| 41 | u'1451' |
| 42 | >>> f.clean('2540') |
| 43 | u'2540' |
| 44 | >>> f.clean('0287') |
| 45 | Traceback (most recent call last): |
| 46 | ... |
| 47 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 48 | >>> f.clean('14309') |
| 49 | Traceback (most recent call last): |
| 50 | ... |
| 51 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 52 | >>> f.clean('873') |
| 53 | Traceback (most recent call last): |
| 54 | ... |
| 55 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 56 | >>> f.clean('35 74') |
| 57 | Traceback (most recent call last): |
| 58 | ... |
| 59 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 60 | >>> f.clean('859A') |
| 61 | Traceback (most recent call last): |
| 62 | ... |
| 63 | ValidationError: [u'Enter a valid postal code in the range and format 1XXX - 9XXX.'] |
| 64 | >>> f.clean('') |
| 65 | u'' |
| 66 | |
| 67 | # BEPhoneNumberField ############################################################## |
| 68 | |
| 69 | BEPhoneNumberField validates that data follows: Landlines have a seven-digit subscriber number and a one-digit area code, while smaller cities have a six-digit subscriber number and a two-digit area code. Cell phones have a six-digit subscriber number and a two-digit area code preceeded by the number 4. |
| 70 | 0d ddd dd dd, 0d/ddd.dd.dd - dialling a bigger city |
| 71 | 0dd dd dd dd, 0dd/dd.dd.dd - dialling a smaller city |
| 72 | 04dd dd dd dd, 04dd/dd.dd.dd - dialling a mobile number |
| 73 | |
| 74 | >>> from django.contrib.localflavor.be.forms import BEPhoneNumberField |
| 75 | >>> f = BEPhoneNumberField() |
| 76 | >>> f.clean('01 234 56 78') |
| 77 | u'01 234 56 78' |
| 78 | >>> f.clean('01/234.56.78') |
| 79 | u'01/234.56.78' |
| 80 | >>> f.clean('012 34 56 78') |
| 81 | u'012 34 56 78' |
| 82 | >>> f.clean('012/34.56.78') |
| 83 | u'012/34.56.78' |
| 84 | >>> f.clean('0412 34 56 78') |
| 85 | u'0412 34 56 78' |
| 86 | >>> f.clean('0412/34.56.78') |
| 87 | u'0412/34.56.78' |
| 88 | >>> f.clean('012345678') |
| 89 | Traceback (most recent call last): |
| 90 | ... |
| 91 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 92 | >>> f.clean('1234567') |
| 93 | Traceback (most recent call last): |
| 94 | ... |
| 95 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 96 | >>> f.clean('12/345.67.89') |
| 97 | Traceback (most recent call last): |
| 98 | ... |
| 99 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 100 | >>> f.clean('012/345.678.90') |
| 101 | Traceback (most recent call last): |
| 102 | ... |
| 103 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 104 | >>> f.clean('012/34.56.789') |
| 105 | Traceback (most recent call last): |
| 106 | ... |
| 107 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 108 | >>> f.clean('0123/45.67.89') |
| 109 | Traceback (most recent call last): |
| 110 | ... |
| 111 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 112 | >>> f.clean('012/345 678 90') |
| 113 | Traceback (most recent call last): |
| 114 | ... |
| 115 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 116 | >>> f.clean('012/34 56 789') |
| 117 | Traceback (most recent call last): |
| 118 | ... |
| 119 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 120 | >>> f.clean('') |
| 121 | Traceback (most recent call last): |
| 122 | ... |
| 123 | ValidationError: [u'This field is required.'] |
| 124 | |
| 125 | >>> f = BEPhoneNumberField(required=False) |
| 126 | >>> f.clean('01 234 56 78') |
| 127 | u'01 234 56 78' |
| 128 | >>> f.clean('01/234.56.78') |
| 129 | u'01/234.56.78' |
| 130 | >>> f.clean('012 34 56 78') |
| 131 | u'012 34 56 78' |
| 132 | >>> f.clean('012/34.56.78') |
| 133 | u'012/34.56.78' |
| 134 | >>> f.clean('0412 34 56 78') |
| 135 | u'0412 34 56 78' |
| 136 | >>> f.clean('0412/34.56.78') |
| 137 | u'0412/34.56.78' |
| 138 | >>> f.clean('012345678') |
| 139 | Traceback (most recent call last): |
| 140 | ... |
| 141 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 142 | >>> f.clean('1234567') |
| 143 | Traceback (most recent call last): |
| 144 | ... |
| 145 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 146 | >>> f.clean('12/345.67.89') |
| 147 | Traceback (most recent call last): |
| 148 | ... |
| 149 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 150 | >>> f.clean('012/345.678.90') |
| 151 | Traceback (most recent call last): |
| 152 | ... |
| 153 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 154 | >>> f.clean('012/34.56.789') |
| 155 | Traceback (most recent call last): |
| 156 | ... |
| 157 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 158 | >>> f.clean('0123/45.67.89') |
| 159 | Traceback (most recent call last): |
| 160 | ... |
| 161 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 162 | >>> f.clean('012/345 678 90') |
| 163 | Traceback (most recent call last): |
| 164 | ... |
| 165 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 166 | >>> f.clean('012/34 56 789') |
| 167 | Traceback (most recent call last): |
| 168 | ... |
| 169 | ValidationError: [u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx.'] |
| 170 | >>> f.clean('') |
| 171 | u'' |
| 172 | |
| 173 | # BERegionSelect ############################################################## |
| 174 | |
| 175 | BERegionSelect is a Select widget that uses a list of belgium regions as its choices. |
| 176 | >>> from django.contrib.localflavor.be.forms import BERegionSelect |
| 177 | >>> w = BERegionSelect() |
| 178 | >>> w.render('regions', 'VLG') |
| 179 | u'<select name="regions">\n<option value="BRU">Brussels Capital Region</option>\n<option value="VLG" selected="selected">Flemish Region</option>\n<option value="WAL">Wallonia</option>\n</select>' |
| 180 | |
| 181 | # BEProvinceSelect ############################################################## |
| 182 | |
| 183 | BEProvinceSelect is a Select widget that uses a list of Belgium provinces as its choices. |
| 184 | >>> from django.contrib.localflavor.be.forms import BEProvinceSelect |
| 185 | >>> w = BEProvinceSelect() |
| 186 | >>> w.render('provinces', 'WLG') |
| 187 | u'<select name="provinces">\n<option value="VAN">Antwerp</option>\n<option value="BRU">Brussels</option>\n<option value="VOV">East Flanders</option>\n<option value="VBR">Flemish Brabant</option>\n<option value="WHT">Hainaut</option>\n<option value="WLG" selected="selected">Liege</option>\n<option value="VLI">Limburg</option>\n<option value="WLX">Luxembourg</option>\n<option value="WNA">Namur</option>\n<option value="WBR">Walloon Brabant</option>\n<option value="VWV">West Flanders</option>\n</select>' |
| 188 | |
| 189 | """ |
| 190 | |