summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/model_options/test_tablespaces.py44
1 files changed, 32 insertions, 12 deletions
diff --git a/tests/model_options/test_tablespaces.py b/tests/model_options/test_tablespaces.py
index ac331bd36c..b9602920da 100644
--- a/tests/model_options/test_tablespaces.py
+++ b/tests/model_options/test_tablespaces.py
@@ -10,20 +10,32 @@ from .models.tablespaces import (Article, ArticleRef, Authors, Reviewers,
Scientist, ScientistRef)
-def sql_for_table(model):
+def sql_for_table_creation(model):
return '\n'.join(connection.creation.sql_create_model(model,
no_style())[0])
-def sql_for_index(model):
+def sql_for_table_schema(model):
+ with connection.schema_editor(collect_sql=True) as editor:
+ editor.create_model(model)
+ return editor.collected_sql[0]
+
+
+def sql_for_index_creation(model):
return '\n'.join(connection.creation.sql_indexes_for_model(model,
no_style()))
+def sql_for_index_schema(model):
+ return '\n'.join(connection.schema_editor()._model_indexes_sql(model))
+
+
# We can't test the DEFAULT_TABLESPACE and DEFAULT_INDEX_TABLESPACE settings
# because they're evaluated when the model class is defined. As a consequence,
# @override_settings doesn't work, and the tests depend
class TablespacesTests(TestCase):
+ sql_for_table = staticmethod(sql_for_table_creation)
+ sql_for_index = staticmethod(sql_for_index_creation)
def setUp(self):
# The unmanaged models need to be removed after the test in order to
@@ -48,7 +60,7 @@ class TablespacesTests(TestCase):
@skipUnlessDBFeature('supports_tablespaces')
def test_tablespace_for_model(self):
- sql = sql_for_table(Scientist).lower()
+ sql = self.sql_for_table(Scientist).lower()
if settings.DEFAULT_INDEX_TABLESPACE:
# 1 for the table
self.assertNumContains(sql, 'tbl_tbsp', 1)
@@ -61,12 +73,12 @@ class TablespacesTests(TestCase):
@skipIfDBFeature('supports_tablespaces')
def test_tablespace_ignored_for_model(self):
# No tablespace-related SQL
- self.assertEqual(sql_for_table(Scientist),
- sql_for_table(ScientistRef))
+ self.assertEqual(self.sql_for_table(Scientist),
+ self.sql_for_table(ScientistRef))
@skipUnlessDBFeature('supports_tablespaces')
def test_tablespace_for_indexed_field(self):
- sql = sql_for_table(Article).lower()
+ sql = self.sql_for_table(Article).lower()
if settings.DEFAULT_INDEX_TABLESPACE:
# 1 for the table
self.assertNumContains(sql, 'tbl_tbsp', 1)
@@ -82,12 +94,12 @@ class TablespacesTests(TestCase):
@skipIfDBFeature('supports_tablespaces')
def test_tablespace_ignored_for_indexed_field(self):
# No tablespace-related SQL
- self.assertEqual(sql_for_table(Article),
- sql_for_table(ArticleRef))
+ self.assertEqual(self.sql_for_table(Article),
+ self.sql_for_table(ArticleRef))
@skipUnlessDBFeature('supports_tablespaces')
def test_tablespace_for_many_to_many_field(self):
- sql = sql_for_table(Authors).lower()
+ sql = self.sql_for_table(Authors).lower()
# The join table of the ManyToManyField goes to the model's tablespace,
# and its indexes too, unless DEFAULT_INDEX_TABLESPACE is set.
if settings.DEFAULT_INDEX_TABLESPACE:
@@ -100,7 +112,7 @@ class TablespacesTests(TestCase):
self.assertNumContains(sql, 'tbl_tbsp', 2)
self.assertNumContains(sql, 'idx_tbsp', 0)
- sql = sql_for_index(Authors).lower()
+ sql = self.sql_for_index(Authors).lower()
# The ManyToManyField declares no db_tablespace, its indexes go to
# the model's tablespace, unless DEFAULT_INDEX_TABLESPACE is set.
if settings.DEFAULT_INDEX_TABLESPACE:
@@ -109,7 +121,7 @@ class TablespacesTests(TestCase):
self.assertNumContains(sql, 'tbl_tbsp', 2)
self.assertNumContains(sql, 'idx_tbsp', 0)
- sql = sql_for_table(Reviewers).lower()
+ sql = self.sql_for_table(Reviewers).lower()
# The join table of the ManyToManyField goes to the model's tablespace,
# and its indexes too, unless DEFAULT_INDEX_TABLESPACE is set.
if settings.DEFAULT_INDEX_TABLESPACE:
@@ -122,7 +134,15 @@ class TablespacesTests(TestCase):
self.assertNumContains(sql, 'tbl_tbsp', 2)
self.assertNumContains(sql, 'idx_tbsp', 0)
- sql = sql_for_index(Reviewers).lower()
+ sql = self.sql_for_index(Reviewers).lower()
# The ManyToManyField declares db_tablespace, its indexes go there.
self.assertNumContains(sql, 'tbl_tbsp', 0)
self.assertNumContains(sql, 'idx_tbsp', 2)
+
+
+class TablespacesSchemaTests(TablespacesTests):
+ """
+ Same tests as TablespacesTests, but for the new schema infrastructure.
+ """
+ sql_for_table = staticmethod(sql_for_table_schema)
+ sql_for_index = staticmethod(sql_for_index_schema)