Ticket #17751: 17751-test.diff

File 17751-test.diff, 1.6 KB (added by Claude Paroz, 13 years ago)

Test showing issue

  • tests/modeltests/validators/tests.py

    diff --git a/tests/modeltests/validators/tests.py b/tests/modeltests/validators/tests.py
    index a1a48bf..a3a0675 100644
    a b TEST_DATA = (  
    5454    (validate_ipv4_address, '25.1.1.', ValidationError),
    5555    (validate_ipv4_address, '25,1,1,1', ValidationError),
    5656    (validate_ipv4_address, '25.1 .1.1', ValidationError),
     57    (validate_ipv4_address, ' 1.1.1.1', ValidationError),
    5758
    5859    # validate_ipv6_address uses django.utils.ipv6, which
    5960    # is tested in much greater detail in it's own testcase
    TEST_DATA = (  
    6465    (validate_ipv6_address, '1:2', ValidationError),
    6566    (validate_ipv6_address, '::zzz', ValidationError),
    6667    (validate_ipv6_address, '12345::', ValidationError),
     68    (validate_ipv6_address, ' fe80::1', ValidationError),
    6769
    6870    (validate_ipv46_address, '1.1.1.1', None),
    6971    (validate_ipv46_address, '255.0.0.0', None),
    def create_simple_test_method(validator, expected, value, num):  
    159161    if expected is not None and issubclass(expected, Exception):
    160162        test_mask = 'test_%s_raises_error_%d'
    161163        def test_func(self):
    162             self.assertRaises(expected, validator, value)
     164            # Do not use assertRaises, so as to be able to produce a more
     165            # precise error message
     166            try:
     167                validator(value)
     168                raise AssertionError("%s not raised for value '%s'" % (
     169                    expected.__name__, value))
     170            except expected:
     171                pass
    163172    else:
    164173        test_mask = 'test_%s_%d'
    165174        def test_func(self):
Back to Top