コード例 #1
0
ファイル: test_notifications.py プロジェクト: 1234-/kitsune
    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)
コード例 #2
0
ファイル: test_notifications.py プロジェクト: 1234-/kitsune
    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,
        })
コード例 #3
0
ファイル: test_notifications.py プロジェクト: 1234-/kitsune
    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)
コード例 #4
0
ファイル: test_cron.py プロジェクト: MarkSchmidty/kitsune
    def test_answer_welcome_email(self):
        u1 = profile().user
        u2 = profile(first_answer_email_sent=True).user
        u3 = profile().user

        two_days = datetime.now() - timedelta(hours=48)

        q = question(creator=u1, save=True)
        answer(question=q, creator=u1, created=two_days, save=True)
        answer(question=q, creator=u2, created=two_days, save=True)
        answer(question=q, creator=u3, created=two_days, save=True)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        cron.send_welcome_emails()

        # There should be an email for u3 only.
        # u1 was the asker, and so did not make a contribution.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u3.email])

        # u3's flag should now be set.
        u3 = User.objects.get(id=u3.id)
        eq_(u3.profile.first_answer_email_sent, True)
コード例 #5
0
    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)
コード例 #6
0
ファイル: test_cron.py プロジェクト: 1234-/kitsune
    def test_l10n_welcome_email(self, get_current):
        get_current.return_value.domain = 'testserver'

        u1 = UserFactory()
        u2 = UserFactory(profile__first_l10n_email_sent=True)

        two_days = datetime.now() - timedelta(hours=48)

        d = DocumentFactory(locale='ru')
        RevisionFactory(document=d, creator=u1, created=two_days)
        RevisionFactory(document=d, creator=u2, created=two_days)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        cron.send_welcome_emails()

        # There should be an email for u1 only.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u1.email])

        # Links should be locale-neutral
        assert 'en-US' not in mail.outbox[0].body

        # Check that no links used the wrong host.
        assert 'support.mozilla.org' not in mail.outbox[0].body
        # Check that one link used the right host.
        assert 'https://testserver/kb/locales' in mail.outbox[0].body
        # Assumption: links will be done consistently, and so this is enough testing.

        # u3's flag should now be set.
        u1 = User.objects.get(id=u1.id)
        eq_(u1.profile.first_l10n_email_sent, True)
コード例 #7
0
    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))
コード例 #8
0
    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)
コード例 #9
0
    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)
コード例 #10
0
    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)
コード例 #11
0
    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))
コード例 #12
0
    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))
コード例 #13
0
    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/",
            ),
        )
コード例 #14
0
    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)
コード例 #15
0
    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=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/'))
コード例 #16
0
    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)
コード例 #17
0
    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))
コード例 #18
0
    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)
コード例 #19
0
    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))
コード例 #20
0
ファイル: test_cron.py プロジェクト: zu83/kitsune
    def test_answer_welcome_email(self, get_current):
        get_current.return_value.domain = "testserver"

        u1 = UserFactory()
        u2 = UserFactory(profile__first_answer_email_sent=True)
        u3 = UserFactory()

        two_days = datetime.now() - timedelta(hours=48)

        q = QuestionFactory(creator=u1)
        AnswerFactory(question=q, creator=u1, created=two_days)
        AnswerFactory(question=q, creator=u2, created=two_days)
        AnswerFactory(question=q, creator=u3, created=two_days)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        call_command("send_welcome_emails")

        # There should be an email for u3 only.
        # u1 was the asker, and so did not make a contribution.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u3.email])

        # Links should be locale-neutral
        assert "en-US" not in mail.outbox[0].body

        # Check that no links used the wrong host.
        assert "support.mozilla.org" not in mail.outbox[0].body
        # Check that one link used the right host.
        assert "https://testserver/forums/contributors" in mail.outbox[0].body
        assert (
            "The community forum is at https://testserver/forums/contributors ."
            in mail.outbox[0].body
        )
        # Assumption: links will be done consistently, and so this is enough testing.

        # u3's flag should now be set.
        u3 = User.objects.get(id=u3.id)
        eq_(u3.profile.first_answer_email_sent, True)
コード例 #21
0
    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))
コード例 #22
0
    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.
        attrs_eq(mail.outbox[0], to=[u.email],
                 subject='Solution found to Firefox Help question')
        starts_with(mail.outbox[0].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[1], to=['*****@*****.**'],
                 subject='Solution found to Firefox Help question')
        starts_with(mail.outbox[1].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/'))

        # make sure email has the proper static url
        self.assertIn('https://example.com/sumo/email/img/mozilla-support.png',
                      mail.outbox[1].alternatives[0][0])
コード例 #23
0
ファイル: test_notifications.py プロジェクト: 1234-/kitsune
    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)
コード例 #24
0
ファイル: test_cron.py プロジェクト: 1234-/kitsune
    def test_answer_welcome_email(self, get_current):
        get_current.return_value.domain = 'testserver'

        u1 = UserFactory()
        u2 = UserFactory(profile__first_answer_email_sent=True)
        u3 = UserFactory()

        two_days = datetime.now() - timedelta(hours=48)

        q = QuestionFactory(creator=u1)
        AnswerFactory(question=q, creator=u1, created=two_days)
        AnswerFactory(question=q, creator=u2, created=two_days)
        AnswerFactory(question=q, creator=u3, created=two_days)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        cron.send_welcome_emails()

        # There should be an email for u3 only.
        # u1 was the asker, and so did not make a contribution.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u3.email])

        # Links should be locale-neutral
        assert 'en-US' not in mail.outbox[0].body

        # Check that no links used the wrong host.
        assert 'support.mozilla.org' not in mail.outbox[0].body
        # Check that one link used the right host.
        assert 'https://testserver/forums/contributors' in mail.outbox[0].body
        assert ('The community forum is at https://testserver/forums/contributors .'
                in mail.outbox[0].body)
        # Assumption: links will be done consistently, and so this is enough testing.

        # u3's flag should now be set.
        u3 = User.objects.get(id=u3.id)
        eq_(u3.profile.first_answer_email_sent, True)
コード例 #25
0
    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))
コード例 #26
0
ファイル: test_notifications.py プロジェクト: zctyhj/kitsune
    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)
コード例 #27
0
ファイル: test_notifications.py プロジェクト: 1234-/kitsune
    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/'))
コード例 #28
0
    def test_answer_welcome_email(self, get_current):
        get_current.return_value.domain = 'testserver'

        u1 = profile().user
        u2 = profile(first_answer_email_sent=True).user
        u3 = profile().user

        two_days = datetime.now() - timedelta(hours=48)

        q = question(creator=u1, save=True)
        answer(question=q, creator=u1, created=two_days, save=True)
        answer(question=q, creator=u2, created=two_days, save=True)
        answer(question=q, creator=u3, created=two_days, save=True)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        cron.send_welcome_emails()

        # There should be an email for u3 only.
        # u1 was the asker, and so did not make a contribution.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u3.email])

        # Links should be locale-neutral
        assert 'en-US' not in mail.outbox[0].body

        # Check that no links used the wrong host.
        assert 'support.mozilla.org' not in mail.outbox[0].body
        # Check that one link used the right host.
        assert 'https://testserver/forums/contributors' in mail.outbox[0].body
        # Assumption: links will be done consistently, and so this is enough testing.

        # u3's flag should now be set.
        u3 = User.objects.get(id=u3.id)
        eq_(u3.profile.first_answer_email_sent, True)
コード例 #29
0
ファイル: test_notifications.py プロジェクト: 1234-/kitsune
    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))
コード例 #30
0
    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)
コード例 #31
0
    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)
コード例 #32
0
    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))
コード例 #33
0
ファイル: test_cron.py プロジェクト: MarkSchmidty/kitsune
    def test_l10n_welcome_email(self):
        u1 = profile().user
        u2 = profile(first_l10n_email_sent=True).user

        two_days = datetime.now() - timedelta(hours=48)

        d = document(locale='ru', save=True)
        revision(document=d, creator=u1, created=two_days, save=True)
        revision(document=d, creator=u2, created=two_days, save=True)

        # Clear out the notifications that were sent
        mail.outbox = []
        # Send email(s) for welcome messages
        cron.send_welcome_emails()

        # There should be an email for u1 only.
        # u2 has already recieved the email

        eq_(len(mail.outbox), 1)
        attrs_eq(mail.outbox[0], to=[u1.email])

        # u3's flag should now be set.
        u1 = User.objects.get(id=u1.id)
        eq_(u1.profile.first_l10n_email_sent, True)
コード例 #34
0
ファイル: test_notifications.py プロジェクト: zctyhj/kitsune
    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)
コード例 #35
0
    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))
コード例 #36
0
    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))