summaryrefslogtreecommitdiff
path: root/tests/field_subclassing
diff options
context:
space:
mode:
authorMarc Tamlyn <marc.tamlyn@gmail.com>2014-03-14 22:18:20 +0000
committerMarc Tamlyn <marc.tamlyn@gmail.com>2014-03-14 22:32:17 +0000
commitd22b291890c1736a40c0ad97448c7318df2eebb2 (patch)
tree23faf94f32ee295dce7b73d16b81f842c5159ef1 /tests/field_subclassing
parent37f7f233f5f30c28ea60a7fbc272ffd296e2dbe1 (diff)
downloaddjango-d22b291890c1736a40c0ad97448c7318df2eebb2.tar.gz
Fixed #22001 -- Ensure db_type is respected.
db_parameters should respect an already existing db_type method and return that as its type string. In particular, this was causing some fields from gis to not be generated. Thanks to @bigsassy and @blueyed for their work on the patch. Also fixed #22260
Diffstat (limited to 'tests/field_subclassing')
-rw-r--r--tests/field_subclassing/fields.py5
-rw-r--r--tests/field_subclassing/tests.py10
2 files changed, 14 insertions, 1 deletions
diff --git a/tests/field_subclassing/fields.py b/tests/field_subclassing/fields.py
index 43ece22e82..d96ce8d873 100644
--- a/tests/field_subclassing/fields.py
+++ b/tests/field_subclassing/fields.py
@@ -74,3 +74,8 @@ class JSONField(six.with_metaclass(models.SubfieldBase, models.TextField)):
if value is None:
return None
return json.dumps(value)
+
+
+class CustomTypedField(models.TextField):
+ def db_type(self, connection):
+ return 'custom_field'
diff --git a/tests/field_subclassing/tests.py b/tests/field_subclassing/tests.py
index 6a3d1cad20..5f1dbac8a3 100644
--- a/tests/field_subclassing/tests.py
+++ b/tests/field_subclassing/tests.py
@@ -3,9 +3,10 @@ from __future__ import unicode_literals
import inspect
from django.core import serializers
+from django.db import connection
from django.test import TestCase
-from .fields import Small
+from .fields import Small, CustomTypedField
from .models import DataModel, MyModel, OtherModel
@@ -104,3 +105,10 @@ class CustomField(TestCase):
data = dict(inspect.getmembers(MyModel))
self.assertIn('__module__', data)
self.assertEqual(data['__module__'], 'field_subclassing.models')
+
+
+class TestDbType(TestCase):
+
+ def test_db_parameters_respects_db_type(self):
+ f = CustomTypedField()
+ self.assertEqual(f.db_parameters(connection)['type'], 'custom_field')