| 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 | |