aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephenfinucane@hotmail.com>2016-08-22 15:06:48 +0100
committerStephen Finucane <stephenfinucane@hotmail.com>2016-09-07 21:17:41 +0100
commitff4a10f47d9839056c67f50d07044e2ce05386a0 (patch)
tree4006b5c5a7bd74eb18e9e1484e142c244370ddbb
parent804ff045e0893249bc80d0bd96de3e963faf7a46 (diff)
downloadpatchwork-ff4a10f47d9839056c67f50d07044e2ce05386a0.tar
patchwork-ff4a10f47d9839056c67f50d07044e2ce05386a0.tar.gz
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 <stephenfinucane@hotmail.com>
-rw-r--r--patchwork/management/commands/cron.py5
-rw-r--r--patchwork/notifications.py (renamed from patchwork/utils.py)17
-rw-r--r--patchwork/tests/test_expiry.py10
-rw-r--r--patchwork/tests/test_notifications.py2
4 files changed, 19 insertions, 15 deletions
diff --git a/patchwork/management/commands/cron.py b/patchwork/management/commands/cron.py
index 4272177..e3e906a 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
index b496af49..5420401 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 7622464..054d156 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 5c426fc..6cd3200 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):