summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNick Sandford <nick@sandford.id.au>2013-01-11 13:57:54 +0800
committerClaude Paroz <claude@2xlibre.net>2013-01-11 18:10:28 +0100
commiteb6c107624930c97390185fdbf7f887c50665808 (patch)
treed1c7657bcb8c0383393f63934b39f53daef0d7ae /tests
parent2e55cf580e48b02165b7aafb0d9368c714742137 (diff)
Fixed #19360 -- Raised an explicit exception for aggregates on date/time fields in sqlite3
Thanks lsaffre for the report and Chris Medrela for the initial patch.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/backends/models.py11
-rw-r--r--tests/regressiontests/backends/tests.py18
2 files changed, 28 insertions, 1 deletions
diff --git a/tests/regressiontests/backends/models.py b/tests/regressiontests/backends/models.py
index 344cf4c798..a92aa71e17 100644
--- a/tests/regressiontests/backends/models.py
+++ b/tests/regressiontests/backends/models.py
@@ -75,3 +75,14 @@ class Article(models.Model):
def __str__(self):
return self.headline
+
+
+@python_2_unicode_compatible
+class Item(models.Model):
+ name = models.CharField(max_length=30)
+ date = models.DateField()
+ time = models.TimeField()
+ last_modified = models.DateTimeField()
+
+ def __str__(self):
+ return self.name
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index 791f4c1daa..b29384739d 100644
--- a/tests/regressiontests/backends/tests.py
+++ b/tests/regressiontests/backends/tests.py
@@ -12,6 +12,7 @@ from django.db import (backend, connection, connections, DEFAULT_DB_ALIAS,
IntegrityError, transaction)
from django.db.backends.signals import connection_created
from django.db.backends.postgresql_psycopg2 import version as pg_version
+from django.db.models import fields, Sum, Avg, Variance, StdDev
from django.db.utils import ConnectionHandler, DatabaseError, load_backend
from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
TransactionTestCase)
@@ -362,6 +363,22 @@ class EscapingChecks(TestCase):
self.assertTrue(int(response))
+class SqlliteAggregationTests(TestCase):
+ """
+ #19360: Raise NotImplementedError when aggregating on date/time fields.
+ """
+ @unittest.skipUnless(connection.vendor == 'sqlite',
+ "No need to check SQLite aggregation semantics")
+ def test_aggregation(self):
+ for aggregate in (Sum, Avg, Variance, StdDev):
+ self.assertRaises(NotImplementedError,
+ models.Item.objects.all().aggregate, aggregate('time'))
+ self.assertRaises(NotImplementedError,
+ models.Item.objects.all().aggregate, aggregate('date'))
+ self.assertRaises(NotImplementedError,
+ models.Item.objects.all().aggregate, aggregate('last_modified'))
+
+
class BackendTestCase(TestCase):
def create_squares_with_executemany(self, args):
@@ -400,7 +417,6 @@ class BackendTestCase(TestCase):
self.create_squares_with_executemany(args)
self.assertEqual(models.Square.objects.count(), 9)
-
def test_unicode_fetches(self):
#6254: fetchone, fetchmany, fetchall return strings as unicode objects
qn = connection.ops.quote_name