From ff4a10f47d9839056c67f50d07044e2ce05386a0 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 22 Aug 2016 15:06:48 +0100 Subject: [PATCH] utils: Rename to 'notifications' Every function in this file is related to notifications. Rename the file and functions therein to something more meaningful. Signed-off-by: Stephen Finucane --- patchwork/management/commands/cron.py | 5 +++-- patchwork/{utils.py => notifications.py} | 17 ++++++++++------- patchwork/tests/test_expiry.py | 10 +++++----- patchwork/tests/test_notifications.py | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) rename patchwork/{utils.py => notifications.py} (90%) diff --git a/patchwork/management/commands/cron.py b/patchwork/management/commands/cron.py index 42721777..e3e906ad 100644 --- a/patchwork/management/commands/cron.py +++ b/patchwork/management/commands/cron.py @@ -19,7 +19,8 @@ from django.core.management.base import BaseCommand -from patchwork.utils import send_notifications, do_expiry +from patchwork.notifications import expire_notifications +from patchwork.notifications import send_notifications class Command(BaseCommand): @@ -32,4 +33,4 @@ class Command(BaseCommand): self.stderr.write("Failed sending to %s: %s" % (recipient.email, error)) - do_expiry() + expire_notifications() diff --git a/patchwork/utils.py b/patchwork/notifications.py similarity index 90% rename from patchwork/utils.py rename to patchwork/notifications.py index b496af49..54204019 100644 --- a/patchwork/utils.py +++ b/patchwork/notifications.py @@ -17,8 +17,6 @@ # along with Patchwork; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from __future__ import absolute_import - import datetime import itertools @@ -29,8 +27,9 @@ from django.core.mail import EmailMessage from django.db.models import Count, Q, F from patchwork.compat import render_to_string -from patchwork.models import (PatchChangeNotification, EmailOptout, - EmailConfirmation) +from patchwork.models import EmailConfirmation +from patchwork.models import EmailOptout +from patchwork.models import PatchChangeNotification def send_notifications(): @@ -97,13 +96,17 @@ def send_notifications(): return errors -def do_expiry(): - # expire any pending confirmations +def expire_notifications(): + """Expire any pending confirmations. + + Users whose registration confirmation has expired are removed. + """ + # expire any invalid confirmations q = (Q(date__lt=datetime.datetime.now() - EmailConfirmation.validity) | Q(active=False)) EmailConfirmation.objects.filter(q).delete() - # expire inactive users with no pending confirmation + # remove inactive users with no pending confirmation pending_confs = EmailConfirmation.objects.values('user') users = User.objects.filter(is_active=False, last_login=F('date_joined')).exclude( diff --git a/patchwork/tests/test_expiry.py b/patchwork/tests/test_expiry.py index 76224649..054d1569 100644 --- a/patchwork/tests/test_expiry.py +++ b/patchwork/tests/test_expiry.py @@ -25,9 +25,9 @@ from django.test import TestCase from patchwork.models import EmailConfirmation from patchwork.models import Patch from patchwork.models import Person +from patchwork.notifications import expire_notifications from patchwork.tests.utils import create_patch from patchwork.tests.utils import create_user -from patchwork.utils import do_expiry class TestRegistrationExpiry(TestCase): @@ -50,7 +50,7 @@ class TestRegistrationExpiry(TestCase): datetime.timedelta(hours=1)) user, conf = self.register(date) - do_expiry() + expire_notifications() self.assertFalse(User.objects.filter(pk=user.pk).exists()) self.assertFalse( @@ -61,7 +61,7 @@ class TestRegistrationExpiry(TestCase): datetime.timedelta(hours=1)) user, conf = self.register(date) - do_expiry() + expire_notifications() self.assertTrue(User.objects.filter(pk=user.pk).exists()) self.assertTrue( @@ -75,7 +75,7 @@ class TestRegistrationExpiry(TestCase): conf.user.save() conf.deactivate() - do_expiry() + expire_notifications() self.assertTrue(User.objects.filter(pk=user.pk).exists()) self.assertFalse( @@ -100,7 +100,7 @@ class TestRegistrationExpiry(TestCase): conf.save() # ... which expires - do_expiry() + expire_notifications() # we should see no matching user self.assertFalse(User.objects.filter(email=patch.submitter.email) diff --git a/patchwork/tests/test_notifications.py b/patchwork/tests/test_notifications.py index 5c426fce..6cd32007 100644 --- a/patchwork/tests/test_notifications.py +++ b/patchwork/tests/test_notifications.py @@ -25,11 +25,11 @@ from django.test import TestCase from patchwork.models import EmailOptout from patchwork.models import PatchChangeNotification +from patchwork.notifications import send_notifications from patchwork.tests.utils import create_patch from patchwork.tests.utils import create_patches from patchwork.tests.utils import create_project from patchwork.tests.utils import create_state -from patchwork.utils import send_notifications class PatchNotificationModelTest(TestCase): -- 2.47.3