Author: aaugustin
Date: 2011-10-15 08:54:53 -0700 (Sat, 15 Oct 2011)
New Revision: 16990

Modified:
   django/trunk/tests/modeltests/tablespaces/tests.py
Log:
Modified the tablespaces tests so that they no longer rely on 
settings.DEFAULT_INDEX_TABLESPACE being empty. Refs #12308.


Modified: django/trunk/tests/modeltests/tablespaces/tests.py
===================================================================
--- django/trunk/tests/modeltests/tablespaces/tests.py  2011-10-15 10:16:24 UTC 
(rev 16989)
+++ django/trunk/tests/modeltests/tablespaces/tests.py  2011-10-15 15:54:53 UTC 
(rev 16990)
@@ -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 @@
 
     @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 @@
 
     @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 @@
 
     @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)
 
-        # 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(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)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to