Commit 89325b9c by Őry Máté

dashboard: test local_periodic_tasks

parent 97d24537
......@@ -62,7 +62,7 @@ def send_email_notifications():
logger.error("Failed to send mail to %s", user, exc_info=True)
else:
logger.info("Delivered notifications %s",
" ".join(j.pk for j in i))
" ".join(unicode(j.pk) for j in i))
for j in i:
j.status = j.STATUS.delivered
j.save()
import unittest
from mock import patch, MagicMock
from ..models import Notification
from ..tasks import local_periodic_tasks
@patch.object(local_periodic_tasks, 'send_mail')
@patch.object(Notification, 'objects')
class EmailNotificationTestCase(unittest.TestCase):
def test_not_sending(self, no, sm):
fake = MagicMock(spec=Notification)
fake.to.profile.email_notifications = False
no.filter.return_value = [fake]
local_periodic_tasks.send_email_notifications()
assert not sm.called
def test_sending(self, no, sm):
fake = MagicMock(spec=Notification)
fake.to.profile.__unicode__.return_value = "user"
fake.to.email = "mail"
fake.to.profile.email_notifications = True
fake.to.profile.preferred_language = "en"
fake.subject = "subj"
fake.message = "msg"
no.filter.return_value = [fake]
local_periodic_tasks.send_email_notifications()
assert sm.called
assert fake.status == fake.STATUS.delivered
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment