diff --git a/hc/api/management/commands/sendreports.py b/hc/api/management/commands/sendreports.py index 59fb8413..2558be3a 100644 --- a/hc/api/management/commands/sendreports.py +++ b/hc/api/management/commands/sendreports.py @@ -4,7 +4,7 @@ import time from django.core.management.base import BaseCommand from django.db.models import Q from django.utils import timezone -from hc.accounts.models import Profile +from hc.accounts.models import NO_NAG, Profile from hc.api.models import Check @@ -63,6 +63,7 @@ class Command(BaseCommand): def handle_one_nag(self): now = timezone.now() q = Profile.objects.filter(next_nag_date__lt=now) + q = q.exclude(nag_period=NO_NAG) profile = q.first() if profile is None: diff --git a/hc/api/tests/test_sendreports.py b/hc/api/tests/test_sendreports.py index 60169036..44ca4b39 100644 --- a/hc/api/tests/test_sendreports.py +++ b/hc/api/tests/test_sendreports.py @@ -70,6 +70,15 @@ class SendAlertsTestCase(BaseTestCase): self.profile.next_nag_date = now() + td(days=1) self.profile.save() + # If next_nag_date is in future, a nag should not get sent. + found = Command().handle_one_nag() + self.assertFalse(found) + + def test_it_obeys_nag_period(self): + self.profile.nag_period = td() + self.profile.save() + + # If nag_period is 0 ("disabled"), a nag should not get sent. found = Command().handle_one_nag() self.assertFalse(found)