| 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('233-3023') |
| 11 | u'2333023' |
| 12 | >>> phone.clean('2333023') |
| 13 | u'2333023' |
| 14 | >>> phone.clean('2333-023') |
| 15 | Traceback (most recent call last): |
| 16 | File "<stdin>", line 1, in <module> |
| 17 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 30, in clean |
| 18 | v = super(NIPhoneNumberField, self).clean(value) |
| 19 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 20 | raise ValidationError(self.error_messages['invalid']) |
| 21 | django.forms.util.ValidationError: [u'Phone numbers must be in the format XXX-XXXX or XXXXXXX.'] |
| 22 | >>> phone.clean('a33-3023') |
| 23 | Traceback (most recent call last): |
| 24 | File "<stdin>", line 1, in <module> |
| 25 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 30, in clean |
| 26 | v = super(NIPhoneNumberField, self).clean(value) |
| 27 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 28 | raise ValidationError(self.error_messages['invalid']) |
| 29 | django.forms.util.ValidationError: [u'Phone numbers must be in the format XXX-XXXX or XXXXXXX.'] |
| 30 | >>> phone.clean('23334023') |
| 31 | Traceback (most recent call last): |
| 32 | File "<stdin>", line 1, in <module> |
| 33 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 30, in clean |
| 34 | v = super(NIPhoneNumberField, self).clean(value) |
| 35 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 36 | raise ValidationError(self.error_messages['invalid']) |
| 37 | django.forms.util.ValidationError: [u'Phone numbers must be in the format XXX-XXXX or XXXXXXX.'] |
| 38 | >>> phone.clean('') |
| 39 | Traceback (most recent call last): |
| 40 | File "<stdin>", line 1, in <module> |
| 41 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 30, in clean |
| 42 | v = super(NIPhoneNumberField, self).clean(value) |
| 43 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 414, in clean |
| 44 | value = super(RegexField, self).clean(value) |
| 45 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 148, in clean |
| 46 | super(CharField, self).clean(value) |
| 47 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 119, in clean |
| 48 | raise ValidationError(self.error_messages['required']) |
| 49 | django.forms.util.ValidationError>>> |
| 50 | >>> phone = NIPhoneNumberField(required = False) |
| 51 | >>> phone.clean('') |
| 52 | u'' |
| 53 | >>> phone.clean(None) |
| 54 | u'' |
| 55 | |
| 56 | |
| 57 | #NICedulaNumberField ########## |
| 58 | |
| 59 | Personal identication number in Nicaragua. In format 999-999999-9999A where 9 is a number an A a letter |
| 60 | |
| 61 | >>> from django.contrib.localflavor.ni.forms import NICedulaNumberField |
| 62 | >>> c = NICedulaNumberField() |
| 63 | >>> c.clean('001-090934-0002A') |
| 64 | u'001-090934-0002A' |
| 65 | >>> c.clean('001-090934-00023') |
| 66 | Traceback (most recent call last): |
| 67 | File "<stdin>", line 1, in <module> |
| 68 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 58, in clean |
| 69 | value = super(NICedulaNumberField, self).clean(value) |
| 70 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 71 | raise ValidationError(self.error_messages['invalid']) |
| 72 | django.forms.util.ValidationError>>> c.clean('001-0909A4-0002A') |
| 73 | Traceback (most recent call last): |
| 74 | File "<stdin>", line 1, in <module> |
| 75 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 58, in clean |
| 76 | value = super(NICedulaNumberField, self).clean(value) |
| 77 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 78 | raise ValidationError(self.error_messages['invalid']) |
| 79 | django.forms.util.ValidationError>>> c.clean('001090994-0002A') |
| 80 | Traceback (most recent call last): |
| 81 | File "<stdin>", line 1, in <module> |
| 82 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 58, in clean |
| 83 | value = super(NICedulaNumberField, self).clean(value) |
| 84 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 85 | raise ValidationError(self.error_messages['invalid']) |
| 86 | django.forms.util.ValidationError |
| 87 | >>> c.clean('0a1-090934-0002A') |
| 88 | Traceback (most recent call last): |
| 89 | File "<stdin>", line 1, in <module> |
| 90 | File "/usr/lib/python2.5/site-packages/django/contrib/localflavor/ni/forms.py", line 58, in clean |
| 91 | value = super(NICedulaNumberField, self).clean(value) |
| 92 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 418, in clean |
| 93 | raise ValidationError(self.error_messages['invalid']) |
| 94 | django.forms.util.ValidationError |
| 95 | >>> c.clean('001-090994-0002a') |
| 96 | u'001-090994-0002a' |
| 97 | |
| 98 | # NIDepartamentSelect ############# |
| 99 | |
| 100 | A choice field with the 15 departaments and 2 autonomic regions in Nicaragua. |
| 101 | |
| 102 | >>> |
| 103 | >>> d = NIDepartamentSelect() |
| 104 | >>> d._get_choices() |
| 105 | [('BO', <django.utils.functional.__proxy__ object at 0x7f4537003750>), ('CZ', <django.utils.functional.__proxy__ object at 0x7f4537003990>), ('CH', <django.utils.functional.__proxy__ object at 0x7f4537003410>), ('CT', <django.utils.functional.__proxy__ object at 0x7f4537003450>), ('ES', <django.utils.functional.__proxy__ object at 0x7f4537003490>), ('GR', <django.utils.functional.__proxy__ object at 0x7f45370035d0>), ('JI', <django.utils.functional.__proxy__ object at 0x7f4537003710>), ('LE', <django.utils.functional.__proxy__ object at 0x7f4537003890>), ('MZ', <django.utils.functional.__proxy__ object at 0x7f4537003910>), ('M', <django.utils.functional.__proxy__ object at 0x7f45365bfd50>), ('MY', <django.utils.functional.__proxy__ object at 0x7f45365bfdd0>), ('MT', <django.utils.functional.__proxy__ object at 0x7f45365bfe50>), ('NS', <django.utils.functional.__proxy__ object at 0x7f45365bfed0>), ('RI', <django.utils.functional.__proxy__ object at 0x7f45365bff10>), ('RS', <django.utils.functional.__proxy__ object at 0x7f45365bff90>), ('RAAN', <django.utils.functional.__proxy__ object at 0x7f453613e050>), ('RAAS', <django.utils.functional.__proxy__ object at 0x7f453613e0d0>)] |
| 106 | >>> d.clean('M') |
| 107 | u'M' |
| 108 | >>> d.clean('FOO') |
| 109 | Traceback (most recent call last): |
| 110 | File "<stdin>", line 1, in <module> |
| 111 | File "/usr/lib/python2.5/site-packages/django/forms/fields.py", line 649, in clean |
| 112 | raise ValidationError(self.error_messages['invalid_choice'] % {'value': value}) |
| 113 | django.forms.util.ValidationError: [u'Escoja una opci\xf3n v\xe1lida. FOO no es una de las opciones disponibles.'] |
| 114 | >>> d.valid_value('M') |
| 115 | True |
| 116 | >>> d.valid_value('FOO') |
| 117 | False |
| 118 | """ |
| 119 | |