summaryrefslogtreecommitdiff
path: root/tests/model_fields/test_integerfield.py
diff options
context:
space:
mode:
authorDiederik van der Boor <vdboor@edoburu.nl>2017-07-13 13:55:23 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-08-05 08:41:29 +0200
commit25f21bd2376603c8e233a0a0e5a726a0fdfdd33e (patch)
tree4c75092f7ee29fff214a3f7c40ac00dd424afc04 /tests/model_fields/test_integerfield.py
parent1af469e67fd3928a4b01722d4706c066000014e9 (diff)
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>
Diffstat (limited to 'tests/model_fields/test_integerfield.py')
-rw-r--r--tests/model_fields/test_integerfield.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/model_fields/test_integerfield.py b/tests/model_fields/test_integerfield.py
index 626b67b00b..c72cb48015 100644
--- a/tests/model_fields/test_integerfield.py
+++ b/tests/model_fields/test_integerfield.py
@@ -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