Ticket #10302: ticket_10302.diff

File ticket_10302.diff, 2.1 KB (added by Raphael Michel, 9 years ago)

Regression test

  • tests/expressions/tests.py

    diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
    index f688927..95c9a92 100644
    a b from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature  
    2121from django.test.utils import Approximate
    2222from django.utils import six
    2323from django.utils.timezone import utc
    24 
    2524from .models import UUID, Company, Employee, Experiment, Number, Time
    2625
    2726
    class BasicExpressionsTests(TestCase):  
    385384        )
    386385        self.assertEqual(str(qs.query).count('JOIN'), 2)
    387386
     387    def test_ticket_10302_date_grouping(self):
     388        dtime = datetime.datetime(2015, 1, 7, 12, 6, 30)
     389        Experiment.objects.bulk_create([
     390            Experiment(name="Experiment A", assigned=dtime.date(), completed=dtime.date(),
     391                       estimated_time=datetime.timedelta(days=1), start=dtime, end=dtime + datetime.timedelta(hours=1)),
     392            Experiment(name="Experiment A", assigned=dtime.date(), completed=dtime.date(),
     393                       estimated_time=datetime.timedelta(days=1), start=dtime, end=dtime + datetime.timedelta(hours=1)),
     394            Experiment(name="Experiment A", assigned=dtime.date(), completed=dtime.date(),
     395                       estimated_time=datetime.timedelta(days=1), start=dtime + datetime.timedelta(hours=1),
     396                       end=dtime + datetime.timedelta(hours=2))
     397        ])
     398        assert list(Experiment.objects.values('start').annotate(num=Count('id'))) == [
     399            {'num': 2, 'start': datetime.datetime(2015, 1, 7, 12, 6, 30)},
     400            {'num': 1, 'start': datetime.datetime(2015, 1, 7, 13, 6, 30)}
     401        ]
     402        assert list(
     403            Experiment.objects.values('assigned').annotate(num=Count('id'))) == [
     404                   {'num': 3, 'assigned': datetime.date(2015, 1, 7)}
     405               ]
     406        assert list(
     407            Experiment.objects.annotate(date=Date('start', 'day')).values('date').annotate(num=Count('id'))) == [
     408                   {'num': 3, 'date': datetime.date(2015, 1, 7)}
     409               ]
     410
    388411
    389412class ExpressionsTests(TestCase):
    390413
Back to Top