~ubuntu-branches/debian/squeeze/python-django/squeeze

« back to all changes in this revision

Viewing changes to tests/regressiontests/forms/localflavor/au.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb, Chris Lamb, David Spreen, Sandro Tosi
  • Date: 2008-11-19 21:31:00 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081119213100-gp0lqhxl1qxa6dgl
Tags: 1.0.2-1
[ Chris Lamb ]
* New upstream bugfix release. Closes: #505783
* Add myself to Uploaders with ACK from Brett.

[ David Spreen ]
* Remove python-pysqlite2 from Recommends because Python 2.5 includes
  sqlite library used by Django. Closes: 497886

[ Sandro Tosi ]
* debian/control
  - switch Vcs-Browser field to viewsvn

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
# Tests for the contrib/localflavor/ AU form fields.
3
 
 
4
 
tests = r"""
5
 
## AUPostCodeField ##########################################################
6
 
 
7
 
A field that accepts a four digit Australian post code.
8
 
 
9
 
>>> from django.contrib.localflavor.au.forms import AUPostCodeField
10
 
>>> f = AUPostCodeField()
11
 
>>> f.clean('1234')
12
 
u'1234'
13
 
>>> f.clean('2000')
14
 
u'2000'
15
 
>>> f.clean('abcd')
16
 
Traceback (most recent call last):
17
 
...
18
 
ValidationError: [u'Enter a 4 digit post code.']
19
 
>>> f.clean('20001')
20
 
Traceback (most recent call last):
21
 
...
22
 
ValidationError: [u'Enter a 4 digit post code.']
23
 
>>> f.clean(None)
24
 
Traceback (most recent call last):
25
 
...
26
 
ValidationError: [u'This field is required.']
27
 
>>> f.clean('')
28
 
Traceback (most recent call last):
29
 
...
30
 
ValidationError: [u'This field is required.']
31
 
 
32
 
>>> f = AUPostCodeField(required=False)
33
 
>>> f.clean('1234')
34
 
u'1234'
35
 
>>> f.clean('2000')
36
 
u'2000'
37
 
>>> f.clean('abcd')
38
 
Traceback (most recent call last):
39
 
...
40
 
ValidationError: [u'Enter a 4 digit post code.']
41
 
>>> f.clean('20001')
42
 
Traceback (most recent call last):
43
 
...
44
 
ValidationError: [u'Enter a 4 digit post code.']
45
 
>>> f.clean(None)
46
 
u''
47
 
>>> f.clean('')
48
 
u''
49
 
 
50
 
## AUPhoneNumberField ########################################################
51
 
 
52
 
A field that accepts a 10 digit Australian phone number.
53
 
llows spaces and parentheses around area code.
54
 
 
55
 
>>> from django.contrib.localflavor.au.forms import AUPhoneNumberField
56
 
>>> f = AUPhoneNumberField()
57
 
>>> f.clean('1234567890')
58
 
u'1234567890'
59
 
>>> f.clean('0213456789')
60
 
u'0213456789'
61
 
>>> f.clean('02 13 45 67 89')
62
 
u'0213456789'
63
 
>>> f.clean('(02) 1345 6789')
64
 
u'0213456789'
65
 
>>> f.clean('(02) 1345-6789')
66
 
u'0213456789'
67
 
>>> f.clean('(02)1345-6789')
68
 
u'0213456789'
69
 
>>> f.clean('0408 123 456')
70
 
u'0408123456'
71
 
>>> f.clean('123')
72
 
Traceback (most recent call last):
73
 
...
74
 
ValidationError: [u'Phone numbers must contain 10 digits.']
75
 
>>> f.clean('1800DJANGO')
76
 
Traceback (most recent call last):
77
 
...
78
 
ValidationError: [u'Phone numbers must contain 10 digits.']
79
 
>>> f.clean(None)
80
 
Traceback (most recent call last):
81
 
...
82
 
ValidationError: [u'This field is required.']
83
 
>>> f.clean('')
84
 
Traceback (most recent call last):
85
 
...
86
 
ValidationError: [u'This field is required.']
87
 
 
88
 
>>> f = AUPhoneNumberField(required=False)
89
 
>>> f.clean('1234567890')
90
 
u'1234567890'
91
 
>>> f.clean('0213456789')
92
 
u'0213456789'
93
 
>>> f.clean('02 13 45 67 89')
94
 
u'0213456789'
95
 
>>> f.clean('(02) 1345 6789')
96
 
u'0213456789'
97
 
>>> f.clean('(02) 1345-6789')
98
 
u'0213456789'
99
 
>>> f.clean('(02)1345-6789')
100
 
u'0213456789'
101
 
>>> f.clean('0408 123 456')
102
 
u'0408123456'
103
 
>>> f.clean('123')
104
 
Traceback (most recent call last):
105
 
...
106
 
ValidationError: [u'Phone numbers must contain 10 digits.']
107
 
>>> f.clean('1800DJANGO')
108
 
Traceback (most recent call last):
109
 
...
110
 
ValidationError: [u'Phone numbers must contain 10 digits.']
111
 
>>> f.clean(None)
112
 
u''
113
 
>>> f.clean('')
114
 
u''
115
 
 
116
 
## AUStateSelect #############################################################
117
 
 
118
 
AUStateSelect is a Select widget that uses a list of Australian
119
 
states/territories as its choices.
120
 
 
121
 
>>> from django.contrib.localflavor.au.forms import AUStateSelect
122
 
>>> f = AUStateSelect()
123
 
>>> print f.render('state', 'NSW')
124
 
<select name="state">
125
 
<option value="ACT">Australian Capital Territory</option>
126
 
<option value="NSW" selected="selected">New South Wales</option>
127
 
<option value="NT">Northern Territory</option>
128
 
<option value="QLD">Queensland</option>
129
 
<option value="SA">South Australia</option>
130
 
<option value="TAS">Tasmania</option>
131
 
<option value="VIC">Victoria</option>
132
 
<option value="WA">Western Australia</option>
133
 
</select>
134
 
"""