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):