def auto_cancel_reservation(): """Таск, автоматически отменяющий бронирование через интервал AUTO_CANCEL_INTERVAL после начала встречи""" from apps.reservation.models import Reservation now_tz = datetime.now(LocalTimezone()) for reservation in Reservation.objects.all(): if reservation.state == '0' and now_tz > reservation.start_meeting_time + timedelta( minutes=AUTO_CANCEL_INTERVAL): Reservation.auto_cancel(reservation) reservation.save() _log = LogEntry.objects.log_action( user_id=1, content_type_id=ContentType.objects.get_for_model(reservation).pk, object_id=reservation.pk, object_repr=force_text(reservation), action_flag=CHANGE, change_message="Successfully completed auto cancellation with Celery!" ) _log.save()
def test_daylight(self, patching): time = patching('celery.utils.time._time') time.timezone = 3600 time.daylight = False x = LocalTimezone() assert x.STDOFFSET == timedelta(seconds=-3600) assert x.DSTOFFSET == x.STDOFFSET time.daylight = True time.altzone = 3600 y = LocalTimezone() assert y.STDOFFSET == timedelta(seconds=-3600) assert y.DSTOFFSET == timedelta(seconds=-3600) assert repr(y) y._isdst = Mock() y._isdst.return_value = True assert y.utcoffset(datetime.now()) assert not y.dst(datetime.now()) y._isdst.return_value = False assert y.utcoffset(datetime.now()) assert not y.dst(datetime.now()) assert y.tzname(datetime.now())
def test_daylight(self): with patch('celery.utils.time._time') as time: time.timezone = 3600 time.daylight = False x = LocalTimezone() self.assertEqual(x.STDOFFSET, timedelta(seconds=-3600)) self.assertEqual(x.DSTOFFSET, x.STDOFFSET) time.daylight = True time.altzone = 3600 y = LocalTimezone() self.assertEqual(y.STDOFFSET, timedelta(seconds=-3600)) self.assertEqual(y.DSTOFFSET, timedelta(seconds=-3600)) self.assertTrue(repr(y)) y._isdst = Mock() y._isdst.return_value = True self.assertTrue(y.utcoffset(datetime.now())) self.assertFalse(y.dst(datetime.now())) y._isdst.return_value = False self.assertTrue(y.utcoffset(datetime.now())) self.assertFalse(y.dst(datetime.now())) self.assertTrue(y.tzname(datetime.now()))