Ticket #4960: after.patch

File after.patch, 1.3 KB (added by Daniel Ward, 9 years ago)

Follow-up tests

  • tests/forms_tests/tests/test_fields.py

    diff --git tests/forms_tests/tests/test_fields.py tests/forms_tests/tests/test_fields.py
    index aa26579..5cac883 100644
    class FieldsTests(SimpleTestCase):  
    164164        self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'})
    165165        self.assertEqual(f.widget_attrs(Textarea()), {'maxlength': '10'})
    166166
     167    def test_value_stripping(self):
     168
     169        """
     170        Ensure that 'strip' argument works as intended (#4960).
     171        """
     172
     173        # Test behaviour of strip method
     174
     175        f = CharField()  # strip=False
     176        self.assertEqual(f.clean(' Foo bar '), ' Foo bar ')
     177        self.assertEqual(f.clean(' Foo \nBar '), ' Foo \nBar ')
     178        self.assertEqual(f.clean('Baz'), 'Baz')
     179        self.assertEqual(f.clean(' '), ' ')
     180
     181        f = CharField(strip=True)
     182        self.assertEqual(f.clean(' Foo bar '), 'Foo bar')
     183        self.assertEqual(f.clean(' Foo \nBar '), 'Foo \nBar')
     184        with self.assertRaises(forms.ValidationError) as err:
     185            f.clean(' ')  # Whitespace, yet empty following strip
     186        self.assertEqual(err.exception.messages[0], 'This field is required.')
     187
    167188    # IntegerField ################################################################
    168189
    169190    def test_integerfield_1(self):
Back to Top