diff --git tests/forms_tests/tests/test_fields.py tests/forms_tests/tests/test_fields.py
index aa26579..5cac883 100644
|
|
class FieldsTests(SimpleTestCase):
|
164 | 164 | self.assertEqual(f.widget_attrs(PasswordInput()), {'maxlength': '10'}) |
165 | 165 | self.assertEqual(f.widget_attrs(Textarea()), {'maxlength': '10'}) |
166 | 166 | |
| 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 | |
167 | 188 | # IntegerField ################################################################ |
168 | 189 | |
169 | 190 | def test_integerfield_1(self): |