diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2010-02-24 15:40:33 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2010-02-24 15:40:33 +0000 |
| commit | 692d122ce20c2136e796a72532e7a5f753785769 (patch) | |
| tree | 9d88296cafa430f7763a6fb39e537da1f690de85 /tests | |
| parent | 770b31e2093d8a69e43f8b3f8a967ba854ccccc1 (diff) | |
[1.1.X] Fixed #12818. SQLite now properly quotes strings for date extraction and truncation. Backport of r12573 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12575 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/backends/models.py | 5 | ||||
| -rw-r--r-- | tests/regressiontests/backends/tests.py | 32 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/regressiontests/backends/models.py b/tests/regressiontests/backends/models.py index 61b7b1af73..423bead1ad 100644 --- a/tests/regressiontests/backends/models.py +++ b/tests/regressiontests/backends/models.py @@ -15,6 +15,11 @@ class Person(models.Model): def __unicode__(self): return u'%s %s' % (self.first_name, self.last_name) +class SchoolClass(models.Model): + year = models.PositiveIntegerField() + day = models.CharField(max_length=9, blank=True) + last_updated = models.DateTimeField() + qn = connection.ops.quote_name __test__ = {'API_TESTS': """ diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py index 628fabf04a..a376cd8e87 100644 --- a/tests/regressiontests/backends/tests.py +++ b/tests/regressiontests/backends/tests.py @@ -1,9 +1,12 @@ # -*- coding: utf-8 -*- # Unit and doctests for specific database backends. +import datetime +import models import unittest from django.db import backend, connection from django.db.backends.signals import connection_created from django.conf import settings +from django.test import TestCase class Callproc(unittest.TestCase): @@ -34,6 +37,35 @@ class LongString(unittest.TestCase): c.execute('DROP TABLE ltext') self.assertEquals(long_str, row[0].read()) +class DateQuotingTest(TestCase): + + def test_django_date_trunc(self): + """ + Test the custom ``django_date_trunc method``, in particular against + fields which clash with strings passed to it (e.g. 'year') - see + #12818__. + + __: http://code.djangoproject.com/ticket/12818 + + """ + updated = datetime.datetime(2010, 2, 20) + models.SchoolClass.objects.create(year=2009, last_updated=updated) + years = models.SchoolClass.objects.dates('last_updated', 'year') + self.assertEqual(list(years), [datetime.datetime(2010, 1, 1, 0, 0)]) + + def test_django_extract(self): + """ + Test the custom ``django_extract method``, in particular against fields + which clash with strings passed to it (e.g. 'day') - see #12818__. + + __: http://code.djangoproject.com/ticket/12818 + + """ + updated = datetime.datetime(2010, 2, 20) + models.SchoolClass.objects.create(year=2009, last_updated=updated) + classes = models.SchoolClass.objects.filter(last_updated__day=20) + self.assertEqual(len(classes), 1) + def connection_created_test(sender, **kwargs): print 'connection_created signal' |
