def test_get_events_by_date_local(self): d = datetime.datetime(2012, 11, 24, 0, 0, 0, 0) tz = 'America/Toronto' es = store.get_events_by_date(d, timezone=tz) self.assertTrue(es.count > 0) from_store = [e.dict() for e in es] expected = [] for e in self._events: new_time = utc_datetime_to_local(e.occurred, pytz.timezone(tz)) if new_time.date() == d.date(): new_event_dict = e.dict() to_pg_datetime_str(new_event_dict, 'occurred') if new_event_dict['related'] is not None: for r in new_event_dict['related']: to_pg_datetime_str(r, 'occurred') new_event = Event.from_dict(new_event_dict) # need a copy new_event.localize(tz) expected.append(new_event) expected.sort(key=lambda x: x.occurred) expected.reverse() expected = [e.dict() for e in expected] for i in range(len(expected)): self.assertDictEqual(from_store[i], expected[i])
def localize(self, timezone): self.occurred = utc_datetime_to_local(self.occurred, timezone)
def latest(self): if self._metadata.latest is not None: return utc_datetime_to_local(self._metadata.latest, self.timezone)