Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Aymeric Augustin authored October 15, 2011

Showing 1 changed file with 61 additions and 23 deletions. Show diff stats Hide diff stats

  1. 84  tests/modeltests/tablespaces/tests.py
84  tests/modeltests/tablespaces/tests.py
... ...
@@ -1,5 +1,6 @@
1 1
 import copy
2 2
 
  3
+from django.conf import settings
3 4
 from django.db import connection
4 5
 from django.db import models
5 6
 from django.db.models.loading import cache
@@ -10,7 +11,7 @@
10 11
 
11 12
 # We can't test the DEFAULT_TABLESPACE and DEFAULT_INDEX_TABLESPACE settings
12 13
 # because they're evaluated when the model class is defined. As a consequence,
13  
-# @override_settings doesn't work.
  14
+# @override_settings doesn't work, and the tests depend
14 15
 
15 16
 def sql_for_table(model):
16 17
     return '\n'.join(connection.creation.sql_create_model(model, no_style())[0])
@@ -45,8 +46,15 @@ def assertNumContains(self, haystack, needle, count):
45 46
 
46 47
     @skipUnlessDBFeature('supports_tablespaces')
47 48
     def test_tablespace_for_model(self):
48  
-        # 1 for the table + 1 for the index on the primary key
49  
-        self.assertNumContains(sql_for_table(Scientist).lower(), 'tbl_tbsp', 2)
  49
+        sql = sql_for_table(Scientist).lower()
  50
+        if settings.DEFAULT_INDEX_TABLESPACE:
  51
+            # 1 for the table
  52
+            self.assertNumContains(sql, 'tbl_tbsp', 1)
  53
+            # 1 for the index on the primary key
  54
+            self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 1)
  55
+        else:
  56
+            # 1 for the table + 1 for the index on the primary key
  57
+            self.assertNumContains(sql, 'tbl_tbsp', 2)
50 58
 
51 59
     @skipIfDBFeature('supports_tablespaces')
52 60
     def test_tablespace_ignored_for_model(self):
@@ -56,10 +64,18 @@ def test_tablespace_ignored_for_model(self):
56 64
 
57 65
     @skipUnlessDBFeature('supports_tablespaces')
58 66
     def test_tablespace_for_indexed_field(self):
59  
-        # 1 for the table + 1 for the primary key + 1 for the index on name
60  
-        self.assertNumContains(sql_for_table(Article).lower(), 'tbl_tbsp', 3)
  67
+        sql = sql_for_table(Article).lower()
  68
+        if settings.DEFAULT_INDEX_TABLESPACE:
  69
+            # 1 for the table
  70
+            self.assertNumContains(sql, 'tbl_tbsp', 1)
  71
+            # 1 for the primary key + 1 for the index on code
  72
+            self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 2)
  73
+        else:
  74
+            # 1 for the table + 1 for the primary key + 1 for the index on code
  75
+            self.assertNumContains(sql, 'tbl_tbsp', 3)
  76
+
61 77
         # 1 for the index on reference
62  
-        self.assertNumContains(sql_for_table(Article).lower(), 'idx_tbsp', 1)
  78
+        self.assertNumContains(sql, 'idx_tbsp', 1)
63 79
 
64 80
     @skipIfDBFeature('supports_tablespaces')
65 81
     def test_tablespace_ignored_for_indexed_field(self):
@@ -69,20 +85,42 @@ def test_tablespace_ignored_for_indexed_field(self):
69 85
 
70 86
     @skipUnlessDBFeature('supports_tablespaces')
71 87
     def test_tablespace_for_many_to_many_field(self):
72  
-        # The join table of the ManyToManyField always goes to the tablespace
73  
-        # of the model.
74  
-        self.assertNumContains(sql_for_table(Authors).lower(), 'tbl_tbsp', 2)
75  
-        self.assertNumContains(sql_for_table(Authors).lower(), 'idx_tbsp', 0)
76  
-        # The ManyToManyField declares no db_tablespace, indexes for the two
77  
-        # foreign keys in the join table go to the tablespace of the model.
78  
-        self.assertNumContains(sql_for_index(Authors).lower(), 'tbl_tbsp', 2)
79  
-        self.assertNumContains(sql_for_index(Authors).lower(), 'idx_tbsp', 0)
80  
-
81  
-        # The join table of the ManyToManyField always goes to the tablespace
82  
-        # of the model.
83  
-        self.assertNumContains(sql_for_table(Reviewers).lower(), 'tbl_tbsp', 2)
84  
-        self.assertNumContains(sql_for_table(Reviewers).lower(), 'idx_tbsp', 0)
85  
-        # The ManyToManyField declares db_tablespace, indexes for the two
86  
-        # foreign keys in the join table go to this tablespace.
87  
-        self.assertNumContains(sql_for_index(Reviewers).lower(), 'tbl_tbsp', 0)
88  
-        self.assertNumContains(sql_for_index(Reviewers).lower(), 'idx_tbsp', 2)
  88
+        sql = sql_for_table(Authors).lower()
  89
+        # The join table of the ManyToManyField goes to the model's tablespace,
  90
+        # and its indexes too, unless DEFAULT_INDEX_TABLESPACE is set.
  91
+        if settings.DEFAULT_INDEX_TABLESPACE:
  92
+            # 1 for the table
  93
+            self.assertNumContains(sql, 'tbl_tbsp', 1)
  94
+            # 1 for the primary key
  95
+            self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 1)
  96
+        else:
  97
+            # 1 for the table + 1 for the index on the primary key
  98
+            self.assertNumContains(sql, 'tbl_tbsp', 2)
  99
+        self.assertNumContains(sql, 'idx_tbsp', 0)
  100
+
  101
+        sql = sql_for_index(Authors).lower()
  102
+        # The ManyToManyField declares no db_tablespace, its indexes go to
  103
+        # the model's tablespace, unless DEFAULT_INDEX_TABLESPACE is set.
  104
+        if settings.DEFAULT_INDEX_TABLESPACE:
  105
+            self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 2)
  106
+        else:
  107
+            self.assertNumContains(sql, 'tbl_tbsp', 2)
  108
+        self.assertNumContains(sql, 'idx_tbsp', 0)
  109
+
  110
+        sql = sql_for_table(Reviewers).lower()
  111
+        # The join table of the ManyToManyField goes to the model's tablespace,
  112
+        # and its indexes too, unless DEFAULT_INDEX_TABLESPACE is set.
  113
+        if settings.DEFAULT_INDEX_TABLESPACE:
  114
+            # 1 for the table
  115
+            self.assertNumContains(sql, 'tbl_tbsp', 1)
  116
+            # 1 for the primary key
  117
+            self.assertNumContains(sql, settings.DEFAULT_INDEX_TABLESPACE, 1)
  118
+        else:
  119
+            # 1 for the table + 1 for the index on the primary key
  120
+            self.assertNumContains(sql, 'tbl_tbsp', 2)
  121
+        self.assertNumContains(sql, 'idx_tbsp', 0)
  122
+
  123
+        sql = sql_for_index(Reviewers).lower()
  124
+        # The ManyToManyField declares db_tablespace, its indexes go there.
  125
+        self.assertNumContains(sql, 'tbl_tbsp', 0)
  126
+        self.assertNumContains(sql, 'idx_tbsp', 2)

0 notes on commit c582609

Please sign in to comment.
Something went wrong with that request. Please try again.