mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
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:
parent
1af469e67f
commit
25f21bd237
6 changed files with 97 additions and 4 deletions
|
@ -137,6 +137,23 @@ class IntegerFieldTests(TestCase):
|
|||
instance = self.model.objects.get(value='10')
|
||||
self.assertEqual(instance.value, 10)
|
||||
|
||||
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 'value' expected a number but got %r." % (value,)
|
||||
with self.assertRaisesMessage(exception, msg):
|
||||
self.model.objects.create(value=value)
|
||||
|
||||
|
||||
class SmallIntegerFieldTests(IntegerFieldTests):
|
||||
model = SmallIntegerModel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue