tests: test content of mail notifications
This commit is contained in:
parent
c4c84e4b8a
commit
e989838624
|
@ -131,7 +131,8 @@ def get_notifiers():
|
|||
|
||||
def process_notifications():
|
||||
notifiers = get_notifiers()
|
||||
for notification in models.Notification.objects.select_for_update().filter(done=False):
|
||||
for notification in models.Notification.objects.order_by('id') \
|
||||
.select_for_update().filter(done=False):
|
||||
for notifier in notifiers:
|
||||
failures = []
|
||||
try:
|
||||
|
|
|
@ -92,7 +92,7 @@ class BaseTestCase(TestCase):
|
|||
User.objects.create(username='user-%s' % i,
|
||||
email='user-%s@example.com' % i))
|
||||
DocbowProfile.objects.create(user=self.users[-1],
|
||||
personal_email='personal-email-user-%s@example.com')
|
||||
personal_email='personal-email-user-%s@example.com' % i)
|
||||
self.filetypes = []
|
||||
for i in range(10):
|
||||
self.filetypes.append(
|
||||
|
@ -112,6 +112,23 @@ class BaseTestCase(TestCase):
|
|||
attached_file.save()
|
||||
self.documents[-1].post()
|
||||
|
||||
class BasicTestCase(BaseTestCase):
|
||||
def test_notification_mail(self):
|
||||
from django.core import mail
|
||||
from django.core import management
|
||||
import re
|
||||
|
||||
management.call_command('notify')
|
||||
self.assertEquals(len(mail.outbox), 20)
|
||||
outbox = sorted(mail.outbox, key=lambda m: tuple(sorted(m.to)))
|
||||
MAIL_LINK_RE = re.compile('https?://[^/]+/inbox/\d+/')
|
||||
for message, i in zip(outbox, range(20)):
|
||||
recipient = self.users[i / 2]
|
||||
emails = [recipient.docbowprofile.personal_email, recipient.email]
|
||||
self.assertEquals(set(message.to), set(emails))
|
||||
match = MAIL_LINK_RE.search(message.body)
|
||||
self.assertIsNotNone(match)
|
||||
|
||||
class UtilsTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
super(UtilsTestCase, self).setUp()
|
||||
|
|
Loading…
Reference in New Issue