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
This commit is contained in:
parent
22d738c2dc
commit
c582609c8d
|
@ -1,5 +1,6 @@
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.loading import cache
|
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
|
# 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,
|
# 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):
|
def sql_for_table(model):
|
||||||
return '\n'.join(connection.creation.sql_create_model(model, no_style())[0])
|
return '\n'.join(connection.creation.sql_create_model(model, no_style())[0])
|
||||||
|
@ -45,8 +46,15 @@ class TablespacesTests(TestCase):
|
||||||
|
|
||||||
@skipUnlessDBFeature('supports_tablespaces')
|
@skipUnlessDBFeature('supports_tablespaces')
|
||||||
def test_tablespace_for_model(self):
|
def test_tablespace_for_model(self):
|
||||||
|
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
|
# 1 for the table + 1 for the index on the primary key
|
||||||
self.assertNumContains(sql_for_table(Scientist).lower(), 'tbl_tbsp', 2)
|
self.assertNumContains(sql, 'tbl_tbsp', 2)
|
||||||
|
|
||||||
@skipIfDBFeature('supports_tablespaces')
|
@skipIfDBFeature('supports_tablespaces')
|
||||||
def test_tablespace_ignored_for_model(self):
|
def test_tablespace_ignored_for_model(self):
|
||||||
|
@ -56,10 +64,18 @@ class TablespacesTests(TestCase):
|
||||||
|
|
||||||
@skipUnlessDBFeature('supports_tablespaces')
|
@skipUnlessDBFeature('supports_tablespaces')
|
||||||
def test_tablespace_for_indexed_field(self):
|
def test_tablespace_for_indexed_field(self):
|
||||||
# 1 for the table + 1 for the primary key + 1 for the index on name
|
sql = sql_for_table(Article).lower()
|
||||||
self.assertNumContains(sql_for_table(Article).lower(), 'tbl_tbsp', 3)
|
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
|
# 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')
|
@skipIfDBFeature('supports_tablespaces')
|
||||||
def test_tablespace_ignored_for_indexed_field(self):
|
def test_tablespace_ignored_for_indexed_field(self):
|
||||||
|
@ -69,20 +85,42 @@ class TablespacesTests(TestCase):
|
||||||
|
|
||||||
@skipUnlessDBFeature('supports_tablespaces')
|
@skipUnlessDBFeature('supports_tablespaces')
|
||||||
def test_tablespace_for_many_to_many_field(self):
|
def test_tablespace_for_many_to_many_field(self):
|
||||||
# The join table of the ManyToManyField always goes to the tablespace
|
sql = sql_for_table(Authors).lower()
|
||||||
# of the model.
|
# The join table of the ManyToManyField goes to the model's tablespace,
|
||||||
self.assertNumContains(sql_for_table(Authors).lower(), 'tbl_tbsp', 2)
|
# and its indexes too, unless DEFAULT_INDEX_TABLESPACE is set.
|
||||||
self.assertNumContains(sql_for_table(Authors).lower(), 'idx_tbsp', 0)
|
if settings.DEFAULT_INDEX_TABLESPACE:
|
||||||
# The ManyToManyField declares no db_tablespace, indexes for the two
|
# 1 for the table
|
||||||
# foreign keys in the join table go to the tablespace of the model.
|
self.assertNumContains(sql, 'tbl_tbsp', 1)
|
||||||
self.assertNumContains(sql_for_index(Authors).lower(), 'tbl_tbsp', 2)
|
# 1 for the primary key
|
||||||
self.assertNumContains(sql_for_index(Authors).lower(), 'idx_tbsp', 0)
|
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
|
sql = sql_for_index(Authors).lower()
|
||||||
# of the model.
|
# The ManyToManyField declares no db_tablespace, its indexes go to
|
||||||
self.assertNumContains(sql_for_table(Reviewers).lower(), 'tbl_tbsp', 2)
|
# the model's tablespace, unless DEFAULT_INDEX_TABLESPACE is set.
|
||||||
self.assertNumContains(sql_for_table(Reviewers).lower(), 'idx_tbsp', 0)
|
if settings.DEFAULT_INDEX_TABLESPACE:
|
||||||
# The ManyToManyField declares db_tablespace, indexes for the two
|
self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 2)
|
||||||
# foreign keys in the join table go to this tablespace.
|
else:
|
||||||
self.assertNumContains(sql_for_index(Reviewers).lower(), 'tbl_tbsp', 0)
|
self.assertNumContains(sql, 'tbl_tbsp', 2)
|
||||||
self.assertNumContains(sql_for_index(Reviewers).lower(), 'idx_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)
|
||||||
|
|
Loading…
Reference in New Issue