| 1 | # -*- coding: utf-8 -*- |
| 2 | # Test for the contrib/localflavor/ NI form fields |
| 3 | |
| 4 | tests = """ |
| 5 | #NIPhoneNumberField ######################## |
| 6 | |
| 7 | A form field that validates Nicaraguan Phone Number validation. |
| 8 | >>> from django.contrib.localflavor.ni.forms import NIPhoneNumberField |
| 9 | >>> phone = NIPhoneNumberField() |
| 10 | >>> phone.clean('98567489') |
| 11 | u'98567489' |
| 12 | >>> phone.clean('9856-7489') |
| 13 | u'98567489' |
| 14 | >>> phone.clean('98-56-74-89') |
| 15 | u'98567489' |
| 16 | >>> phone.clean('2344 5678') |
| 17 | u'23445678' |
| 18 | >>> phone.clean('2344 567 8') |
| 19 | u'23445678' |
| 20 | >>> phone.clean('9856-489') |
| 21 | Traceback (most recent call last): |
| 22 | File "<console>", line 1, in <module> |
| 23 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 37, in clean |
| 24 | raise ValidationError(self.default_error_messages['invalid']) |
| 25 | ValidationError: [u'Phone numbers must be in the format XXX-XXXX or XXXXXXX.'] |
| 26 | >>> phone.clean('9856K489') |
| 27 | Traceback (most recent call last): |
| 28 | File "<console>", line 1, in <module> |
| 29 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 33, in clean |
| 30 | v = super(NIPhoneNumberField, self).clean(value) |
| 31 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 32 | raise ValidationError(self.error_messages['invalid']) |
| 33 | ValidationError: [u'Phone numbers must be in the format XXX-XXXX or XXXXXXX.'] |
| 34 | >>> phone.clean('9856*489') |
| 35 | Traceback (most recent call last): |
| 36 | File "<console>", line 1, in <module> |
| 37 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 33, in clean |
| 38 | v = super(NIPhoneNumberField, self).clean(value) |
| 39 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 40 | raise ValidationError(self.error_messages['invalid']) |
| 41 | ValidationError: [u'Phone numbers must be in the format XXX-XXXX or XXXXXXX.'] |
| 42 | >>> phone.clean('') |
| 43 | u'' |
| 44 | >>> phone.clean(None) |
| 45 | u'' |
| 46 | |
| 47 | |
| 48 | #NICedulaNumberField ########## |
| 49 | |
| 50 | Personal identication number in Nicaragua. In format 999-999999-9999A where 9 is a number an A a letter |
| 51 | |
| 52 | >>> from django.contrib.localflavor.ni.forms import NICedulaNumberField |
| 53 | >>> c = NICedulaNumberField() |
| 54 | >>> c.clean('001-090934-0002A') |
| 55 | u'001-090934-0002A' |
| 56 | >>> c.clean('001-090934-00023') |
| 57 | Traceback (most recent call last): |
| 58 | File "<stdin>", line 1, in <module> |
| 59 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 58, in clean |
| 60 | value = super(NICedulaNumberField, self).clean(value) |
| 61 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 62 | raise ValidationError(self.error_messages['invalid']) |
| 63 | django.forms.util.ValidationError>>> c.clean('001-0909A4-0002A') |
| 64 | Traceback (most recent call last): |
| 65 | File "<stdin>", line 1, in <module> |
| 66 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 58, in clean |
| 67 | value = super(NICedulaNumberField, self).clean(value) |
| 68 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 69 | raise ValidationError(self.error_messages['invalid']) |
| 70 | django.forms.util.ValidationError>>> c.clean('001090994-0002A') |
| 71 | Traceback (most recent call last): |
| 72 | File "<stdin>", line 1, in <module> |
| 73 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 58, in clean |
| 74 | value = super(NICedulaNumberField, self).clean(value) |
| 75 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 76 | raise ValidationError(self.error_messages['invalid']) |
| 77 | django.forms.util.ValidationError |
| 78 | >>> c.clean('0a1-090934-0002A') |
| 79 | Traceback (most recent call last): |
| 80 | File "<stdin>", line 1, in <module> |
| 81 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 58, in clean |
| 82 | value = super(NICedulaNumberField, self).clean(value) |
| 83 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 84 | raise ValidationError(self.error_messages['invalid']) |
| 85 | django.forms.util.ValidationError |
| 86 | >>> c.clean('001-090994-0002a') |
| 87 | u'001-090994-0002a' |
| 88 | |
| 89 | # NIDepartamentSelect ############# |
| 90 | |
| 91 | A choice field with the 15 departaments and 2 autonomic regions in Nicaragua. |
| 92 | >>> from django.contrib.localflavor.ni.forms import NIDepartamentSelect |
| 93 | >>> d = NIDepartamentSelect() |
| 94 | >>> print d.render('departaments', 'managua') |
| 95 | <select name="departaments"> |
| 96 | <option value="50">Boaco</option> |
| 97 | <option value="75">Carazo</option> |
| 98 | <option value="30">Chinandega</option> |
| 99 | <option value="65">Chontales</option> |
| 100 | <option value="25">Estelí</option> |
| 101 | <option value="70">Granada</option> |
| 102 | <option value="10">Jinotega</option> |
| 103 | <option value="35">León</option> |
| 104 | <option value="20">Madriz</option> |
| 105 | <option value="55">Managua</option> |
| 106 | <option value="60">Masaya</option> |
| 107 | <option value="40">Matagalpa</option> |
| 108 | <option value="5">Nueva Segovia</option> |
| 109 | <option value="80">Rivas</option> |
| 110 | <option value="85">Río San Juan</option> |
| 111 | <option value="91">Región Autónoma del Atlántico Norte(RAAN)</option> |
| 112 | <option value="93">Región Autónoma del Atlántico Sur(RAAS)</option> |
| 113 | </select> |
| 114 | No newline at end of file |