mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[1.5.x] Fixed #5805 -- it is now possible to specify multi-column indexes. Thanks to jgelens for the original patch. Backport of 4285571c5a.
This commit is contained in:
0
tests/regressiontests/indexes/__init__.py
Normal file
0
tests/regressiontests/indexes/__init__.py
Normal file
11
tests/regressiontests/indexes/models.py
Normal file
11
tests/regressiontests/indexes/models.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Article(models.Model):
|
||||
headline = models.CharField(max_length=100)
|
||||
pub_date = models.DateTimeField()
|
||||
|
||||
class Meta:
|
||||
index_together = [
|
||||
["headline", "pub_date"],
|
||||
]
|
||||
12
tests/regressiontests/indexes/tests.py
Normal file
12
tests/regressiontests/indexes/tests.py
Normal file
@@ -0,0 +1,12 @@
|
||||
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
|
||||
|
||||
|
||||
class IndexesTests(TestCase):
|
||||
def test_index_together(self):
|
||||
connection = connections[DEFAULT_DB_ALIAS]
|
||||
index_sql = connection.creation.sql_indexes_for_model(Article, no_style())
|
||||
self.assertEqual(len(index_sql), 1)
|
||||
@@ -1,3 +1,6 @@
|
||||
from django.core.management.color import no_style
|
||||
from django.core.management.sql import custom_sql_for_model
|
||||
from django.db import connections, DEFAULT_DB_ALIAS
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import Simple
|
||||
@@ -15,10 +18,6 @@ class InitialSQLTests(TestCase):
|
||||
self.assertEqual(Simple.objects.count(), 0)
|
||||
|
||||
def test_custom_sql(self):
|
||||
from django.core.management.sql import custom_sql_for_model
|
||||
from django.core.management.color import no_style
|
||||
from django.db import connections, DEFAULT_DB_ALIAS
|
||||
|
||||
# Simulate the custom SQL loading by syncdb
|
||||
connection = connections[DEFAULT_DB_ALIAS]
|
||||
custom_sql = custom_sql_for_model(Simple, no_style(), connection)
|
||||
|
||||
@@ -17,6 +17,7 @@ class Reporter(models.Model):
|
||||
def __str__(self):
|
||||
return "%s %s" % (self.first_name, self.last_name)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Article(models.Model):
|
||||
headline = models.CharField(max_length=100)
|
||||
@@ -28,3 +29,6 @@ class Article(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ('headline',)
|
||||
index_together = [
|
||||
["headline", "pub_date"],
|
||||
]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import,unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from functools import update_wrapper
|
||||
|
||||
@@ -13,7 +13,7 @@ if connection.vendor == 'oracle':
|
||||
else:
|
||||
expectedFailureOnOracle = lambda f: f
|
||||
|
||||
#
|
||||
|
||||
# The introspection module is optional, so methods tested here might raise
|
||||
# NotImplementedError. This is perfectly acceptable behavior for the backend
|
||||
# in question, but the tests need to handle this without failing. Ideally we'd
|
||||
@@ -23,7 +23,7 @@ else:
|
||||
# wrapper that ignores the exception.
|
||||
#
|
||||
# The metaclass is just for fun.
|
||||
#
|
||||
|
||||
|
||||
def ignore_not_implemented(func):
|
||||
def _inner(*args, **kwargs):
|
||||
@@ -34,15 +34,16 @@ def ignore_not_implemented(func):
|
||||
update_wrapper(_inner, func)
|
||||
return _inner
|
||||
|
||||
|
||||
class IgnoreNotimplementedError(type):
|
||||
def __new__(cls, name, bases, attrs):
|
||||
for k,v in attrs.items():
|
||||
for k, v in attrs.items():
|
||||
if k.startswith('test'):
|
||||
attrs[k] = ignore_not_implemented(v)
|
||||
return type.__new__(cls, name, bases, attrs)
|
||||
|
||||
class IntrospectionTests(six.with_metaclass(IgnoreNotimplementedError, TestCase)):
|
||||
|
||||
class IntrospectionTests(six.with_metaclass(IgnoreNotimplementedError, TestCase)):
|
||||
def test_table_names(self):
|
||||
tl = connection.introspection.table_names()
|
||||
self.assertEqual(tl, sorted(tl))
|
||||
@@ -163,6 +164,7 @@ class IntrospectionTests(six.with_metaclass(IgnoreNotimplementedError, TestCase)
|
||||
self.assertNotIn('first_name', indexes)
|
||||
self.assertIn('id', indexes)
|
||||
|
||||
|
||||
def datatype(dbtype, description):
|
||||
"""Helper to convert a data type into a string."""
|
||||
dt = connection.introspection.get_field_type(dbtype, description)
|
||||
|
||||
Reference in New Issue
Block a user