Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Converted Belerusian localflavor tests to use the new, less verbose f…

…ormat. Thanks to Idan Gazit for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14932 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b035759199cce68164402e2dc1bc2b72de6aca2d 1 parent c9b79c5
Alex Gaynor authored
159  tests/regressiontests/forms/localflavor/be.py
... ...
@@ -1,94 +1,79 @@
1  
-from django.test import TestCase
2  
-from django.forms import *
3  
-
4 1
 from django.contrib.localflavor.be.forms import (BEPostalCodeField,
5 2
     BEPhoneNumberField, BERegionSelect, BEProvinceSelect)
6 3
 
7  
-class BELocalFlavorTests(TestCase):
8  
-    """
9  
-    Test case to validate BE localflavor
10  
-    """
11  
-    def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):
12  
-        self.assertRaises(error, callable, *args, **kwargs)
13  
-        try:
14  
-            callable(*args, **kwargs)
15  
-        except error, e:
16  
-            self.assertEqual(message, str(e))
  4
+from utils import LocalFlavorTestCase
  5
+
17 6
 
18  
-    def test_postal_code_field(self):
19  
-        f = BEPostalCodeField()
20  
-        self.assertEqual(u'1451', f.clean('1451'))
21  
-        self.assertEqual(u'2540', f.clean('2540'))
22  
-        err_message = "[u'Enter a valid postal code in the range and format 1XXX - 9XXX.']"
23  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0287')
24  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '14309')
25  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '873')
26  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '35 74')
27  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '859A')
28  
-        err_message = "[u'This field is required.']"
29  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '')
30  
-        f = BEPostalCodeField(required=False)
31  
-        self.assertEqual(u'1451', f.clean('1451'))
32  
-        self.assertEqual(u'2540', f.clean('2540'))
33  
-        self.assertEqual(u'', f.clean(''))
34  
-        err_message = "[u'Enter a valid postal code in the range and format 1XXX - 9XXX.']"
35  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0287')
36  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '14309')
37  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '873')
38  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '35 74')
39  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '859A')
  7
+class BELocalFlavorTests(LocalFlavorTestCase):
  8
+    def test_BEPostalCodeField(self):
  9
+        error_format = [u'Enter a valid postal code in the range and format 1XXX - 9XXX.']
  10
+        valid = {
  11
+            u'1451': '1451',
  12
+            u'2540': '2540',
  13
+        }
  14
+        invalid = {
  15
+            '0287': error_format,
  16
+            '14309': error_format,
  17
+            '873': error_format,
  18
+            '35 74': error_format,
  19
+            '859A': error_format,
  20
+        }
  21
+        self.assertFieldOutput(BEPostalCodeField, valid, invalid)
40 22
 
41  
-    def test_phone_number_field(self):
42  
-        f = BEPhoneNumberField()
43  
-        self.assertEqual(u'01 234 56 78', f.clean('01 234 56 78'))
44  
-        self.assertEqual(u'01/234.56.78', f.clean('01/234.56.78'))
45  
-        self.assertEqual(u'01.234.56.78', f.clean('01.234.56.78'))
46  
-        self.assertEqual(u'012 34 56 78', f.clean('012 34 56 78'))
47  
-        self.assertEqual(u'012/34.56.78', f.clean('012/34.56.78'))
48  
-        self.assertEqual(u'012.34.56.78', f.clean('012.34.56.78'))
49  
-        self.assertEqual(u'0412 34 56 78', f.clean('0412 34 56 78'))
50  
-        self.assertEqual(u'0412/34.56.78', f.clean('0412/34.56.78'))
51  
-        self.assertEqual(u'0412.34.56.78', f.clean('0412.34.56.78'))
52  
-        self.assertEqual(u'012345678', f.clean('012345678'))
53  
-        self.assertEqual(u'0412345678', f.clean('0412345678'))
54  
-        err_message = "[u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx, 0xxxxxxxx or 04xxxxxxxx.']"
55  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '01234567')
56  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '12/345.67.89')
57  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345.678.90')
58  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34.56.789')
59  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0123/45.67.89')
60  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345 678 90')
61  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34 56 789')
62  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012.34 56 789')
63  
-        err_message = "[u'This field is required.']"
64  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '')
65  
-        f = BEPhoneNumberField(required=False)
66  
-        self.assertEqual(u'01 234 56 78', f.clean('01 234 56 78'))
67  
-        self.assertEqual(u'01/234.56.78', f.clean('01/234.56.78'))
68  
-        self.assertEqual(u'01.234.56.78', f.clean('01.234.56.78'))
69  
-        self.assertEqual(u'012 34 56 78', f.clean('012 34 56 78'))
70  
-        self.assertEqual(u'012/34.56.78', f.clean('012/34.56.78'))
71  
-        self.assertEqual(u'012.34.56.78', f.clean('012.34.56.78'))
72  
-        self.assertEqual(u'0412 34 56 78', f.clean('0412 34 56 78'))
73  
-        self.assertEqual(u'0412/34.56.78', f.clean('0412/34.56.78'))
74  
-        self.assertEqual(u'0412.34.56.78', f.clean('0412.34.56.78'))
75  
-        self.assertEqual(u'012345678', f.clean('012345678'))
76  
-        self.assertEqual(u'0412345678', f.clean('0412345678'))
77  
-        self.assertEqual(u'', f.clean(''))
78  
-        err_message = "[u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx, 0xxxxxxxx or 04xxxxxxxx.']"
79  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '01234567')
80  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '12/345.67.89')
81  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345.678.90')
82  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34.56.789')
83  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0123/45.67.89')
84  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345 678 90')
85  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34 56 789')
86  
-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012.34 56 789')
  23
+    def test_BEPhoneNumberField(self):
  24
+        error_format = [
  25
+            ('Enter a valid phone number in one of the formats 0x xxx xx xx, '
  26
+                '0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, '
  27
+                '04xx/xx.xx.xx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx, '
  28
+                '0xxxxxxxx or 04xxxxxxxx.')
  29
+        ]
  30
+        valid = {
  31
+            u'01 234 56 78': '01 234 56 78',
  32
+            u'01/234.56.78': '01/234.56.78',
  33
+            u'01.234.56.78': '01.234.56.78',
  34
+            u'012 34 56 78': '012 34 56 78',
  35
+            u'012/34.56.78': '012/34.56.78',
  36
+            u'012.34.56.78': '012.34.56.78',
  37
+            u'0412 34 56 78': '0412 34 56 78',
  38
+            u'0412/34.56.78': '0412/34.56.78',
  39
+            u'0412.34.56.78': '0412.34.56.78',
  40
+            u'012345678': '012345678',
  41
+            u'0412345678': '0412345678',
  42
+        }
  43
+        invalid = {
  44
+            '01234567': error_format,
  45
+            '12/345.67.89': error_format,
  46
+            '012/345.678.90': error_format,
  47
+            '012/34.56.789': error_format,
  48
+            '0123/45.67.89': error_format,
  49
+            '012/345 678 90': error_format,
  50
+            '012/34 56 789': error_format,
  51
+            '012.34 56 789': error_format,
  52
+        }
  53
+        self.assertFieldOutput(BEPhoneNumberField, valid, invalid)
87 54
 
88  
-    def test_region_field(self):
89  
-        w = BERegionSelect()
90  
-        self.assertEqual(u'<select name="regions">\n<option value="BRU">Brussels Capital Region</option>\n<option value="VLG" selected="selected">Flemish Region</option>\n<option value="WAL">Wallonia</option>\n</select>', w.render('regions', 'VLG'))
  55
+    def test_BERegionSelect(self):
  56
+        f = BERegionSelect()
  57
+        out = u'''<select name="regions">
  58
+<option value="BRU">Brussels Capital Region</option>
  59
+<option value="VLG" selected="selected">Flemish Region</option>
  60
+<option value="WAL">Wallonia</option>
  61
+</select>'''
  62
+        self.assertEqual(f.render('regions', 'VLG'), out)
91 63
 
92  
-    def test_province_field(self):
93  
-        w = BEProvinceSelect()
94  
-        self.assertEqual(u'<select name="provinces">\n<option value="VAN">Antwerp</option>\n<option value="BRU">Brussels</option>\n<option value="VOV">East Flanders</option>\n<option value="VBR">Flemish Brabant</option>\n<option value="WHT">Hainaut</option>\n<option value="WLG" selected="selected">Liege</option>\n<option value="VLI">Limburg</option>\n<option value="WLX">Luxembourg</option>\n<option value="WNA">Namur</option>\n<option value="WBR">Walloon Brabant</option>\n<option value="VWV">West Flanders</option>\n</select>', w.render('provinces', 'WLG'))
  64
+    def test_BEProvinceSelect(self):
  65
+        f = BEProvinceSelect()
  66
+        out = u'''<select name="provinces">
  67
+<option value="VAN">Antwerp</option>
  68
+<option value="BRU">Brussels</option>
  69
+<option value="VOV">East Flanders</option>
  70
+<option value="VBR">Flemish Brabant</option>
  71
+<option value="WHT">Hainaut</option>
  72
+<option value="WLG" selected="selected">Liege</option>
  73
+<option value="VLI">Limburg</option>
  74
+<option value="WLX">Luxembourg</option>
  75
+<option value="WNA">Namur</option>
  76
+<option value="WBR">Walloon Brabant</option>
  77
+<option value="VWV">West Flanders</option>
  78
+</select>'''
  79
+        self.assertEqual(f.render('provinces', 'WLG'), out)

0 notes on commit b035759

Please sign in to comment.
Something went wrong with that request. Please try again.