|
@@ -3,6 +3,7 @@ import json
|
|
import warnings
|
|
import warnings
|
|
|
|
|
|
from django.core import mail
|
|
from django.core import mail
|
|
|
|
+from django.core.management import call_command
|
|
from django.core.signing import BadSignature
|
|
from django.core.signing import BadSignature
|
|
from django.contrib.auth.models import User
|
|
from django.contrib.auth.models import User
|
|
from django.test import TestCase, Client, override_settings
|
|
from django.test import TestCase, Client, override_settings
|
|
@@ -398,3 +399,36 @@ class ContribTokenManagerTests(TestCase):
|
|
self.assertEqual(
|
|
self.assertEqual(
|
|
manager.get_instance_if_allowed(token, contrib.pk),
|
|
manager.get_instance_if_allowed(token, contrib.pk),
|
|
contrib)
|
|
contrib)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class TestManagementCommands(TestCase):
|
|
|
|
+ def setUp(self):
|
|
|
|
+ contrib = Contrib.objects.create(
|
|
|
|
+ name='John',
|
|
|
|
+ email='foo@example.com',
|
|
|
|
+ contrib_type=Contrib.CONTRIB_CONNECT,
|
|
|
|
+ latitude=0.5,
|
|
|
|
+ longitude=0.5,
|
|
|
|
+ )
|
|
|
|
+ contrib.expiration_date = datetime.datetime(
|
|
|
|
+ 2010, 10, 10, tzinfo=pytz.utc)
|
|
|
|
+ contrib.save()
|
|
|
|
+
|
|
|
|
+ @override_settings(DATA_EXPIRATION_REMINDERS=[10])
|
|
|
|
+ def test_send_expiration_reminders(self):
|
|
|
|
+ # 11 days before (should not send)
|
|
|
|
+ with freeze_time('29-09-2010', tz_offset=0):
|
|
|
|
+ call_command('send_expiration_reminders')
|
|
|
|
+ self.assertEqual(len(mail.outbox), 0)
|
|
|
|
+
|
|
|
|
+ # 9 days before (should not send)
|
|
|
|
+ with freeze_time('01-10-2010', tz_offset=0):
|
|
|
|
+ call_command('send_expiration_reminders')
|
|
|
|
+ self.assertEqual(len(mail.outbox), 0)
|
|
|
|
+
|
|
|
|
+ # 10 days before (should send)
|
|
|
|
+ with freeze_time('30-09-2010', tz_offset=0):
|
|
|
|
+ call_command('send_expiration_reminders', '--dry-run')
|
|
|
|
+ self.assertEqual(len(mail.outbox), 0)
|
|
|
|
+ call_command('send_expiration_reminders')
|
|
|
|
+ self.assertEqual(len(mail.outbox), 1)
|