Skip to content
Snippets Groups Projects

Move end role notifications to day after end

Merged Andreas Ellewsen requested to merge GREG-268-notify-endrole-later into master
All threads resolved!
Files
3
+ 30
4
import datetime
import pytest
from django_q.models import Schedule
from greg.models import Notification, Role
from greg.signals import _queue_role_start_notification, _queue_role_end_notification
@@ -53,14 +55,38 @@ def test_queue_role_end_notification(role_today):
assert Notification.objects.all().count() == 5
@pytest.mark.django_db
def test_role_save_schedules_notifications(role_today):
"""Verify that future end or start dates schedule future notifications"""
oneday = datetime.timedelta(days=1)
today = datetime.date.today()
tomorrow = today + oneday
yesterday = today - oneday
assert Notification.objects.all().count() == 3
assert Schedule.objects.all().count() == 0
# Future end date schedules
role_today.end_date = tomorrow
role_today.save()
assert Schedule.objects.all().count() == 1
# Future start date schedules
role_today.start_date = tomorrow
role_today.save()
assert Schedule.objects.all().count() == 2
# Past end date does not schedule (should be impossible in the application but test anyway)
role_today.end_date = yesterday
role_today.save()
assert Schedule.objects.all().count() == 2 # Past start date schedules
role_today.start_date = yesterday
role_today.save()
@pytest.mark.django_db
def test_queue_role_end_notification_wrong_date(role_today):
"""Check that a notification is not produced if the role does not end yesterday"""
role_today.end_date = datetime.date.today() - datetime.timedelta(days=2)
role_today.save()
assert Notification.objects.all().count() == 4
assert Notification.objects.all().count() == 3
_queue_role_end_notification(role_today.id, True)
assert Notification.objects.all().count() == 4
assert Notification.objects.all().count() == 3
@pytest.mark.django_db
Loading