From fb17211320981492c9f18f809348cfa6367ddf67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 29 Dec 2017 18:03:42 +0200 Subject: [PATCH] Clear out `Profile.next_report_date` and `Profile.next_nag_date` when unsubscribing from reports. --- hc/accounts/tests/test_unsubscribe_reports.py | 6 ++++++ hc/accounts/views.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/hc/accounts/tests/test_unsubscribe_reports.py b/hc/accounts/tests/test_unsubscribe_reports.py index e3194f54..6464bea3 100644 --- a/hc/accounts/tests/test_unsubscribe_reports.py +++ b/hc/accounts/tests/test_unsubscribe_reports.py @@ -1,13 +1,16 @@ from datetime import timedelta as td from django.core import signing +from django.utils.timezone import now from hc.test import BaseTestCase class UnsubscribeReportsTestCase(BaseTestCase): def test_token_works(self): + self.profile.next_report_date = now() self.profile.nag_period = td(hours=1) + self.profile.next_nag_date = now() self.profile.save() token = signing.Signer().sign("foo") @@ -17,7 +20,10 @@ class UnsubscribeReportsTestCase(BaseTestCase): self.profile.refresh_from_db() self.assertFalse(self.profile.reports_allowed) + self.assertIsNone(self.profile.next_report_date) + self.assertEqual(self.profile.nag_period.total_seconds(), 0) + self.assertIsNone(self.profile.next_nag_date) def test_bad_token_gets_rejected(self): url = "/accounts/unsubscribe_reports/alice/?token=invalid" diff --git a/hc/accounts/views.py b/hc/accounts/views.py index f7f39dac..1e3b56e5 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -370,7 +370,9 @@ def unsubscribe_reports(request, username): user = User.objects.get(username=username) profile = Profile.objects.for_user(user) profile.reports_allowed = False + profile.next_report_date = None profile.nag_period = td() + profile.next_nag_date = None profile.save() return render(request, "accounts/unsubscribed.html")