summaryrefslogtreecommitdiff
path: root/tests/model_fields/test_autofield.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_autofield.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_autofield.py')
-rw-r--r--tests/model_fields/test_autofield.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/model_fields/test_autofield.py b/tests/model_fields/test_autofield.py
new file mode 100644
index 0000000000..73220ae62b
--- /dev/null
+++ b/tests/model_fields/test_autofield.py
@@ -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