1 | # -*- coding: utf-8 -*-
|
---|
2 | # Tests for the contrib/localflavor/ IN form fields.
|
---|
3 | tests = r"""
|
---|
4 | # INPhoneNumberField ##########################################################
|
---|
5 |
|
---|
6 | INPhoneNumberField validates that the data is a valid Indian phone number,
|
---|
7 | including the STD code. It's normalised to 0XXX-XXXXXXX or 0XXX XXXXXXX format. The first
|
---|
8 | string is the STD code which is a '0' followed by 2-4 digits. The second string
|
---|
9 | is 8 digits if the STD code is 3 digits, 7 digits if the STD code is 4 digits and
|
---|
10 | 6 digits if the STD code is 5 digits. The second string will start with numbers
|
---|
11 | between 1 and 6. The separator is either a space or a hyphen.
|
---|
12 | >>> from django.contrib.localflavor.in_.forms import INPhoneNumberField
|
---|
13 | >>> f = INPhoneNumberField()
|
---|
14 | >>> f.clean('04-2443667')
|
---|
15 | Traceback (most recent call last):
|
---|
16 | ...
|
---|
17 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
18 | >>> f.clean('423-2443667')
|
---|
19 | Traceback (most recent call last):
|
---|
20 | ...
|
---|
21 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
22 | >>> f.clean('0423-9442667')
|
---|
23 | Traceback (most recent call last):
|
---|
24 | ...
|
---|
25 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
26 | >>> f.clean('0423-0443667')
|
---|
27 | Traceback (most recent call last):
|
---|
28 | ...
|
---|
29 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
30 | >>> f.clean('0423-244366')
|
---|
31 | Traceback (most recent call last):
|
---|
32 | ...
|
---|
33 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
34 | >>> f.clean('04232442667')
|
---|
35 | Traceback (most recent call last):
|
---|
36 | ...
|
---|
37 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
38 | >>> f.clean('0423-2443667')
|
---|
39 | u'0423-2443667'
|
---|
40 | >>> f.clean('0423 2443667')
|
---|
41 | u'0423 2443667'
|
---|
42 | >>> f.clean('04236-2443667')
|
---|
43 | u'04236-2443667'
|
---|
44 | >>> f.clean('040-2443667')
|
---|
45 | u'040-2443667'
|
---|
46 | >>> f.clean(None)
|
---|
47 | Traceback (most recent call last):
|
---|
48 | ...
|
---|
49 | ValidationError: [u'This field is required.']
|
---|
50 | >>> f.clean('')
|
---|
51 | Traceback (most recent call last):
|
---|
52 | ...
|
---|
53 | ValidationError: [u'This field is required.']
|
---|
54 |
|
---|
55 | >>> f = INPhoneNumberField(required=False)
|
---|
56 | >>> f.clean('04-2443667')
|
---|
57 | Traceback (most recent call last):
|
---|
58 | ...
|
---|
59 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
60 | >>> f.clean('423-2443667')
|
---|
61 | Traceback (most recent call last):
|
---|
62 | ...
|
---|
63 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
64 | >>> f.clean('0423-9442667')
|
---|
65 | Traceback (most recent call last):
|
---|
66 | ...
|
---|
67 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
68 | >>> f.clean('0423-0443667')
|
---|
69 | Traceback (most recent call last):
|
---|
70 | ...
|
---|
71 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
72 | >>> f.clean('0423-244366')
|
---|
73 | Traceback (most recent call last):
|
---|
74 | ...
|
---|
75 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
76 | >>> f.clean('04232442667')
|
---|
77 | Traceback (most recent call last):
|
---|
78 | ...
|
---|
79 | ValidationError: [u'Phone numbers must be in 02X-7X or 03X-6X or 04X-5X format.']
|
---|
80 | >>> f.clean('0423-2443667')
|
---|
81 | u'0423-2443667'
|
---|
82 | >>> f.clean('0423 2443667')
|
---|
83 | u'0423 2443667'
|
---|
84 | >>> f.clean('04236-244366')
|
---|
85 | u'04236-2443667'
|
---|
86 | >>> f.clean('040-24436678')
|
---|
87 | u'040-24436678'
|
---|
88 | >>> f.clean(None)
|
---|
89 | u''
|
---|
90 | >>> f.clean('')
|
---|
91 | u''
|
---|
92 | """
|
---|