Ticket #14608: in.py

File in.py, 3.1 KB (added by Kenneth Gonsalves, 14 years ago)

in.py with tests for INPhoneNumberField

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