Fixed #28393 -- Added helpful error messages for invalid AutoField/FloatField/IntegerField values.

Co-authored-by: Diederik van der Boor <vdboor@edoburu.nl>
Co-authored-by: Nick Pope <nick.pope@flightdataservices.com>
This commit is contained in:
Diederik van der Boor 2017-07-13 13:55:23 +02:00 committed by Mariusz Felisiak
parent 1af469e67f
commit 25f21bd237
6 changed files with 97 additions and 4 deletions

View file

@ -31,3 +31,20 @@ class TestFloatField(TestCase):
obj.size = obj
with self.assertRaisesMessage(TypeError, msg):
obj.save()
def test_invalid_value(self):
tests = [
(TypeError, ()),
(TypeError, []),
(TypeError, {}),
(TypeError, set()),
(TypeError, object()),
(TypeError, complex()),
(ValueError, 'non-numeric string'),
(ValueError, b'non-numeric byte-string'),
]
for exception, value in tests:
with self.subTest(value):
msg = "Field 'size' expected a number but got %r." % (value,)
with self.assertRaisesMessage(exception, msg):
FloatModel.objects.create(size=value)