summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2011-10-15 15:54:53 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2011-10-15 15:54:53 +0000
commitc582609c8dbaa0a782999fa5f81e71d34ff219b8 (patch)
tree839dd9404e65bbea1738b89505b05716d45e2bf8 /tests
parent22d738c2dc87c073c20051c9fd19fa2c2887dbaa (diff)
Modified the tablespaces tests so that they no longer rely on settings.DEFAULT_INDEX_TABLESPACE being empty. Refs #12308.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16990 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/tablespaces/tests.py82
1 files changed, 60 insertions, 22 deletions
diff --git a/tests/modeltests/tablespaces/tests.py b/tests/modeltests/tablespaces/tests.py
index e8c1671717..17fdb8dd74 100644
--- a/tests/modeltests/tablespaces/tests.py
+++ b/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 @@ from models import Article, ArticleRef, Authors, Reviewers, Scientist, Scientist
# 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 @@ class TablespacesTests(TestCase):
@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 @@ class TablespacesTests(TestCase):
@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 @@ class TablespacesTests(TestCase):
@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)
+ 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)
- # 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_index(Reviewers).lower()
+ # The ManyToManyField declares db_tablespace, its indexes go there.
+ self.assertNumContains(sql, 'tbl_tbsp', 0)
+ self.assertNumContains(sql, 'idx_tbsp', 2)