diff --git a/tests/regressiontests/forms/localflavor/__init__.py b/tests/regressiontests/forms/localflavor/__init__.py
index e69de29..8a4bf04 100644
a
|
b
|
|
| 1 | from django.forms import EmailField |
| 2 | from utils import LocalFlavorTestCase |
| 3 | |
| 4 | class AssertFieldOutputTests(LocalFlavorTestCase): |
| 5 | |
| 6 | def test_assert_field_output(self): |
| 7 | error_invalid = [u'Enter a valid e-mail address.'] |
| 8 | self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid}) |
| 9 | self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid + [u'Another error']}) |
| 10 | self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'Wrong output'}, {'aaa': error_invalid}) |
| 11 | self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'a@a.com'}, {'aaa': [u'Come one, gimme some well formatted data, dude.']}) |
diff --git a/tests/regressiontests/forms/localflavor/au.py b/tests/regressiontests/forms/localflavor/au.py
index 4bd8a76..ddf2b8e 100644
a
|
b
|
class AULocalFlavorTests(LocalFlavorTestCase):
|
20 | 20 | self.assertEqual(f.render('state', 'NSW'), out) |
21 | 21 | |
22 | 22 | def test_AUPostCodeField(self): |
23 | | error_format = [u'Enter a 4 digit post code.'] |
| 23 | error_format = [u'Enter a 4 digit postcode.'] |
24 | 24 | valid = { |
25 | 25 | '1234': '1234', |
26 | 26 | '2000': '2000', |
27 | 27 | } |
28 | 28 | invalid = { |
29 | 29 | 'abcd': error_format, |
30 | | '20001': error_format, |
| 30 | '20001': [u'Ensure this value has at most 4 characters (it has 5).'] + error_format, |
31 | 31 | } |
32 | 32 | self.assertFieldOutput(AUPostCodeField, valid, invalid) |
33 | 33 | |
diff --git a/tests/regressiontests/forms/localflavor/hr.py b/tests/regressiontests/forms/localflavor/hr.py
index 5a7a6b1..27d747c 100644
a
|
b
|
class HRLocalFlavorTests(LocalFlavorTestCase):
|
158 | 158 | '12345678901': '12345678901', |
159 | 159 | } |
160 | 160 | invalid = { |
161 | | '1234567890': error_invalid, |
| 161 | '1234567890': [u'Ensure this value has at least 11 characters (it has 10).'] + error_invalid, |
162 | 162 | 'ABCDEFGHIJK': error_invalid, |
163 | 163 | } |
164 | 164 | self.assertFieldOutput(HROIBField, valid, invalid) |
diff --git a/tests/regressiontests/forms/localflavor/pt.py b/tests/regressiontests/forms/localflavor/pt.py
index ce52018..b8d784a 100644
a
|
b
|
class PTLocalFlavorTests(LocalFlavorTestCase):
|
17 | 17 | self.assertFieldOutput(PTZipCodeField, valid, invalid) |
18 | 18 | |
19 | 19 | def test_PTPhoneNumberField(self): |
20 | | error_format = [u'Phone numbers must have 9 digits, or start by + or 00'] |
| 20 | error_format = [u'Phone numbers must have 9 digits, or start by + or 00.'] |
21 | 21 | valid = { |
22 | 22 | '917845189': '917845189', |
23 | 23 | '91 784 5189': '917845189', |
diff --git a/tests/regressiontests/forms/localflavor/ro.py b/tests/regressiontests/forms/localflavor/ro.py
index 5b546cd..7545843 100644
a
|
b
|
class ROLocalFlavorTests(LocalFlavorTestCase):
|
66 | 66 | invalid = { |
67 | 67 | '21694680': error_invalid, |
68 | 68 | '21694680000': error_atmost, |
69 | | '0': error_atleast, |
| 69 | '0': error_atleast + error_invalid, |
70 | 70 | } |
71 | 71 | self.assertFieldOutput(ROCIFField, valid, invalid) |
72 | 72 | |
… |
… |
class ROLocalFlavorTests(LocalFlavorTestCase):
|
81 | 81 | '1981211204487': error_invalid, |
82 | 82 | '1981232204489': error_invalid, |
83 | 83 | '9981211204489': error_invalid, |
84 | | '9981211209': error_atleast, |
| 84 | '9981211209': error_atleast + error_invalid, |
85 | 85 | '19812112044891': error_atmost, |
86 | 86 | } |
87 | 87 | self.assertFieldOutput(ROCNPField, valid, invalid) |
… |
… |
class ROLocalFlavorTests(LocalFlavorTestCase):
|
109 | 109 | invalid = { |
110 | 110 | 'RO56RZBR0000060003291176': error_invalid, |
111 | 111 | 'AT61 1904 3002 3457 3201': error_invalid, |
112 | | 'RO56RZBR000006000329117': error_atleast, |
| 112 | 'RO56RZBR000006000329117': error_atleast + error_invalid, |
113 | 113 | } |
114 | 114 | self.assertFieldOutput(ROIBANField, valid, invalid) |
115 | 115 | |
116 | 116 | def test_ROPhoneNumberField(self): |
117 | 117 | error_format = [u'Phone numbers must be in XXXX-XXXXXX format.'] |
118 | 118 | error_atleast = [u'Ensure this value has at least 10 characters (it has 9).'] |
| 119 | error_invalid = [u'Phone numbers must be in XXXX-XXXXXX format.'] |
119 | 120 | valid = { |
120 | 121 | '0264485936': '0264485936', |
121 | 122 | '(0264)-485936': '0264485936', |
122 | 123 | } |
123 | 124 | invalid = { |
124 | 125 | '02644859368': error_format, |
125 | | '026448593': error_atleast, |
| 126 | '026448593': error_atleast + error_invalid, |
126 | 127 | } |
127 | 128 | self.assertFieldOutput(ROPhoneNumberField, valid, invalid) |
128 | 129 | |
129 | 130 | def test_ROPostalCodeField(self): |
130 | 131 | error_atleast = [u'Ensure this value has at least 6 characters (it has 5).'] |
131 | 132 | error_atmost = [u'Ensure this value has at most 6 characters (it has 7).'] |
132 | | |
| 133 | error_invalid = [u'Enter a valid postal code in the format XXXXXX'] |
| 134 | |
133 | 135 | valid = { |
134 | 136 | '400473': '400473', |
135 | 137 | } |
136 | 138 | invalid = { |
137 | | '40047': error_atleast, |
138 | | '4004731': error_atmost, |
| 139 | '40047': error_atleast + error_invalid, |
| 140 | '4004731': error_atmost + error_invalid, |
139 | 141 | } |
140 | 142 | self.assertFieldOutput(ROPostalCodeField, valid, invalid) |
diff --git a/tests/regressiontests/forms/localflavor/utils.py b/tests/regressiontests/forms/localflavor/utils.py
index 31d53dd..000f4cb 100644
a
|
b
|
|
| 1 | from __future__ import with_statement |
| 2 | |
1 | 3 | from django.core.exceptions import ValidationError |
2 | 4 | from django.core.validators import EMPTY_VALUES |
3 | 5 | from django.forms.fields import CharField |
… |
… |
class LocalFlavorTestCase(TestCase):
|
42 | 44 | self.assertEqual(optional.clean(input), output) |
43 | 45 | # test invalid inputs |
44 | 46 | for input, errors in invalid.items(): |
45 | | self.assertRaisesRegexp(ValidationError, unicode(errors), |
46 | | required.clean, input |
47 | | ) |
48 | | self.assertRaisesRegexp(ValidationError, unicode(errors), |
49 | | optional.clean, input |
50 | | ) |
| 47 | with self.assertRaises(ValidationError) as context_manager: |
| 48 | required.clean(input) |
| 49 | self.assertEqual(context_manager.exception.messages, errors) |
| 50 | |
| 51 | with self.assertRaises(ValidationError) as context_manager: |
| 52 | optional.clean(input) |
| 53 | self.assertEqual(context_manager.exception.messages, errors) |
51 | 54 | # test required inputs |
52 | | error_required = u'This field is required' |
| 55 | error_required = [u'This field is required.'] |
53 | 56 | for e in EMPTY_VALUES: |
54 | | self.assertRaisesRegexp(ValidationError, error_required, |
55 | | required.clean, e) |
| 57 | with self.assertRaises(ValidationError) as context_manager: |
| 58 | required.clean(e) |
| 59 | self.assertEqual(context_manager.exception.messages, error_required) |
56 | 60 | self.assertEqual(optional.clean(e), empty_value) |
57 | 61 | # test that max_length and min_length are always accepted |
58 | 62 | if issubclass(fieldclass, CharField): |
diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py
index fb501ab..e2d5aa6 100644
a
|
b
|
|
| 1 | from localflavor import AssertFieldOutputTests |
1 | 2 | from localflavor.ar import ARLocalFlavorTests |
2 | 3 | from localflavor.at import ATLocalFlavorTests |
3 | 4 | from localflavor.au import AULocalFlavorTests |
diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py
index 6366a93..39db39f 100644
a
|
b
|
from regressiontests.forms.localflavortests import (
|
46 | 46 | TRLocalFlavorTests, |
47 | 47 | USLocalFlavorTests, |
48 | 48 | UYLocalFlavorTests, |
49 | | ZALocalFlavorTests |
| 49 | ZALocalFlavorTests, |
| 50 | AssertFieldOutputTests, |
50 | 51 | ) |