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/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 482f7ad..cd368bb 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.test.utils import get_warnings_state, restore_warnings_state |
… |
… |
class LocalFlavorTestCase(TestCase):
|
37 | 39 | self.assertEqual(optional.clean(input), output) |
38 | 40 | # test invalid inputs |
39 | 41 | for input, errors in invalid.items(): |
40 | | self.assertRaisesRegexp(ValidationError, unicode(errors), |
41 | | required.clean, input |
42 | | ) |
43 | | self.assertRaisesRegexp(ValidationError, unicode(errors), |
44 | | optional.clean, input |
45 | | ) |
| 42 | with self.assertRaises(ValidationError) as context_manager: |
| 43 | required.clean(input) |
| 44 | self.assertEqual(context_manager.exception.messages, errors) |
| 45 | |
| 46 | with self.assertRaises(ValidationError) as context_manager: |
| 47 | optional.clean(input) |
| 48 | self.assertEqual(context_manager.exception.messages, errors) |
46 | 49 | # test required inputs |
47 | | error_required = u'This field is required' |
| 50 | error_required = [u'This field is required.'] |
48 | 51 | for e in EMPTY_VALUES: |
49 | | self.assertRaisesRegexp(ValidationError, error_required, |
50 | | required.clean, e) |
| 52 | with self.assertRaises(ValidationError) as context_manager: |
| 53 | required.clean(e) |
| 54 | self.assertEqual(context_manager.exception.messages, error_required) |
51 | 55 | self.assertEqual(optional.clean(e), empty_value) |
diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py
index 5ee1c32..5a736b3 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 2d96b2f..d04f111 100644
a
|
b
|
from regressiontests.forms.localflavortests import (
|
22 | 22 | NLLocalFlavorTests, PLLocalFlavorTests, PTLocalFlavorTests, |
23 | 23 | ROLocalFlavorTests, SELocalFlavorTests, SKLocalFlavorTests, |
24 | 24 | TRLocalFlavorTests, UKLocalFlavorTests, USLocalFlavorTests, |
25 | | UYLocalFlavorTests, ZALocalFlavorTests |
| 25 | UYLocalFlavorTests, ZALocalFlavorTests, AssertFieldOutputTests, |
26 | 26 | ) |