summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid-Wobrock <david.wobrock@gmail.com>2020-11-02 08:20:15 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-11-02 20:11:58 +0100
commit4ebd633350ac07091a23c0f0c3eac3aa691cab05 (patch)
treecaf32af81880cff8b87f9daf99daa92857aabbbf
parentd1791539a7d86739cd44c909fa8239cae7f85874 (diff)
Refs #32132 -- Added rel_db_type() tests for auto and integer fields.
-rw-r--r--tests/model_fields/test_autofield.py3
-rw-r--r--tests/model_fields/test_integerfield.py13
2 files changed, 16 insertions, 0 deletions
diff --git a/tests/model_fields/test_autofield.py b/tests/model_fields/test_autofield.py
index db8e79e34b..646cd2ab0a 100644
--- a/tests/model_fields/test_autofield.py
+++ b/tests/model_fields/test_autofield.py
@@ -9,14 +9,17 @@ from .test_integerfield import (
class AutoFieldTests(IntegerFieldTests):
model = AutoModel
+ rel_db_type_class = models.IntegerField
class BigAutoFieldTests(BigIntegerFieldTests):
model = BigAutoModel
+ rel_db_type_class = models.BigIntegerField
class SmallAutoFieldTests(SmallIntegerFieldTests):
model = SmallAutoModel
+ rel_db_type_class = models.SmallIntegerField
class AutoFieldInheritanceTests(SimpleTestCase):
diff --git a/tests/model_fields/test_integerfield.py b/tests/model_fields/test_integerfield.py
index b5517e4c56..bc370f18e2 100644
--- a/tests/model_fields/test_integerfield.py
+++ b/tests/model_fields/test_integerfield.py
@@ -14,6 +14,7 @@ from .models import (
class IntegerFieldTests(TestCase):
model = IntegerModel
documented_range = (-2147483648, 2147483647)
+ rel_db_type_class = models.IntegerField
@property
def backend_range(self):
@@ -154,15 +155,22 @@ class IntegerFieldTests(TestCase):
with self.assertRaisesMessage(exception, msg):
self.model.objects.create(value=value)
+ def test_rel_db_type(self):
+ field = self.model._meta.get_field('value')
+ rel_db_type = field.rel_db_type(connection)
+ self.assertEqual(rel_db_type, self.rel_db_type_class().db_type(connection))
+
class SmallIntegerFieldTests(IntegerFieldTests):
model = SmallIntegerModel
documented_range = (-32768, 32767)
+ rel_db_type_class = models.SmallIntegerField
class BigIntegerFieldTests(IntegerFieldTests):
model = BigIntegerModel
documented_range = (-9223372036854775808, 9223372036854775807)
+ rel_db_type_class = models.BigIntegerField
class PositiveSmallIntegerFieldTests(IntegerFieldTests):
@@ -173,6 +181,11 @@ class PositiveSmallIntegerFieldTests(IntegerFieldTests):
class PositiveIntegerFieldTests(IntegerFieldTests):
model = PositiveIntegerModel
documented_range = (0, 2147483647)
+ rel_db_type_class = (
+ models.PositiveIntegerField
+ if connection.features.related_fields_match_type
+ else models.IntegerField
+ )
@unittest.skipIf(connection.vendor == 'sqlite', "SQLite doesn't have a constraint.")
def test_negative_values(self):