def test_auto_check_out_dst(event, position, clist): event.settings.timezone = 'Europe/Berlin' # Survive across a shift that doesn't affect the time in question clist.exit_all_at = event.timezone.localize(datetime(2021, 3, 28, 1, 0)) clist.save() with freeze_time(clist.exit_all_at + timedelta(minutes=5)): process_exit_all(sender=None) clist.refresh_from_db() assert clist.exit_all_at.astimezone(event.timezone) == event.timezone.localize(datetime(2021, 3, 29, 1, 0)) # Survive across a shift that makes the time in question ambigous clist.exit_all_at = event.timezone.localize(datetime(2021, 10, 28, 2, 30)) clist.save() with freeze_time(clist.exit_all_at + timedelta(minutes=5)): process_exit_all(sender=None) clist.refresh_from_db() assert clist.exit_all_at.astimezone(event.timezone) == event.timezone.localize(datetime(2021, 10, 29, 2, 30)) # Doesn't survive across a shift that makes the time in question non-existant clist.exit_all_at = event.timezone.localize(datetime(2021, 3, 27, 2, 30)) clist.save() with freeze_time(clist.exit_all_at + timedelta(minutes=5)): process_exit_all(sender=None) clist.refresh_from_db() assert clist.exit_all_at.astimezone(event.timezone) == event.timezone.localize(datetime(2021, 3, 28, 2, 30)) with freeze_time(clist.exit_all_at + timedelta(minutes=5)): process_exit_all(sender=None) clist.refresh_from_db() assert clist.exit_all_at.astimezone(event.timezone) == event.timezone.localize(datetime(2021, 3, 29, 2, 30)) with freeze_time(clist.exit_all_at + timedelta(minutes=5)): process_exit_all(sender=None) clist.refresh_from_db() assert clist.exit_all_at.astimezone(event.timezone) == event.timezone.localize(datetime(2021, 3, 30, 2, 30))
def test_auto_check_out_only_if_checked_in_before_exit_all_at(event, position, clist): clist.exit_all_at = event.timezone.localize(datetime(2020, 1, 2, 3, 0)) clist.save() with freeze_time("2020-01-02 04:05:00+01:00"): perform_checkin(position, clist, {}) process_exit_all(sender=None) assert position.checkins.count() == 1
def test_auto_checkout_at_correct_time(event, position, clist): clist.exit_all_at = event.timezone.localize(datetime(2020, 1, 2, 3, 0)) clist.save() with freeze_time("2020-01-01 10:00:00+01:00"): perform_checkin(position, clist, {}) with freeze_time("2020-01-02 02:55:00+01:00"): process_exit_all(sender=None) assert position.checkins.count() == 1 with freeze_time("2020-01-02 03:05:00+01:00"): process_exit_all(sender=None) assert clist.inside_count == 0 assert position.checkins.count() == 2 assert position.checkins.first().type == Checkin.TYPE_EXIT clist.refresh_from_db() assert clist.exit_all_at == event.timezone.localize(datetime(2020, 1, 3, 3, 0))