Ticket #15805: 15805.assertFieldOutput.5.diff

File 15805.assertFieldOutput.5.diff, 8.6 KB (added by Julien Phalip, 13 years ago)

Patch updated to latest trunk

  • tests/regressiontests/forms/localflavor/__init__.py

    diff --git a/tests/regressiontests/forms/localflavor/__init__.py b/tests/regressiontests/forms/localflavor/__init__.py
    index e69de29..8a4bf04 100644
    a b  
     1from django.forms import EmailField
     2from utils import LocalFlavorTestCase
     3
     4class 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.']})
  • tests/regressiontests/forms/localflavor/au.py

    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):  
    2020        self.assertEqual(f.render('state', 'NSW'), out)
    2121
    2222    def test_AUPostCodeField(self):
    23         error_format = [u'Enter a 4 digit post code.']
     23        error_format = [u'Enter a 4 digit postcode.']
    2424        valid = {
    2525            '1234': '1234',
    2626            '2000': '2000',
    2727        }
    2828        invalid = {
    2929            'abcd': error_format,
    30             '20001': error_format,
     30            '20001': [u'Ensure this value has at most 4 characters (it has 5).'] + error_format,
    3131        }
    3232        self.assertFieldOutput(AUPostCodeField, valid, invalid)
    3333
  • tests/regressiontests/forms/localflavor/hr.py

    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):  
    158158            '12345678901': '12345678901',
    159159        }
    160160        invalid = {
    161             '1234567890': error_invalid,
     161            '1234567890': [u'Ensure this value has at least 11 characters (it has 10).'] + error_invalid,
    162162            'ABCDEFGHIJK': error_invalid,
    163163        }
    164164        self.assertFieldOutput(HROIBField, valid, invalid)
  • tests/regressiontests/forms/localflavor/pt.py

    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):  
    1717        self.assertFieldOutput(PTZipCodeField, valid, invalid)
    1818
    1919    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.']
    2121        valid = {
    2222            '917845189': '917845189',
    2323            '91 784 5189': '917845189',
  • tests/regressiontests/forms/localflavor/ro.py

    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):  
    6666        invalid = {
    6767            '21694680': error_invalid,
    6868            '21694680000': error_atmost,
    69             '0': error_atleast,
     69            '0': error_atleast + error_invalid,
    7070        }
    7171        self.assertFieldOutput(ROCIFField, valid, invalid)
    7272
    class ROLocalFlavorTests(LocalFlavorTestCase):  
    8181            '1981211204487': error_invalid,
    8282            '1981232204489': error_invalid,
    8383            '9981211204489': error_invalid,
    84             '9981211209': error_atleast,
     84            '9981211209': error_atleast + error_invalid,
    8585            '19812112044891': error_atmost,
    8686        }
    8787        self.assertFieldOutput(ROCNPField, valid, invalid)
    class ROLocalFlavorTests(LocalFlavorTestCase):  
    109109        invalid = {
    110110            'RO56RZBR0000060003291176': error_invalid,
    111111            'AT61 1904 3002 3457 3201': error_invalid,
    112             'RO56RZBR000006000329117': error_atleast,
     112            'RO56RZBR000006000329117': error_atleast + error_invalid,
    113113        }
    114114        self.assertFieldOutput(ROIBANField, valid, invalid)
    115115
    116116    def test_ROPhoneNumberField(self):
    117117        error_format = [u'Phone numbers must be in XXXX-XXXXXX format.']
    118118        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.']
    119120        valid = {
    120121            '0264485936': '0264485936',
    121122            '(0264)-485936': '0264485936',
    122123        }
    123124        invalid = {
    124125            '02644859368': error_format,
    125             '026448593': error_atleast,
     126            '026448593': error_atleast + error_invalid,
    126127        }
    127128        self.assertFieldOutput(ROPhoneNumberField, valid, invalid)
    128129
    129130    def test_ROPostalCodeField(self):
    130131        error_atleast = [u'Ensure this value has at least 6 characters (it has 5).']
    131132        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       
    133135        valid = {
    134136            '400473': '400473',
    135137        }
    136138        invalid = {
    137             '40047': error_atleast,
    138             '4004731': error_atmost,
     139            '40047': error_atleast + error_invalid,
     140            '4004731': error_atmost + error_invalid,
    139141        }
    140142        self.assertFieldOutput(ROPostalCodeField, valid, invalid)
  • tests/regressiontests/forms/localflavor/utils.py

    diff --git a/tests/regressiontests/forms/localflavor/utils.py b/tests/regressiontests/forms/localflavor/utils.py
    index 31d53dd..000f4cb 100644
    a b  
     1from __future__ import with_statement
     2
    13from django.core.exceptions import ValidationError
    24from django.core.validators import EMPTY_VALUES
    35from django.forms.fields import CharField
    class LocalFlavorTestCase(TestCase):  
    4244            self.assertEqual(optional.clean(input), output)
    4345        # test invalid inputs
    4446        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)
    5154        # test required inputs
    52         error_required = u'This field is required'
     55        error_required = [u'This field is required.']
    5356        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)
    5660            self.assertEqual(optional.clean(e), empty_value)
    5761        # test that max_length and min_length are always accepted
    5862        if issubclass(fieldclass, CharField):
  • tests/regressiontests/forms/localflavortests.py

    diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py
    index fb501ab..e2d5aa6 100644
    a b  
     1from localflavor import AssertFieldOutputTests
    12from localflavor.ar import ARLocalFlavorTests
    23from localflavor.at import ATLocalFlavorTests
    34from localflavor.au import AULocalFlavorTests
  • tests/regressiontests/forms/tests/__init__.py

    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 (  
    4646    TRLocalFlavorTests,
    4747    USLocalFlavorTests,
    4848    UYLocalFlavorTests,
    49     ZALocalFlavorTests
     49    ZALocalFlavorTests,
     50    AssertFieldOutputTests,
    5051)
Back to Top