Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Converted French localflavor doctests into unittests. We have…

… always been at war with doctests. Thanks to Idan Gazit. Backport of [14939].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14964 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4aedbcb57e8578fd572bcbce4fd1b284c5198b7a 1 parent aaaaa83
Alex Gaynor alex authored
145 tests/regressiontests/forms/localflavor/fr.py
View
@@ -1,117 +1,40 @@
-# -*- coding: utf-8 -*-
-# Tests for the contrib/localflavor/ FR form fields.
+from django.contrib.localflavor.fr.forms import (FRZipCodeField,
+ FRPhoneNumberField, FRDepartmentSelect)
-tests = r"""
-# FRZipCodeField #############################################################
+from utils import LocalFlavorTestCase
-FRZipCodeField validates that the data is a valid FR zipcode.
->>> from django.contrib.localflavor.fr.forms import FRZipCodeField
->>> f = FRZipCodeField()
->>> f.clean('75001')
-u'75001'
->>> f.clean('93200')
-u'93200'
->>> f.clean('2A200')
-Traceback (most recent call last):
-...
-ValidationError: [u'Enter a zip code in the format XXXXX.']
->>> f.clean('980001')
-Traceback (most recent call last):
-...
-ValidationError: [u'Enter a zip code in the format XXXXX.']
->>> 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 = FRZipCodeField(required=False)
->>> f.clean('75001')
-u'75001'
->>> f.clean('93200')
-u'93200'
->>> f.clean('2A200')
-Traceback (most recent call last):
-...
-ValidationError: [u'Enter a zip code in the format XXXXX.']
->>> f.clean('980001')
-Traceback (most recent call last):
-...
-ValidationError: [u'Enter a zip code in the format XXXXX.']
->>> f.clean(None)
-u''
->>> f.clean('')
-u''
+class FRLocalFlavorTests(LocalFlavorTestCase):
+ def test_FRZipCodeField(self):
+ error_format = [u'Enter a zip code in the format XXXXX.']
+ valid = {
+ '75001': '75001',
+ '93200': '93200',
+ }
+ invalid = {
+ '2A200': error_format,
+ '980001': error_format,
+ }
+ self.assertFieldOutput(FRZipCodeField, valid, invalid)
+ def test_FRPhoneNumberField(self):
+ error_format = [u'Phone numbers must be in 0X XX XX XX XX format.']
+ valid = {
+ '01 55 44 58 64': '01 55 44 58 64',
+ '0155445864': '01 55 44 58 64',
+ '01 5544 5864': '01 55 44 58 64',
+ '01 55.44.58.64': '01 55 44 58 64',
+ '01.55.44.58.64': '01 55 44 58 64',
+ }
+ invalid = {
+ '01,55,44,58,64': error_format,
+ '555 015 544': error_format,
+ }
+ self.assertFieldOutput(FRPhoneNumberField, valid, invalid)
-# FRPhoneNumberField ##########################################################
-
-FRPhoneNumberField validates that the data is a valid french phone number.
-It's normalized to 0X XX XX XX XX format. Dots are valid too.
->>> from django.contrib.localflavor.fr.forms import FRPhoneNumberField
->>> f = FRPhoneNumberField()
->>> f.clean('01 55 44 58 64')
-u'01 55 44 58 64'
->>> f.clean('0155445864')
-u'01 55 44 58 64'
->>> f.clean('01 5544 5864')
-u'01 55 44 58 64'
->>> f.clean('01 55.44.58.64')
-u'01 55 44 58 64'
->>> f.clean('01.55.44.58.64')
-u'01 55 44 58 64'
->>> f.clean('01,55,44,58,64')
-Traceback (most recent call last):
-...
-ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.']
->>> f.clean('555 015 544')
-Traceback (most recent call last):
-...
-ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.']
->>> 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 = FRPhoneNumberField(required=False)
->>> f.clean('01 55 44 58 64')
-u'01 55 44 58 64'
->>> f.clean('0155445864')
-u'01 55 44 58 64'
->>> f.clean('01 5544 5864')
-u'01 55 44 58 64'
->>> f.clean('01 55.44.58.64')
-u'01 55 44 58 64'
->>> f.clean('01.55.44.58.64')
-u'01 55 44 58 64'
->>> f.clean('01,55,44,58,64')
-Traceback (most recent call last):
-...
-ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.']
->>> f.clean('555 015 544')
-Traceback (most recent call last):
-...
-ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.']
->>> f.clean(None)
-u''
->>> f.clean('')
-u''
-
-# FRDepartmentSelect ###############################################################
-
-FRDepartmentSelect is a Select widget that uses a list of french departments
-including DOM TOM
->>> from django.contrib.localflavor.fr.forms import FRDepartmentSelect
->>> w = FRDepartmentSelect()
->>> print w.render('dep', 'Paris')
-<select name="dep">
+ def test_FRDepartmentSelect(self):
+ f = FRDepartmentSelect()
+ out = u'''<select name="dep">
<option value="01">01 - Ain</option>
<option value="02">02 - Aisne</option>
<option value="03">03 - Allier</option>
@@ -218,5 +141,5 @@
<option value="986">986 - Wallis et Futuna</option>
<option value="987">987 - Polynesie Francaise</option>
<option value="988">988 - Nouvelle-Caledonie</option>
-</select>
-"""
+</select>'''
+ self.assertEqual(f.render('dep', 'Paris'), out)
3  tests/regressiontests/forms/localflavortests.py
View
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from localflavor.cz import tests as localflavor_cz_tests
-from localflavor.fr import tests as localflavor_fr_tests
from localflavor.generic import tests as localflavor_generic_tests
from localflavor.id import tests as localflavor_id_tests
from localflavor.ie import tests as localflavor_ie_tests
@@ -30,11 +29,11 @@
from localflavor.de import DELocalFlavorTests
from localflavor.es import ESLocalFlavorTests
from localflavor.fi import FILocalFlavorTests
+from localflavor.fr import FRLocalFlavorTests
__test__ = {
'localflavor_cz_tests': localflavor_cz_tests,
- 'localflavor_fr_tests': localflavor_fr_tests,
'localflavor_generic_tests': localflavor_generic_tests,
'localflavor_id_tests': localflavor_id_tests,
'localflavor_ie_tests': localflavor_ie_tests,
1  tests/regressiontests/forms/tests/__init__.py
View
@@ -23,4 +23,5 @@
DELocalFlavorTests,
ESLocalFlavorTests,
FILocalFlavorTests,
+ FRLocalFlavorTests,
)
Please sign in to comment.
Something went wrong with that request. Please try again.