sendreports doesn't send nags if nag_period=0 ("disabled"). This would result in an infinite loop of nag emails.

This commit is contained in:
Pēteris Caune 2017-12-29 18:05:23 +02:00
parent fb17211320
commit 266fbd225d
2 changed files with 11 additions and 1 deletions

View File

@ -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:

View File

@ -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)