Moved SearchVectorIndexTests.test_search_vector_index to postgres_tests.test_indexes.
This commit is contained in:
parent
263db8af46
commit
02a04ab79a
@ -539,6 +539,21 @@ class SchemaTests(PostgreSQLTestCase):
|
|||||||
editor.remove_index(Scene, index)
|
editor.remove_index(Scene, index)
|
||||||
self.assertNotIn(index_name, self.get_constraints(table))
|
self.assertNotIn(index_name, self.get_constraints(table))
|
||||||
|
|
||||||
|
def test_search_vector(self):
|
||||||
|
"""SearchVector generates IMMUTABLE SQL in order to be indexable."""
|
||||||
|
index_name = "test_search_vector"
|
||||||
|
index = Index(SearchVector("id", "scene", config="english"), name=index_name)
|
||||||
|
# Indexed function must be IMMUTABLE.
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.add_index(Scene, index)
|
||||||
|
constraints = self.get_constraints(Scene._meta.db_table)
|
||||||
|
self.assertIn(index_name, constraints)
|
||||||
|
self.assertIs(constraints[index_name]["index"], True)
|
||||||
|
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
editor.remove_index(Scene, index)
|
||||||
|
self.assertNotIn(index_name, self.get_constraints(Scene._meta.db_table))
|
||||||
|
|
||||||
def test_hash_index(self):
|
def test_hash_index(self):
|
||||||
# Ensure the table is there and doesn't have an index.
|
# Ensure the table is there and doesn't have an index.
|
||||||
self.assertNotIn("field", self.get_constraints(CharFieldModel._meta.db_table))
|
self.assertNotIn("field", self.get_constraints(CharFieldModel._meta.db_table))
|
||||||
|
@ -5,7 +5,6 @@ These tests use dialogue from the 1975 film Monty Python and the Holy Grail.
|
|||||||
All text copyright Python (Monty) Pictures. Thanks to sacred-texts.com for the
|
All text copyright Python (Monty) Pictures. Thanks to sacred-texts.com for the
|
||||||
transcript.
|
transcript.
|
||||||
"""
|
"""
|
||||||
from django.db import connection
|
|
||||||
from django.db.models import F, Value
|
from django.db.models import F, Value
|
||||||
|
|
||||||
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
|
||||||
@ -609,26 +608,6 @@ class TestRankingAndWeights(GrailTestData, PostgreSQLTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SearchVectorIndexTests(PostgreSQLTestCase):
|
|
||||||
def test_search_vector_index(self):
|
|
||||||
"""SearchVector generates IMMUTABLE SQL in order to be indexable."""
|
|
||||||
# This test should be moved to test_indexes and use a functional
|
|
||||||
# index instead once support lands (see #26167).
|
|
||||||
query = Line.objects.all().query
|
|
||||||
resolved = SearchVector("id", "dialogue", config="english").resolve_expression(
|
|
||||||
query
|
|
||||||
)
|
|
||||||
compiler = query.get_compiler(connection.alias)
|
|
||||||
sql, params = resolved.as_sql(compiler, connection)
|
|
||||||
# Indexed function must be IMMUTABLE.
|
|
||||||
with connection.cursor() as cursor:
|
|
||||||
cursor.execute(
|
|
||||||
"CREATE INDEX search_vector_index ON %s USING GIN (%s)"
|
|
||||||
% (Line._meta.db_table, sql),
|
|
||||||
params,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SearchQueryTests(PostgreSQLSimpleTestCase):
|
class SearchQueryTests(PostgreSQLSimpleTestCase):
|
||||||
def test_str(self):
|
def test_str(self):
|
||||||
tests = (
|
tests = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user