summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@rd.io>2012-11-04 10:16:06 -0800
committerAlex Gaynor <alex.gaynor@rd.io>2012-11-04 10:26:59 -0800
commit6f716e9e5f8f373f48b59791b80f0d68ce9e5bd2 (patch)
tree0037f965236d151fb5e6f278fcce2c86cd898470 /tests
parent26e0651c42a70104d237b5433970158d27b244dc (diff)
[1.5.x] Fixed #5805 -- it is now possible to specify multi-column indexes. Thanks to jgelens for the original patch. Backport of 4285571c5a9bf6ca3cb7c4d774942b9ae5b537e4.
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/invalid_models/invalid_models/models.py8
-rw-r--r--tests/regressiontests/indexes/__init__.py0
-rw-r--r--tests/regressiontests/indexes/models.py11
-rw-r--r--tests/regressiontests/indexes/tests.py12
-rw-r--r--tests/regressiontests/initial_sql_regress/tests.py7
-rw-r--r--tests/regressiontests/introspection/models.py4
-rw-r--r--tests/regressiontests/introspection/tests.py12
-rwxr-xr-xtests/runtests.py2
8 files changed, 46 insertions, 10 deletions
diff --git a/tests/modeltests/invalid_models/invalid_models/models.py b/tests/modeltests/invalid_models/invalid_models/models.py
index ccb6396352..3c21e1ddb8 100644
--- a/tests/modeltests/invalid_models/invalid_models/models.py
+++ b/tests/modeltests/invalid_models/invalid_models/models.py
@@ -356,6 +356,13 @@ class HardReferenceModel(models.Model):
m2m_4 = models.ManyToManyField('invalid_models.SwappedModel', related_name='m2m_hardref4')
+class BadIndexTogether1(models.Model):
+ class Meta:
+ index_together = [
+ ["field_that_does_not_exist"],
+ ]
+
+
model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer.
invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer.
invalid_models.fielderrors: "charfield3": CharFields require a "max_length" attribute that is a positive integer.
@@ -470,6 +477,7 @@ invalid_models.hardreferencemodel: 'm2m_3' defines a relation with the model 'in
invalid_models.hardreferencemodel: 'm2m_4' defines a relation with the model 'invalid_models.SwappedModel', which has been swapped out. Update the relation to point at settings.TEST_SWAPPED_MODEL.
invalid_models.badswappablevalue: TEST_SWAPPED_MODEL_BAD_VALUE is not of the form 'app_label.app_name'.
invalid_models.badswappablemodel: Model has been swapped out for 'not_an_app.Target' which has not been installed or is abstract.
+invalid_models.badindextogether1: "index_together" refers to field_that_does_not_exist, a field that doesn't exist.
"""
if not connection.features.interprets_empty_strings_as_nulls:
diff --git a/tests/regressiontests/indexes/__init__.py b/tests/regressiontests/indexes/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/indexes/__init__.py
diff --git a/tests/regressiontests/indexes/models.py b/tests/regressiontests/indexes/models.py
new file mode 100644
index 0000000000..9758377f99
--- /dev/null
+++ b/tests/regressiontests/indexes/models.py
@@ -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"],
+ ]
diff --git a/tests/regressiontests/indexes/tests.py b/tests/regressiontests/indexes/tests.py
new file mode 100644
index 0000000000..0dac881fa9
--- /dev/null
+++ b/tests/regressiontests/indexes/tests.py
@@ -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)
diff --git a/tests/regressiontests/initial_sql_regress/tests.py b/tests/regressiontests/initial_sql_regress/tests.py
index 03a91cb807..39d8921061 100644
--- a/tests/regressiontests/initial_sql_regress/tests.py
+++ b/tests/regressiontests/initial_sql_regress/tests.py
@@ -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)
diff --git a/tests/regressiontests/introspection/models.py b/tests/regressiontests/introspection/models.py
index 6e5beba61d..4de82e47e7 100644
--- a/tests/regressiontests/introspection/models.py
+++ b/tests/regressiontests/introspection/models.py
@@ -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"],
+ ]
diff --git a/tests/regressiontests/introspection/tests.py b/tests/regressiontests/introspection/tests.py
index 4b8a3277e2..2df946d874 100644
--- a/tests/regressiontests/introspection/tests.py
+++ b/tests/regressiontests/introspection/tests.py
@@ -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)
diff --git a/tests/runtests.py b/tests/runtests.py
index a81fee6858..90e2dc2d65 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -277,7 +277,7 @@ if __name__ == "__main__":
usage = "%prog [options] [module module module ...]"
parser = OptionParser(usage=usage)
parser.add_option(
- '-v','--verbosity', action='store', dest='verbosity', default='1',
+ '-v', '--verbosity', action='store', dest='verbosity', default='1',
type='choice', choices=['0', '1', '2', '3'],
help='Verbosity level; 0=minimal output, 1=normal output, 2=all '
'output')