Ticket #11975: bug11975.patch

File bug11975.patch, 2.0 KB (added by Fabián Ezequiel Gallina, 15 years ago)

Tests for bug #11975

  • tests/regressiontests/bug11975/views.py

     
     1# Create your views here.
  • tests/regressiontests/bug11975/tests.py

     
     1from datetime import date
     2from django.conf import settings
     3from django.db import connection
     4from django.db.models import Count
     5from django.test import TestCase
     6from models import TestModel
     7
     8
     9class TestBug11975(TestCase):
     10
     11    def setUp(self):
     12        settings.DEBUG = True
     13
     14    def testResult(self):
     15        t = TestModel()
     16        t.date = date.today()
     17        t.save()
     18        t = TestModel()
     19        t.date = date(2010, 1, 20)
     20        t.save()
     21        result = TestModel.objects.extra(
     22            select={'year':connection.ops.date_trunc_sql('year', "bug11975_testmodel.date")}
     23        ).values('year').order_by().annotate(total=Count('pk'))
     24        expected = [{'total': 2, 'year': u'2010-01-01 00:00:00'}]
     25        self.assertNotEqual(expected, result)
     26        failsql = u'SELECT (django_date_trunc("year", "bug11975_testmodel"."date")) AS "year", COUNT("bug11975_testmodel"."id") AS "total" FROM "bug11975_testmodel" GROUP BY django_date_trunc("year", "bug11975_testmodel"."date")'
     27        self.assertNotEquals(failsql, result.query.__str__())
  • tests/regressiontests/bug11975/models.py

     
     1from django.db import models
     2
     3class TestModel(models.Model):
     4
     5    date = models.DateField()
Back to Top