From 266fbd225d2011c6516ee27917b2e9506e747cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 29 Dec 2017 18:05:23 +0200 Subject: [PATCH] sendreports doesn't send nags if nag_period=0 ("disabled"). This would result in an infinite loop of nag emails. --- hc/api/management/commands/sendreports.py | 3 ++- hc/api/tests/test_sendreports.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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)