mirror of
				https://github.com/django/django.git
				synced 2025-11-04 13:39:16 +00:00 
			
		
		
		
	Converted Australian localfavor doctests into unittests. We have always been at war with doctests. Thanks to Idan Gazit for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14931 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		
							parent
							
								
									152ae52a6d
								
							
						
					
					
						commit
						c9b79c59bb
					
				
					 3 changed files with 41 additions and 125 deletions
				
			
		| 
						 | 
					@ -1,127 +1,13 @@
 | 
				
			||||||
# -*- coding: utf-8 -*-
 | 
					from django.contrib.localflavor.au.forms import (AUPostCodeField,
 | 
				
			||||||
# Tests for the contrib/localflavor/ AU form fields.
 | 
					        AUPhoneNumberField, AUStateSelect)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tests = r"""
 | 
					from utils import LocalFlavorTestCase
 | 
				
			||||||
## AUPostCodeField ##########################################################
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
A field that accepts a four digit Australian post code.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
>>> from django.contrib.localflavor.au.forms import AUPostCodeField
 | 
					class AULocalFlavorTests(LocalFlavorTestCase):
 | 
				
			||||||
>>> f = AUPostCodeField()
 | 
					    def test_AUStateSelect(self):
 | 
				
			||||||
>>> f.clean('1234')
 | 
					        f = AUStateSelect()
 | 
				
			||||||
u'1234'
 | 
					        out = u'''<select name="state">
 | 
				
			||||||
>>> f.clean('2000')
 | 
					 | 
				
			||||||
u'2000'
 | 
					 | 
				
			||||||
>>> f.clean('abcd')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'Enter a 4 digit post code.']
 | 
					 | 
				
			||||||
>>> f.clean('20001')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'Enter a 4 digit post code.']
 | 
					 | 
				
			||||||
>>> f.clean(None)
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'This field is required.']
 | 
					 | 
				
			||||||
>>> f.clean('')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'This field is required.']
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
>>> f = AUPostCodeField(required=False)
 | 
					 | 
				
			||||||
>>> f.clean('1234')
 | 
					 | 
				
			||||||
u'1234'
 | 
					 | 
				
			||||||
>>> f.clean('2000')
 | 
					 | 
				
			||||||
u'2000'
 | 
					 | 
				
			||||||
>>> f.clean('abcd')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'Enter a 4 digit post code.']
 | 
					 | 
				
			||||||
>>> f.clean('20001')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'Enter a 4 digit post code.']
 | 
					 | 
				
			||||||
>>> f.clean(None)
 | 
					 | 
				
			||||||
u''
 | 
					 | 
				
			||||||
>>> f.clean('')
 | 
					 | 
				
			||||||
u''
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## AUPhoneNumberField ########################################################
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
A field that accepts a 10 digit Australian phone number.
 | 
					 | 
				
			||||||
Allows spaces and parentheses around area code.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
>>> from django.contrib.localflavor.au.forms import AUPhoneNumberField
 | 
					 | 
				
			||||||
>>> f = AUPhoneNumberField()
 | 
					 | 
				
			||||||
>>> f.clean('1234567890')
 | 
					 | 
				
			||||||
u'1234567890'
 | 
					 | 
				
			||||||
>>> f.clean('0213456789')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('02 13 45 67 89')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('(02) 1345 6789')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('(02) 1345-6789')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('(02)1345-6789')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('0408 123 456')
 | 
					 | 
				
			||||||
u'0408123456'
 | 
					 | 
				
			||||||
>>> f.clean('123')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'Phone numbers must contain 10 digits.']
 | 
					 | 
				
			||||||
>>> f.clean('1800DJANGO')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'Phone numbers must contain 10 digits.']
 | 
					 | 
				
			||||||
>>> f.clean(None)
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'This field is required.']
 | 
					 | 
				
			||||||
>>> f.clean('')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'This field is required.']
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
>>> f = AUPhoneNumberField(required=False)
 | 
					 | 
				
			||||||
>>> f.clean('1234567890')
 | 
					 | 
				
			||||||
u'1234567890'
 | 
					 | 
				
			||||||
>>> f.clean('0213456789')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('02 13 45 67 89')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('(02) 1345 6789')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('(02) 1345-6789')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('(02)1345-6789')
 | 
					 | 
				
			||||||
u'0213456789'
 | 
					 | 
				
			||||||
>>> f.clean('0408 123 456')
 | 
					 | 
				
			||||||
u'0408123456'
 | 
					 | 
				
			||||||
>>> f.clean('123')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'Phone numbers must contain 10 digits.']
 | 
					 | 
				
			||||||
>>> f.clean('1800DJANGO')
 | 
					 | 
				
			||||||
Traceback (most recent call last):
 | 
					 | 
				
			||||||
...
 | 
					 | 
				
			||||||
ValidationError: [u'Phone numbers must contain 10 digits.']
 | 
					 | 
				
			||||||
>>> f.clean(None)
 | 
					 | 
				
			||||||
u''
 | 
					 | 
				
			||||||
>>> f.clean('')
 | 
					 | 
				
			||||||
u''
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## AUStateSelect #############################################################
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
AUStateSelect is a Select widget that uses a list of Australian
 | 
					 | 
				
			||||||
states/territories as its choices.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
>>> from django.contrib.localflavor.au.forms import AUStateSelect
 | 
					 | 
				
			||||||
>>> f = AUStateSelect()
 | 
					 | 
				
			||||||
>>> print f.render('state', 'NSW')
 | 
					 | 
				
			||||||
<select name="state">
 | 
					 | 
				
			||||||
<option value="ACT">Australian Capital Territory</option>
 | 
					<option value="ACT">Australian Capital Territory</option>
 | 
				
			||||||
<option value="NSW" selected="selected">New South Wales</option>
 | 
					<option value="NSW" selected="selected">New South Wales</option>
 | 
				
			||||||
<option value="NT">Northern Territory</option>
 | 
					<option value="NT">Northern Territory</option>
 | 
				
			||||||
| 
						 | 
					@ -130,5 +16,35 @@ states/territories as its choices.
 | 
				
			||||||
<option value="TAS">Tasmania</option>
 | 
					<option value="TAS">Tasmania</option>
 | 
				
			||||||
<option value="VIC">Victoria</option>
 | 
					<option value="VIC">Victoria</option>
 | 
				
			||||||
<option value="WA">Western Australia</option>
 | 
					<option value="WA">Western Australia</option>
 | 
				
			||||||
</select>
 | 
					</select>'''
 | 
				
			||||||
"""
 | 
					        self.assertEqual(f.render('state', 'NSW'), out)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_AUPostCodeField(self):
 | 
				
			||||||
 | 
					        error_format = [u'Enter a 4 digit post code.']
 | 
				
			||||||
 | 
					        valid = {
 | 
				
			||||||
 | 
					            '1234': '1234',
 | 
				
			||||||
 | 
					            '2000': '2000',
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        invalid = {
 | 
				
			||||||
 | 
					            'abcd': error_format,
 | 
				
			||||||
 | 
					            '20001': error_format,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        self.assertFieldOutput(AUPostCodeField, valid, invalid)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_AUPhoneNumberField(self):
 | 
				
			||||||
 | 
					        error_format = [u'Phone numbers must contain 10 digits.']
 | 
				
			||||||
 | 
					        valid = {
 | 
				
			||||||
 | 
					            '1234567890': '1234567890',
 | 
				
			||||||
 | 
					            '0213456789': '0213456789',
 | 
				
			||||||
 | 
					            '02 13 45 67 89': '0213456789',
 | 
				
			||||||
 | 
					            '(02) 1345 6789': '0213456789',
 | 
				
			||||||
 | 
					            '(02) 1345-6789': '0213456789',
 | 
				
			||||||
 | 
					            '(02)1345-6789': '0213456789',
 | 
				
			||||||
 | 
					            '0408 123 456': '0408123456',
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        invalid = {
 | 
				
			||||||
 | 
					            '123': error_format,
 | 
				
			||||||
 | 
					            '1800DJANGO': error_format,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        self.assertFieldOutput(AUPhoneNumberField, valid, invalid)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,4 @@
 | 
				
			||||||
# -*- coding: utf-8 -*-
 | 
					# -*- coding: utf-8 -*-
 | 
				
			||||||
from localflavor.au import tests as localflavor_au_tests
 | 
					 | 
				
			||||||
from localflavor.br import tests as localflavor_br_tests
 | 
					from localflavor.br import tests as localflavor_br_tests
 | 
				
			||||||
from localflavor.ca import tests as localflavor_ca_tests
 | 
					from localflavor.ca import tests as localflavor_ca_tests
 | 
				
			||||||
from localflavor.ch import tests as localflavor_ch_tests
 | 
					from localflavor.ch import tests as localflavor_ch_tests
 | 
				
			||||||
| 
						 | 
					@ -29,13 +28,13 @@ from localflavor.za import tests as localflavor_za_tests
 | 
				
			||||||
from localflavor.ar import ARLocalFlavorTests
 | 
					from localflavor.ar import ARLocalFlavorTests
 | 
				
			||||||
from localflavor.at import ATLocalFlavorTests
 | 
					from localflavor.at import ATLocalFlavorTests
 | 
				
			||||||
from localflavor.de import DELocalFlavorTests
 | 
					from localflavor.de import DELocalFlavorTests
 | 
				
			||||||
 | 
					from localflavor.au import AULocalFlavorTests
 | 
				
			||||||
from localflavor.be import BELocalFlavorTests
 | 
					from localflavor.be import BELocalFlavorTests
 | 
				
			||||||
from localflavor.il import ILLocalFlavorTests
 | 
					from localflavor.il import ILLocalFlavorTests
 | 
				
			||||||
from localflavor.tr import TRLocalFlavorTests
 | 
					from localflavor.tr import TRLocalFlavorTests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__test__ = {
 | 
					__test__ = {
 | 
				
			||||||
    'localflavor_au_tests': localflavor_au_tests,
 | 
					 | 
				
			||||||
    'localflavor_br_tests': localflavor_br_tests,
 | 
					    'localflavor_br_tests': localflavor_br_tests,
 | 
				
			||||||
    'localflavor_ca_tests': localflavor_ca_tests,
 | 
					    'localflavor_ca_tests': localflavor_ca_tests,
 | 
				
			||||||
    'localflavor_ch_tests': localflavor_ch_tests,
 | 
					    'localflavor_ch_tests': localflavor_ch_tests,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,6 +15,7 @@ from regressiontests.forms.localflavortests import (
 | 
				
			||||||
    __test__,
 | 
					    __test__,
 | 
				
			||||||
    ARLocalFlavorTests,
 | 
					    ARLocalFlavorTests,
 | 
				
			||||||
    ATLocalFlavorTests,
 | 
					    ATLocalFlavorTests,
 | 
				
			||||||
 | 
					    AULocalFlavorTests,
 | 
				
			||||||
    BELocalFlavorTests,
 | 
					    BELocalFlavorTests,
 | 
				
			||||||
    DELocalFlavorTests,
 | 
					    DELocalFlavorTests,
 | 
				
			||||||
    ILLocalFlavorTests,
 | 
					    ILLocalFlavorTests,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue