summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_indexes.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/postgres_tests/test_indexes.py')
-rw-r--r--tests/postgres_tests/test_indexes.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py
index f98d03c6c1..7d1e182726 100644
--- a/tests/postgres_tests/test_indexes.py
+++ b/tests/postgres_tests/test_indexes.py
@@ -665,6 +665,30 @@ class SchemaTests(PostgreSQLTestCase):
str(index.create_sql(CharFieldModel, editor)),
)
+ def test_custom_sql(self):
+ class CustomSQLIndex(PostgresIndex):
+ sql_create_index = "SELECT 1"
+ sql_delete_index = "SELECT 2"
+
+ def create_sql(self, model, schema_editor, using="", **kwargs):
+ kwargs.setdefault("sql", self.sql_create_index)
+ return super().create_sql(model, schema_editor, using, **kwargs)
+
+ def remove_sql(self, model, schema_editor, **kwargs):
+ kwargs.setdefault("sql", self.sql_delete_index)
+ return super().remove_sql(model, schema_editor, **kwargs)
+
+ index = CustomSQLIndex(fields=["field"], name="custom_sql_idx")
+
+ operations = [
+ (index.create_sql, CustomSQLIndex.sql_create_index),
+ (index.remove_sql, CustomSQLIndex.sql_delete_index),
+ ]
+ for operation, expected in operations:
+ with self.subTest(operation=operation.__name__):
+ with connection.schema_editor() as editor:
+ self.assertEqual(expected, str(operation(CharFieldModel, editor)))
+
def test_op_class(self):
index_name = "test_op_class"
index = Index(