mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +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:
committed by
Mariusz Felisiak
parent
1af469e67f
commit
25f21bd237
32
tests/model_fields/test_autofield.py
Normal file
32
tests/model_fields/test_autofield.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import AutoModel, BigAutoModel, SmallAutoModel
|
||||
|
||||
|
||||
class AutoFieldTests(TestCase):
|
||||
model = AutoModel
|
||||
|
||||
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=value):
|
||||
msg = "Field 'value' expected a number but got %r." % (value,)
|
||||
with self.assertRaisesMessage(exception, msg):
|
||||
self.model.objects.create(value=value)
|
||||
|
||||
|
||||
class BigAutoFieldTests(AutoFieldTests):
|
||||
model = BigAutoModel
|
||||
|
||||
|
||||
class SmallAutoFieldTests(AutoFieldTests):
|
||||
model = SmallAutoModel
|
||||
Reference in New Issue
Block a user