summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2017-05-23 17:02:40 +0200
committerGitHub <noreply@github.com>2017-05-23 17:02:40 +0200
commit538bf43458a147b7edeb7118c9f325c3f59ff6fb (patch)
treea1724f358e8d8829c0c68b1e8bba6882d108fc53 /tests
parentb3eb6eaf1a197ff155faf333871da032c77ba855 (diff)
Fixed #27859 -- Ignored db_index for TextField/BinaryField on Oracle and MySQL.
Thanks Zubair Alam for the initial patch and Tim Graham for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/invalid_models_tests/test_ordinary_fields.py25
-rw-r--r--tests/schema/models.py7
-rw-r--r--tests/schema/tests.py17
3 files changed, 43 insertions, 6 deletions
diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py
index 90f4b31902..cad375aae5 100644
--- a/tests/invalid_models_tests/test_ordinary_fields.py
+++ b/tests/invalid_models_tests/test_ordinary_fields.py
@@ -2,7 +2,7 @@ import unittest
from django.core.checks import Error, Warning as DjangoWarning
from django.db import connection, models
-from django.test import SimpleTestCase, TestCase
+from django.test import SimpleTestCase, TestCase, skipIfDBFeature
from django.test.utils import isolate_apps, override_settings
from django.utils.timezone import now
@@ -646,3 +646,26 @@ class TimeFieldTests(TestCase):
@override_settings(USE_TZ=True)
def test_fix_default_value_tz(self):
self.test_fix_default_value()
+
+
+@isolate_apps('invalid_models_tests')
+class TextFieldTests(TestCase):
+
+ @skipIfDBFeature('supports_index_on_text_field')
+ def test_max_length_warning(self):
+ class Model(models.Model):
+ value = models.TextField(db_index=True)
+ field = Model._meta.get_field('value')
+ field_type = field.db_type(connection)
+ self.assertEqual(field.check(), [
+ DjangoWarning(
+ '%s does not support a database index on %s columns.'
+ % (connection.display_name, field_type),
+ hint=(
+ "An index won't be created. Silence this warning if you "
+ "don't care about it."
+ ),
+ obj=field,
+ id='fields.W162',
+ )
+ ])
diff --git a/tests/schema/models.py b/tests/schema/models.py
index 0c73760d96..0e04dbab87 100644
--- a/tests/schema/models.py
+++ b/tests/schema/models.py
@@ -17,6 +17,13 @@ class Author(models.Model):
apps = new_apps
+class AuthorTextFieldWithIndex(models.Model):
+ text_field = models.TextField(db_index=True)
+
+ class Meta:
+ apps = new_apps
+
+
class AuthorWithDefaultHeight(models.Model):
name = models.CharField(max_length=255)
height = models.PositiveIntegerField(null=True, blank=True, default=42)
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 17a4d7c715..ef4b192a36 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -29,11 +29,11 @@ from .fields import (
CustomManyToManyField, InheritedManyToManyField, MediumBlobField,
)
from .models import (
- Author, AuthorWithDefaultHeight, AuthorWithEvenLongerName,
- AuthorWithIndexedName, Book, BookForeignObj, BookWeak, BookWithLongName,
- BookWithO2O, BookWithoutAuthor, BookWithSlug, IntegerPK, Node, Note,
- NoteRename, Tag, TagIndexed, TagM2MTest, TagUniqueRename, Thing,
- UniqueTest, new_apps,
+ Author, AuthorTextFieldWithIndex, AuthorWithDefaultHeight,
+ AuthorWithEvenLongerName, AuthorWithIndexedName, Book, BookForeignObj,
+ BookWeak, BookWithLongName, BookWithO2O, BookWithoutAuthor, BookWithSlug,
+ IntegerPK, Node, Note, NoteRename, Tag, TagIndexed, TagM2MTest,
+ TagUniqueRename, Thing, UniqueTest, new_apps,
)
@@ -1749,6 +1749,13 @@ class SchemaTests(TransactionTestCase):
self.get_indexes(Book._meta.db_table),
)
+ def test_text_field_with_db_index(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(AuthorTextFieldWithIndex)
+ # The text_field index is present if the database supports it.
+ assertion = self.assertIn if connection.features.supports_index_on_text_field else self.assertNotIn
+ assertion('text_field', self.get_indexes(AuthorTextFieldWithIndex._meta.db_table))
+
def test_primary_key(self):
"""
Tests altering of the primary key