]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
utils: Rename to 'notifications'
authorStephen Finucane <stephenfinucane@hotmail.com>
Mon, 22 Aug 2016 14:06:48 +0000 (15:06 +0100)
committerStephen Finucane <stephenfinucane@hotmail.com>
Wed, 7 Sep 2016 20:17:41 +0000 (21:17 +0100)
Every function in this file is related to notifications. Rename the
file and functions therein to something more meaningful.

Signed-off-by: Stephen Finucane <stephenfinucane@hotmail.com>
patchwork/management/commands/cron.py
patchwork/notifications.py [moved from patchwork/utils.py with 90% similarity]
patchwork/tests/test_expiry.py
patchwork/tests/test_notifications.py

index 42721777e5ae7f9b75a263e0556b01ed52d9588f..e3e906ade2ad1cd9f12c13bcf5a1b3e26904e8e6 100644 (file)
@@ -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()
similarity index 90%
rename from patchwork/utils.py
rename to patchwork/notifications.py
index b496af49ea019b0d1260959e6226a690f7adaae2..54204019e47a5a1ecc644a31bba753288b3a148a 100644 (file)
@@ -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(
index 76224649b9271d8475ecc70833ec959556a24a60..054d1569fa0561cf63195e405fe79b26e7a29161 100644 (file)
@@ -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)
index 5c426fcee6d7c5a894d6431bbf18c6ccdfdaaffd..6cd3200733b32a4a165be5e79cc5eddc247f6c44 100644 (file)
@@ -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):