def test_watch_both_then_new_post(self, get_current): """Watching both forum and thread. Replying to a thread should send ONE email.""" get_current.return_value.domain = 'testserver' t = thread(save=True) f = t.forum forum_post(thread=t, save=True) poster = user(save=True) watcher = user(save=True) self._toggle_watch_forum_as(f, watcher, turn_on=True) self._toggle_watch_thread_as(t, watcher, turn_on=True) self.client.login(username=poster.username, password='******') post(self.client, 'forums.reply', {'content': 'a post'}, args=[f.slug, t.id]) eq_(1, len(mail.outbox)) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[watcher.email], subject='Re: {f} - {t}'.format(f=f, t=t)) body = REPLY_EMAIL.format( username=poster.username, forum_slug=f.slug, thread=t.title, thread_id=t.id, post_id=p.id) starts_with(mail.outbox[0].body, body)
def test_watch_all_then_new_post(self, get_current): """Watching document + thread + locale and reply to thread.""" get_current.return_value.domain = 'testserver' u = UserFactory() _d = DocumentFactory(title='an article title') d = self._toggle_watch_kbforum_as(u.username, _d, turn_on=True) t = ThreadFactory(title='Sticky Thread', document=d) self._toggle_watch_thread_as(u.username, t, turn_on=True) self.client.login(username=u.username, password='******') post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'}) # Reply as jsocol to document d. u2 = UserFactory(username='******') self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.reply', {'content': 'a post'}, args=[d.slug, t.id]) # Only ONE email was sent. As expected. eq_(1, len(mail.outbox)) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject='Re: an article title - Sticky Thread') starts_with(mail.outbox[0].body, REPLY_EMAIL % { 'user': u2.profile.name, 'document_slug': d.slug, 'thread_id': t.id, 'post_id': p.id, })
def test_watch_forum_then_new_post(self, get_current): """Watching a forum and replying to a thread should send email.""" get_current.return_value.domain = 'testserver' t = ThreadFactory() f = t.forum PostFactory(thread=t) poster = UserFactory() watcher = UserFactory() self._toggle_watch_forum_as(f, watcher, turn_on=True) self.client.login(username=poster.username, password='******') post(self.client, 'forums.reply', {'content': 'a post'}, args=[f.slug, t.id]) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[watcher.email], subject=u'Re: {f} - {t}'.format(f=f, t=t)) body = REPLY_EMAIL.format( username=poster.profile.name, forum_slug=f.slug, thread=t.title, thread_id=t.id, post_id=p.id) starts_with(mail.outbox[0].body, body)
def test_watch_both_then_new_post(self, get_current): """Watching both and replying to a thread should send ONE email.""" get_current.return_value.domain = 'testserver' u = UserFactory() d = DocumentFactory(title='an article title') f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) t = ThreadFactory(title='Sticky Thread', document=d) self._toggle_watch_thread_as(u.username, t, turn_on=True) u2 = UserFactory(username='******') self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.reply', {'content': 'a post'}, args=[f.slug, t.id]) eq_(1, len(mail.outbox)) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject='Re: an article title - Sticky Thread') starts_with(mail.outbox[0].body, REPLY_EMAIL % { 'user': u2.profile.name, 'document_slug': d.slug, 'thread_id': t.id, 'post_id': p.id, }) self._toggle_watch_kbforum_as(u.username, d, turn_on=False) self._toggle_watch_thread_as(u.username, t, turn_on=False)
def test_notify_asker(self): """Test that the answer is notified of answers, without registering.""" self.makeAnswer() eq_(1, len(mail.outbox)) notification = mail.outbox[0] eq_([self.question.creator.email], notification.to) eq_(u'{0} posted an answer to your question "{1}"' .format(display_name(self.answer.creator), self.question.title), notification.subject) body = re.sub(r'auth=[a-zA-Z0-9%_-]+', 'auth=AUTH', notification.body) starts_with(body, ANSWER_EMAIL_TO_ASKER.format(**self.format_args()))
def test_notify_arbitrary(self): """Test that arbitrary users are notified of new answers.""" watcher = UserFactory() QuestionReplyEvent.notify(watcher, self.question) self.makeAnswer() # One for the asker's email, and one for the watcher's email. eq_(2, len(mail.outbox)) notification = [m for m in mail.outbox if m.to == [watcher.email]][0] eq_([watcher.email], notification.to) eq_(u'Re: {0}'.format(self.question.title), notification.subject) body = re.sub(r'auth=[a-zA-Z0-9%_-]+', 'auth=AUTH', notification.body) starts_with(body, ANSWER_EMAIL.format(to_user=display_name(watcher), **self.format_args()))
def test_notify_anonymous(self): """Test that anonymous users are notified of new answers.""" ANON_EMAIL = "*****@*****.**" QuestionReplyEvent.notify(ANON_EMAIL, self.question) self.makeAnswer() # One for the asker's email, and one for the anonymous email. eq_(2, len(mail.outbox)) notification = [m for m in mail.outbox if m.to == [ANON_EMAIL]][0] eq_([ANON_EMAIL], notification.to) eq_("Re: {0}".format(self.question.title), notification.subject) body = re.sub(r"auth=[a-zA-Z0-9%_-]+", "auth=AUTH", notification.body) starts_with(body, ANSWER_EMAIL_TO_ANONYMOUS.format(**self.format_args()))
def test_notify_arbitrary(self): """Test that arbitrary users are notified of new answers.""" watcher = user(save=True) QuestionReplyEvent.notify(watcher, self.question) self.makeAnswer() # One for the asker's email, and one for the watcher's email. eq_(2, len(mail.outbox)) notification = [m for m in mail.outbox if m.to == [watcher.email]][0] eq_([watcher.email], notification.to) eq_("Re: {0}".format(self.question.title), notification.subject) body = re.sub(r"auth=[a-zA-Z0-9%_-]+", "auth=AUTH", notification.body) starts_with(body, ANSWER_EMAIL.format(to_user=watcher.username, **self.format_args()))
def test_watch_forum_then_new_post(self, get_current): """Watching a forum and replying to a thread should send email.""" get_current.return_value.domain = "testserver" u = user(save=True) d = document(title="an article title", save=True) f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) t = thread(title="Sticky Thread", document=d, save=True) u2 = user(username="******", save=True) self.client.login(username=u2.username, password="******") post(self.client, "wiki.discuss.reply", {"content": "a post"}, args=[f.slug, t.id]) p = Post.objects.all().order_by("-id")[0] attrs_eq(mail.outbox[0], to=[u.email], subject="Re: an article title - Sticky Thread") starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id))
def test_watch_forum_then_new_thread(self, get_current): """Watching a forum and creating a new thread should send email.""" get_current.return_value.domain = "testserver" u = user(save=True) d = document(title="an article title", save=True) f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) u2 = user(username="******", save=True) self.client.login(username=u2.username, password="******") post(self.client, "wiki.discuss.new_thread", {"title": "a title", "content": "a post"}, args=[f.slug]) t = Thread.objects.all().order_by("-id")[0] attrs_eq(mail.outbox[0], to=[u.email], subject=u"an article title - a title") starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % (d.slug, t.id)) self._toggle_watch_kbforum_as(u.username, d, turn_on=False)
def test_watch_thread_then_reply(self, get_current): """The event fires and sends emails when watching a thread.""" get_current.return_value.domain = "testserver" u = user(username="******", save=True) u_b = user(username="******", save=True) d = document(title="an article title", save=True) _t = thread(title="Sticky Thread", document=d, is_sticky=True, save=True) t = self._toggle_watch_thread_as(u_b.username, _t, turn_on=True) self.client.login(username=u.username, password="******") post(self.client, "wiki.discuss.reply", {"content": "a post"}, args=[t.document.slug, t.id]) p = Post.objects.all().order_by("-id")[0] attrs_eq(mail.outbox[0], to=[u_b.email], subject="Re: an article title - Sticky Thread") starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id)) self._toggle_watch_thread_as(u_b.username, _t, turn_on=False)
def test_watch_forum_then_new_thread(self, get_current): """Watching a forum and creating a new thread should send email.""" get_current.return_value.domain = "testserver" f = forum(save=True) poster = user(save=True) watcher = user(save=True) self._toggle_watch_forum_as(f, watcher, turn_on=True) self.client.login(username=poster.username, password="******") post(self.client, "forums.new_thread", {"title": "a title", "content": "a post"}, args=[f.slug]) t = Thread.objects.all().order_by("-id")[0] attrs_eq(mail.outbox[0], to=[watcher.email], subject="{f} - {t}".format(f=f, t=t)) body = NEW_THREAD_EMAIL.format(username=poster.username, forum_slug=f.slug, thread=t.title, thread_id=t.id) starts_with(mail.outbox[0].body, body)
def test_watch_locale_then_new_thread(self, get_current): """Watching locale and create a thread.""" get_current.return_value.domain = "testserver" d = document(title="an article title", locale="en-US", save=True) u = user(username="******", save=True) self.client.login(username=u.username, password="******") post(self.client, "wiki.discuss.watch_locale", {"watch": "yes"}) u2 = user(username="******", save=True) self.client.login(username=u2.username, password="******") post(self.client, "wiki.discuss.new_thread", {"title": "a title", "content": "a post"}, args=[d.slug]) # Email was sent as expected. t = Thread.objects.all().order_by("-id")[0] attrs_eq(mail.outbox[0], to=[u.email], subject=u"an article title - a title") starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % (d.slug, t.id))
def test_watch_forum_then_new_post(self, get_current): """Watching a forum and replying to a thread should send email.""" get_current.return_value.domain = 'testserver' u = user(save=True) d = document(title='an article title', save=True) f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) t = thread(title='Sticky Thread', document=d, save=True) u2 = user(username='******', save=True) self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.reply', {'content': 'a post'}, args=[f.slug, t.id]) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject='Re: an article title - Sticky Thread') starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id))
def test_solution_notification(self, get_current): """Assert that hitting the watch toggle toggles and that proper mails are sent to anonymous and registered watchers.""" # TODO: Too monolithic. Split this test into several. get_current.return_value.domain = "testserver" u = user(save=True) q = self._toggle_watch_question("solution", u, turn_on=True) QuestionSolvedEvent.notify("*****@*****.**", q) a = answer(question=q, save=True) # Mark a solution self.client.login(username=q.creator.username, password="******") post(self.client, "questions.solve", args=[q.id, a.id]) # Order of emails is not important. # Note: we skip the first email because it is a reply notification # to the asker. attrs_eq(mail.outbox[1], to=[u.email], subject="Solution found to Firefox Help question") starts_with( mail.outbox[1].body, SOLUTION_EMAIL.format( to_user=u.username, replier=a.creator.username, title=q.title, asker=q.creator.username, question_id=q.id, answer_id=a.id, locale="en-US/", ), ) attrs_eq(mail.outbox[2], to=["*****@*****.**"], subject="Solution found to Firefox Help question") starts_with( mail.outbox[2].body, SOLUTION_EMAIL_TO_ANONYMOUS.format( replier=a.creator.username, title=q.title, asker=q.creator.username, question_id=q.id, answer_id=a.id, locale="en-US/", ), )
def test_notify_anonymous(self): """Test that anonymous users are notified of new answers.""" ANON_EMAIL = '*****@*****.**' QuestionReplyEvent.notify(ANON_EMAIL, self.question) self.makeAnswer() # One for the asker's email, and one for the anonymous email. eq_(2, len(mail.outbox)) notification = [m for m in mail.outbox if m.to == [ANON_EMAIL]][0] eq_([ANON_EMAIL], notification.to) eq_("{0} commented on a Firefox question you're watching" .format(self.answer.creator.username), notification.subject) body = re.sub(r'auth=[a-zA-Z0-9%_-]+', 'auth=AUTH', notification.body) starts_with(body, ANSWER_EMAIL_TO_ANONYMOUS .format(**self.format_args()))
def test_watch_forum_then_new_thread(self, get_current): """Watching a forum and creating a new thread should send email.""" get_current.return_value.domain = 'testserver' u = user(save=True) d = document(title='an article title', save=True) f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) u2 = user(username='******', save=True) self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.new_thread', {'title': 'a title', 'content': 'a post'}, args=[f.slug]) t = Thread.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject=u'an article title - a title') starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % (d.slug, t.id)) self._toggle_watch_kbforum_as(u.username, d, turn_on=False)
def test_watch_thread_then_reply(self, get_current): """The event fires and sends emails when watching a thread.""" get_current.return_value.domain = "testserver" t = thread(save=True) f = t.forum poster = user(save=True) watcher = user(save=True) self._toggle_watch_thread_as(t, watcher, turn_on=True) self.client.login(username=poster.username, password="******") post(self.client, "forums.reply", {"content": "a post"}, args=[t.forum.slug, t.id]) p = Post.objects.all().order_by("-id")[0] attrs_eq(mail.outbox[0], to=[watcher.email], subject="Re: {f} - {t}".format(f=f, t=t)) body = REPLY_EMAIL.format( username=poster.username, forum_slug=f.slug, thread=t.title, thread_id=t.id, post_id=p.id ) starts_with(mail.outbox[0].body, body)
def test_watch_locale_then_new_thread(self, get_current): """Watching locale and create a thread.""" get_current.return_value.domain = 'testserver' d = document(title='an article title', locale='en-US', save=True) u = user(username='******', save=True) self.client.login(username=u.username, password='******') post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'}) u2 = user(username='******', save=True) self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.new_thread', {'title': 'a title', 'content': 'a post'}, args=[d.slug]) # Email was sent as expected. t = Thread.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject=u'an article title - a title') starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % (d.slug, t.id))
def test_watch_thread_then_reply(self, get_current): """The event fires and sends emails when watching a thread.""" get_current.return_value.domain = 'testserver' u = user(username='******', save=True) u_b = user(username='******', save=True) d = document(title='an article title', save=True) _t = thread(title='Sticky Thread', document=d, is_sticky=True, save=True) t = self._toggle_watch_thread_as(u_b.username, _t, turn_on=True) self.client.login(username=u.username, password='******') post(self.client, 'wiki.discuss.reply', {'content': 'a post'}, args=[t.document.slug, t.id]) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u_b.email], subject='Re: an article title - Sticky Thread') starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id)) self._toggle_watch_thread_as(u_b.username, _t, turn_on=False)
def test_watch_locale_then_new_post(self, get_current): """Watching locale and reply to a thread.""" get_current.return_value.domain = "testserver" d = document(title="an article title", locale="en-US", save=True) t = thread(document=d, title="Sticky Thread", save=True) u = user(save=True) self.client.login(username=u.username, password="******") post(self.client, "wiki.discuss.watch_locale", {"watch": "yes"}) # Reply as jsocol to document d. u2 = user(username="******", save=True) self.client.login(username=u2.username, password="******") post(self.client, "wiki.discuss.reply", {"content": "a post"}, args=[d.slug, t.id]) # Email was sent as expected. eq_(1, len(mail.outbox)) p = Post.objects.all().order_by("-id")[0] attrs_eq(mail.outbox[0], to=[u.email], subject="Re: an article title - Sticky Thread") starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id))
def test_watch_forum_then_new_thread(self, get_current): """Watching a forum and creating a new thread should send email.""" get_current.return_value.domain = 'testserver' f = ForumFactory() poster = UserFactory(username='******', profile__name='Poster') watcher = UserFactory(username='******', profile__name='Watcher') self._toggle_watch_forum_as(f, watcher, turn_on=True) self.client.login(username=poster.username, password='******') post(self.client, 'forums.new_thread', {'title': 'a title', 'content': 'a post'}, args=[f.slug]) t = Thread.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[watcher.email], subject=u'{f} - {t}'.format(f=f, t=t)) body = NEW_THREAD_EMAIL.format( username=poster.profile.name, forum_slug=f.slug, thread=t.title, thread_id=t.id) starts_with(mail.outbox[0].body, body)
def test_watch_locale_then_new_post(self, get_current): """Watching locale and reply to a thread.""" get_current.return_value.domain = 'testserver' d = document(title='an article title', locale='en-US', save=True) t = thread(document=d, title='Sticky Thread', save=True) u = user(save=True) self.client.login(username=u.username, password='******') post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'}) # Reply as jsocol to document d. u2 = user(username='******', save=True) self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.reply', {'content': 'a post'}, args=[d.slug, t.id]) # Email was sent as expected. eq_(1, len(mail.outbox)) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject='Re: an article title - Sticky Thread') starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id))
def test_solution_notification(self, get_current): """Assert that hitting the watch toggle toggles and that proper mails are sent to anonymous and registered watchers.""" # TODO: Too monolithic. Split this test into several. get_current.return_value.domain = 'testserver' u = UserFactory() q = self._toggle_watch_question('solution', u, turn_on=True) QuestionSolvedEvent.notify('*****@*****.**', q) a = AnswerFactory(question=q) # Mark a solution self.client.login(username=q.creator.username, password='******') post(self.client, 'questions.solve', args=[q.id, a.id]) # Order of emails is not important. # Note: we skip the first email because it is a reply notification # to the asker. attrs_eq(mail.outbox[1], to=[u.email], subject='Solution found to Firefox Help question') starts_with(mail.outbox[1].body, SOLUTION_EMAIL.format( to_user=display_name(u), replier=display_name(a.creator), title=q.title, asker=display_name(q.creator), question_id=q.id, answer_id=a.id, locale='en-US/')) attrs_eq(mail.outbox[2], to=['*****@*****.**'], subject='Solution found to Firefox Help question') starts_with(mail.outbox[2].body, SOLUTION_EMAIL_TO_ANONYMOUS.format( replier=display_name(a.creator), title=q.title, asker=display_name(q.creator), question_id=q.id, answer_id=a.id, locale='en-US/'))
def test_watch_forum_then_new_thread(self, get_current): """Watching a forum and creating a new thread should send email.""" get_current.return_value.domain = 'testserver' u = user(save=True) d = document(title='an article title', save=True) f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) u2 = user(username='******', save=True) self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.new_thread', { 'title': 'a title', 'content': 'a post' }, args=[f.slug]) t = Thread.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject=u'an article title - a title') starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % (d.slug, t.id)) self._toggle_watch_kbforum_as(u.username, d, turn_on=False)
def test_private_message_sends_email(self, get_current): """ With the setting enabled and receiving a private message should send and email. """ get_current.return_value.domain = 'testserver' s, c = Setting.objects.get_or_create(user=self.to, name='email_private_messages') s.value = True s.save() # User has setting, and should recieve notification email. assert Setting.get_for_user(self.to, 'email_private_messages') self.client.login(username=self.sender.username, password='******') post(self.client, 'messages.new', {'to': self.to, 'message': 'a message'}) subject = u'[SUMO] You have a new private message from [{sender}]' attrs_eq(mail.outbox[0], to=[self.to.email], subject=subject.format(sender=self.sender.profile.name)) starts_with(mail.outbox[0].body, PRIVATE_MESSAGE_EMAIL.format(sender=self.sender.profile.name))
def test_solution_notification(self, get_current): """Assert that hitting the watch toggle toggles and that proper mails are sent to anonymous and registered watchers.""" # TODO: Too monolithic. Split this test into several. get_current.return_value.domain = 'testserver' u = user(save=True) q = self._toggle_watch_question('solution', u, turn_on=True) QuestionSolvedEvent.notify('*****@*****.**', q) a = answer(question=q, save=True) # Mark a solution self.client.login(username=q.creator.username, password='******') post(self.client, 'questions.solve', args=[q.id, a.id]) # Order of emails is not important. # Note: we skip the first email because it is a reply notification # to the asker. attrs_eq(mail.outbox[1], to=[u.email], subject='Solution found to Firefox Help question') starts_with(mail.outbox[1].body, SOLUTION_EMAIL.format( to_user=u.username, replier=a.creator.username, title=q.title, asker=q.creator.username, question_id=q.id, answer_id=a.id)) attrs_eq(mail.outbox[2], to=['*****@*****.**'], subject='Solution found to Firefox Help question') starts_with(mail.outbox[2].body, SOLUTION_EMAIL_TO_ANONYMOUS.format( replier=a.creator.username, title=q.title, asker=q.creator.username, question_id=q.id, answer_id=a.id))
def test_watch_all_then_new_post(self, get_current): """Watching document + thread + locale and reply to thread.""" get_current.return_value.domain = 'testserver' u = user(save=True) _d = document(title='an article title', save=True) d = self._toggle_watch_kbforum_as(u.username, _d, turn_on=True) t = thread(title='Sticky Thread', document=d, save=True) self._toggle_watch_thread_as(u.username, t, turn_on=True) self.client.login(username=u.username, password='******') post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'}) # Reply as jsocol to document d. u2 = user(username='******', save=True) self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.reply', {'content': 'a post'}, args=[d.slug, t.id]) # Only ONE email was sent. As expected. eq_(1, len(mail.outbox)) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject='Re: an article title - Sticky Thread') starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id))
def test_watch_locale_then_new_thread(self, get_current): """Watching locale and create a thread.""" get_current.return_value.domain = 'testserver' d = document(title='an article title', locale='en-US', save=True) u = user(username='******', save=True) self.client.login(username=u.username, password='******') post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'}) u2 = user(username='******', save=True) self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.new_thread', { 'title': 'a title', 'content': 'a post' }, args=[d.slug]) # Email was sent as expected. t = Thread.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject=u'an article title - a title') starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % (d.slug, t.id))
def test_watch_both_then_new_post(self, get_current): """Watching both and replying to a thread should send ONE email.""" get_current.return_value.domain = 'testserver' u = user(save=True) d = document(title='an article title', save=True) f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) t = thread(title='Sticky Thread', document=d, save=True) self._toggle_watch_thread_as(u.username, t, turn_on=True) u2 = user(username='******', save=True) self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.reply', {'content': 'a post'}, args=[f.slug, t.id]) eq_(1, len(mail.outbox)) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[u.email], subject='Re: an article title - Sticky Thread') starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id)) self._toggle_watch_kbforum_as(u.username, d, turn_on=False) self._toggle_watch_thread_as(u.username, t, turn_on=False)
def test_watch_thread_then_reply(self, get_current): """The event fires and sends emails when watching a thread.""" get_current.return_value.domain = 'testserver' t = thread(save=True) f = t.forum poster = user(save=True) watcher = user(save=True) self._toggle_watch_thread_as(t, watcher, turn_on=True) self.client.login(username=poster.username, password='******') post(self.client, 'forums.reply', {'content': 'a post'}, args=[t.forum.slug, t.id]) p = Post.objects.all().order_by('-id')[0] attrs_eq(mail.outbox[0], to=[watcher.email], subject='Re: {f} - {t}'.format(f=f, t=t)) body = REPLY_EMAIL.format( username=poster.username, forum_slug=f.slug, thread=t.title, thread_id=t.id, post_id=p.id) starts_with(mail.outbox[0].body, body)
def test_answer_notification(self, get_current): """Assert that hitting the watch toggle toggles and that proper mails are sent to anonymous users, registered users, and the question asker.""" # TODO: This test is way too monolithic, and the fixtures encode # assumptions that aren't obvious here. Split this test into about 5, # each of which tests just 1 thing. Consider using instantiation # helpers. get_current.return_value.domain = 'testserver' # An arbitrary registered user watches: watcher = user(save=True) q = self._toggle_watch_question('reply', watcher, turn_on=True) # An anonymous user watches: QuestionReplyEvent.notify('*****@*****.**', q) # The question asker watches: QuestionReplyEvent.notify(q.creator, q) # Post a reply replier = user(save=True) self.client.login(username=replier.username, password='******') post(self.client, 'questions.reply', {'content': 'an answer'}, args=[q.id]) a = Answer.uncached.filter().order_by('-id')[0] # Order of emails is not important. eq_(3, len(mail.outbox)) emails_to = [m.to[0] for m in mail.outbox] i = emails_to.index(watcher.email) attrs_eq(mail.outbox[i], to=[watcher.email], subject='%s commented on a Firefox question ' "you're watching" % a.creator.username) body = mail.outbox[i].body body = re.sub(r'auth=[a-zA-Z0-9%_-]+', r'auth=AUTH', body) starts_with(body, ANSWER_EMAIL.format( to_user=watcher.username, title=q.title, content=a.content, replier=replier.username, question_id=q.id, answer_id=a.id)) i = emails_to.index(q.creator.email) attrs_eq(mail.outbox[i], to=[q.creator.email], subject='%s posted an answer to your question "%s"' % (a.creator.username, q.title)) body = mail.outbox[i].body body = re.sub(r'auth=[a-zA-Z0-9%_-]+', r'auth=AUTH', body) starts_with(body, ANSWER_EMAIL_TO_ASKER.format( asker=q.creator.username, title=q.title, content=a.content, replier=replier.username, question_id=q.id, answer_id=a.id)) i = emails_to.index('*****@*****.**') attrs_eq(mail.outbox[i], to=['*****@*****.**'], subject="%s commented on a Firefox question you're watching" % a.creator.username) body = mail.outbox[i].body body = re.sub(r'auth=[a-zA-Z0-9%_-]+', r'auth=AUTH', body) starts_with(body, ANSWER_EMAIL_TO_ANONYMOUS.format( title=q.title, content=a.content, replier=replier.username, question_id=q.id, answer_id=a.id))
def test_answer_notification(self, get_current): """Assert that hitting the watch toggle toggles and that proper mails are sent to anonymous users, registered users, and the question asker.""" # TODO: This test is way too monolithic, and the fixtures encode # assumptions that aren't obvious here. Split this test into about 5, # each of which tests just 1 thing. Consider using instantiation # helpers. get_current.return_value.domain = 'testserver' # An arbitrary registered user watches: watcher = user(save=True) q = self._toggle_watch_question('reply', watcher, turn_on=True) # An anonymous user watches: QuestionReplyEvent.notify('*****@*****.**', q) # The question asker watches: QuestionReplyEvent.notify(q.creator, q) # Post a reply replier = user(save=True) self.client.login(username=replier.username, password='******') post(self.client, 'questions.reply', {'content': 'an answer'}, args=[q.id]) a = Answer.uncached.filter().order_by('-id')[0] # Order of emails is not important. eq_(3, len(mail.outbox)) emails_to = [m.to[0] for m in mail.outbox] i = emails_to.index(watcher.email) attrs_eq(mail.outbox[i], to=[watcher.email], subject='%s commented on a Firefox question ' "you're watching" % a.creator.username) starts_with( mail.outbox[i].body, ANSWER_EMAIL.format(to_user=watcher.username, title=q.title, content=a.content, replier=replier.username, question_id=q.id, answer_id=a.id)) i = emails_to.index(q.creator.email) attrs_eq(mail.outbox[i], to=[q.creator.email], subject='%s posted an answer to your question "%s"' % (a.creator.username, q.title)) starts_with( mail.outbox[i].body, ANSWER_EMAIL_TO_ASKER.format(asker=q.creator.username, title=q.title, content=a.content, replier=replier.username, question_id=q.id, answer_id=a.id)) i = emails_to.index('*****@*****.**') attrs_eq(mail.outbox[i], to=['*****@*****.**'], subject="%s commented on a Firefox question you're watching" % a.creator.username) starts_with( mail.outbox[i].body, ANSWER_EMAIL_TO_ANONYMOUS.format(title=q.title, content=a.content, replier=replier.username, question_id=q.id, answer_id=a.id))