Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modified the tablespaces tests so that they no longer rely on setting…

…s.DEFAULT_INDEX_TABLESPACE being empty. Refs #12308.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16990 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c582609c8dbaa0a782999fa5f81e71d34ff219b8 1 parent 22d738c
@aaugustin aaugustin authored
Showing with 61 additions and 23 deletions.
  1. +61 −23 tests/modeltests/tablespaces/tests.py
View
84 tests/modeltests/tablespaces/tests.py
@@ -1,5 +1,6 @@
import copy
+from django.conf import settings
from django.db import connection
from django.db import models
from django.db.models.loading import cache
@@ -10,7 +11,7 @@
# 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.
+# @override_settings doesn't work, and the tests depend
def sql_for_table(model):
return '\n'.join(connection.creation.sql_create_model(model, no_style())[0])
@@ -45,8 +46,15 @@ def assertNumContains(self, haystack, needle, count):
@skipUnlessDBFeature('supports_tablespaces')
def test_tablespace_for_model(self):
- # 1 for the table + 1 for the index on the primary key
- self.assertNumContains(sql_for_table(Scientist).lower(), 'tbl_tbsp', 2)
+ sql = sql_for_table(Scientist).lower()
+ if settings.DEFAULT_INDEX_TABLESPACE:
+ # 1 for the table
+ self.assertNumContains(sql, 'tbl_tbsp', 1)
+ # 1 for the index on the primary key
+ self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 1)
+ else:
+ # 1 for the table + 1 for the index on the primary key
+ self.assertNumContains(sql, 'tbl_tbsp', 2)
@skipIfDBFeature('supports_tablespaces')
def test_tablespace_ignored_for_model(self):
@@ -56,10 +64,18 @@ def test_tablespace_ignored_for_model(self):
@skipUnlessDBFeature('supports_tablespaces')
def test_tablespace_for_indexed_field(self):
- # 1 for the table + 1 for the primary key + 1 for the index on name
- self.assertNumContains(sql_for_table(Article).lower(), 'tbl_tbsp', 3)
+ sql = sql_for_table(Article).lower()
+ if settings.DEFAULT_INDEX_TABLESPACE:
+ # 1 for the table
+ self.assertNumContains(sql, 'tbl_tbsp', 1)
+ # 1 for the primary key + 1 for the index on code
+ self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 2)
+ else:
+ # 1 for the table + 1 for the primary key + 1 for the index on code
+ self.assertNumContains(sql, 'tbl_tbsp', 3)
+
# 1 for the index on reference
- self.assertNumContains(sql_for_table(Article).lower(), 'idx_tbsp', 1)
+ self.assertNumContains(sql, 'idx_tbsp', 1)
@skipIfDBFeature('supports_tablespaces')
def test_tablespace_ignored_for_indexed_field(self):
@@ -69,20 +85,42 @@ def test_tablespace_ignored_for_indexed_field(self):
@skipUnlessDBFeature('supports_tablespaces')
def test_tablespace_for_many_to_many_field(self):
- # The join table of the ManyToManyField always goes to the tablespace
- # of the model.
- self.assertNumContains(sql_for_table(Authors).lower(), 'tbl_tbsp', 2)
- self.assertNumContains(sql_for_table(Authors).lower(), 'idx_tbsp', 0)
- # The ManyToManyField declares no db_tablespace, indexes for the two
- # foreign keys in the join table go to the tablespace of the model.
- self.assertNumContains(sql_for_index(Authors).lower(), 'tbl_tbsp', 2)
- self.assertNumContains(sql_for_index(Authors).lower(), 'idx_tbsp', 0)
-
- # The join table of the ManyToManyField always goes to the tablespace
- # of the model.
- self.assertNumContains(sql_for_table(Reviewers).lower(), 'tbl_tbsp', 2)
- self.assertNumContains(sql_for_table(Reviewers).lower(), 'idx_tbsp', 0)
- # The ManyToManyField declares db_tablespace, indexes for the two
- # foreign keys in the join table go to this tablespace.
- self.assertNumContains(sql_for_index(Reviewers).lower(), 'tbl_tbsp', 0)
- self.assertNumContains(sql_for_index(Reviewers).lower(), 'idx_tbsp', 2)
+ sql = 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:
+ # 1 for the table
+ self.assertNumContains(sql, 'tbl_tbsp', 1)
+ # 1 for the primary key
+ self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 1)
+ else:
+ # 1 for the table + 1 for the index on the primary key
+ self.assertNumContains(sql, 'tbl_tbsp', 2)
+ self.assertNumContains(sql, 'idx_tbsp', 0)
+
+ sql = 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:
+ self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 2)
+ else:
+ self.assertNumContains(sql, 'tbl_tbsp', 2)
+ self.assertNumContains(sql, 'idx_tbsp', 0)
+
+ sql = 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:
+ # 1 for the table
+ self.assertNumContains(sql, 'tbl_tbsp', 1)
+ # 1 for the primary key
+ self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 1)
+ else:
+ # 1 for the table + 1 for the index on the primary key
+ self.assertNumContains(sql, 'tbl_tbsp', 2)
+ self.assertNumContains(sql, 'idx_tbsp', 0)
+
+ sql = 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)
Please sign in to comment.
Something went wrong with that request. Please try again.