summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnubhav Joshi <anubhav9042@gmail.com>2014-03-02 00:36:15 +0530
committerTim Graham <timograham@gmail.com>2014-03-01 15:44:42 -0500
commitbb2ca9fe6cdd490526b44b30f207c8f743bfaa84 (patch)
tree8e448c5f136ad0160d062bc65e23bc107cee656c /tests
parent3273bd7b254680a5b241e2fdbc3196956b2b44e8 (diff)
downloaddjango-bb2ca9fe6cdd490526b44b30f207c8f743bfaa84.tar.gz
Fixed #22172 -- Allowed index_together to be a single list (rather than list of lists)..
Thanks EmilStenstrom for the suggestion.
Diffstat (limited to 'tests')
-rw-r--r--tests/indexes/models.py8
-rw-r--r--tests/indexes/tests.py8
-rw-r--r--tests/invalid_models_tests/test_models.py21
-rw-r--r--tests/migrations/test_state.py3
4 files changed, 34 insertions, 6 deletions
diff --git a/tests/indexes/models.py b/tests/indexes/models.py
index e38eb005db..064a099b40 100644
--- a/tests/indexes/models.py
+++ b/tests/indexes/models.py
@@ -12,6 +12,14 @@ class Article(models.Model):
]
+# Model for index_together being used only with single list
+class IndexTogetherSingleList(models.Model):
+ headline = models.CharField(max_length=100)
+ pub_date = models.DateTimeField()
+
+ class Meta:
+ index_together = ["headline", "pub_date"]
+
# Indexing a TextField on Oracle or MySQL results in index creation error.
if connection.vendor == 'postgresql':
class IndexedArticle(models.Model):
diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py
index 605fe9037c..da93b31d87 100644
--- a/tests/indexes/tests.py
+++ b/tests/indexes/tests.py
@@ -4,7 +4,7 @@ from django.core.management.color import no_style
from django.db import connections, DEFAULT_DB_ALIAS
from django.test import TestCase
-from .models import Article
+from .models import Article, IndexTogetherSingleList
class IndexesTests(TestCase):
@@ -13,6 +13,12 @@ class IndexesTests(TestCase):
index_sql = connection.creation.sql_indexes_for_model(Article, no_style())
self.assertEqual(len(index_sql), 1)
+ def test_index_together_single_list(self):
+ # Test for using index_together with a single list (#22172)
+ connection = connections[DEFAULT_DB_ALIAS]
+ index_sql = connection.creation.sql_indexes_for_model(IndexTogetherSingleList, no_style())
+ self.assertEqual(len(index_sql), 1)
+
@skipUnless(connections[DEFAULT_DB_ALIAS].vendor == 'postgresql',
"This is a postgresql-specific issue")
def test_postgresql_text_indexes(self):
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py
index 9820aea969..c4ac960773 100644
--- a/tests/invalid_models_tests/test_models.py
+++ b/tests/invalid_models_tests/test_models.py
@@ -45,10 +45,7 @@ class IndexTogetherTests(IsolatedModelsTestCase):
def test_list_containing_non_iterable(self):
class Model(models.Model):
class Meta:
- index_together = [
- 'non-iterable',
- 'second-non-iterable',
- ]
+ index_together = [('a', 'b'), 42]
errors = Model.check()
expected = [
@@ -139,6 +136,22 @@ class UniqueTogetherTests(IsolatedModelsTestCase):
]
self.assertEqual(errors, expected)
+ def test_non_list(self):
+ class Model(models.Model):
+ class Meta:
+ unique_together = 'not-a-list'
+
+ errors = Model.check()
+ expected = [
+ Error(
+ '"unique_together" must be a list or tuple.',
+ hint=None,
+ obj=Model,
+ id='E008',
+ ),
+ ]
+ self.assertEqual(errors, expected)
+
def test_valid_model(self):
class Model(models.Model):
one = models.IntegerField()
diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py
index 5c71376179..187b06b94a 100644
--- a/tests/migrations/test_state.py
+++ b/tests/migrations/test_state.py
@@ -25,6 +25,7 @@ class StateTests(TestCase):
app_label = "migrations"
apps = new_apps
unique_together = ["name", "bio"]
+ index_together = ["bio", "age"]
class AuthorProxy(Author):
class Meta:
@@ -63,7 +64,7 @@ class StateTests(TestCase):
self.assertEqual(author_state.fields[1][1].max_length, 255)
self.assertEqual(author_state.fields[2][1].null, False)
self.assertEqual(author_state.fields[3][1].null, True)
- self.assertEqual(author_state.options, {"unique_together": set([("name", "bio")])})
+ self.assertEqual(author_state.options, {"unique_together": set([("name", "bio")]), "index_together": set([("bio", "age")])})
self.assertEqual(author_state.bases, (models.Model, ))
self.assertEqual(book_state.app_label, "migrations")