Ticket #17728: 17728-failing-tests.diff

File 17728-failing-tests.diff, 4.4 KB (added by aaugustin, 3 years ago)
  • tests/modeltests/timezones/tests.py

     
    2525from django.utils.unittest import skipIf, skipUnless
    2626
    2727from .forms import EventForm, EventSplitForm, EventModelForm
    28 from .models import Event, MaybeEvent, Timestamp
     28from .models import Event, MaybeEvent, Session, SessionEvent, Timestamp
    2929
    3030
    3131# These tests use the EAT (Eastern Africa Time) and ICT (Indochina Time)
     
    231231            'dt__max': datetime.datetime(2011, 9, 1, 23, 20, 20),
    232232        })
    233233
     234    def test_query_annotation(self):
     235        # Only min and max make sense for datetimes.
     236        morning = Session.objects.create(name='morning')
     237        afternoon = Session.objects.create(name='afternoon')
     238        SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 23, 20, 20), session=afternoon)
     239        SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 13, 20, 30), session=afternoon)
     240        SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 3, 20, 40), session=morning)
     241        morning_min_dt = datetime.datetime(2011, 9, 1, 3, 20, 40)
     242        afternoon_min_dt = datetime.datetime(2011, 9, 1, 13, 20, 30)
     243        self.assertQuerysetEqual(
     244                Session.objects.annotate(dt=Min('events__dt')).order_by('dt'),
     245                [morning_min_dt, afternoon_min_dt],
     246                transform=lambda d: d.dt)
     247        self.assertQuerysetEqual(
     248                Session.objects.annotate(dt=Min('events__dt')).filter(dt__lt=afternoon_min_dt),
     249                [morning_min_dt],
     250                transform=lambda d: d.dt)
     251        self.assertQuerysetEqual(
     252                Session.objects.annotate(dt=Min('events__dt')).filter(dt__gte=afternoon_min_dt),
     253                [afternoon_min_dt],
     254                transform=lambda d: d.dt)
     255
    234256    def test_query_dates(self):
    235257        Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0))
    236258        Event.objects.create(dt=datetime.datetime(2011, 1, 1, 4, 30, 0))
     
    412434            'dt__max': datetime.datetime(2011, 9, 1, 23, 20, 20, tzinfo=EAT),
    413435        })
    414436
     437    def test_query_annotation(self):
     438        # Only min and max make sense for datetimes.
     439        morning = Session.objects.create(name='morning')
     440        afternoon = Session.objects.create(name='afternoon')
     441        SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 23, 20, 20, tzinfo=EAT), session=afternoon)
     442        SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT), session=afternoon)
     443        SessionEvent.objects.create(dt=datetime.datetime(2011, 9, 1, 3, 20, 40, tzinfo=EAT), session=morning)
     444        morning_min_dt = datetime.datetime(2011, 9, 1, 3, 20, 40, tzinfo=EAT)
     445        afternoon_min_dt = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)
     446        self.assertQuerysetEqual(
     447                Session.objects.annotate(dt=Min('events__dt')).order_by('dt'),
     448                [morning_min_dt, afternoon_min_dt],
     449                transform=lambda d: d.dt)
     450        self.assertQuerysetEqual(
     451                Session.objects.annotate(dt=Min('events__dt')).filter(dt__lt=afternoon_min_dt),
     452                [morning_min_dt],
     453                transform=lambda d: d.dt)
     454        self.assertQuerysetEqual(
     455                Session.objects.annotate(dt=Min('events__dt')).filter(dt__gte=afternoon_min_dt),
     456                [afternoon_min_dt],
     457                transform=lambda d: d.dt)
     458
    415459    def test_query_dates(self):
    416460        # Same comment as in test_query_date_related_filters.
    417461        Event.objects.create(dt=datetime.datetime(2011, 1, 1, 1, 30, 0, tzinfo=EAT))
  • tests/modeltests/timezones/models.py

     
    66class MaybeEvent(models.Model):
    77    dt = models.DateTimeField(blank=True, null=True)
    88
     9class Session(models.Model):
     10    name = models.CharField(max_length=20)
     11
     12class SessionEvent(models.Model):
     13    dt = models.DateTimeField()
     14    session = models.ForeignKey(Session, related_name='events')
     15
    916class Timestamp(models.Model):
    1017    created = models.DateTimeField(auto_now_add=True)
    1118    updated = models.DateTimeField(auto_now=True)
Back to Top