Ejemplo n.º 1
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_title=t.title,
            thread_id=t.id,
            post_id=p.id)
        starts_with(mail.outbox[0].body, body)
Ejemplo n.º 2
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'

        question = self._toggle_watch_question('solution', turn_on=True)
        QuestionSolvedEvent.notify('*****@*****.**', question)

        answer = question.answers.all()[0]
        # Post a reply
        self.client.login(username='******', password='******')
        post(self.client, 'questions.solution', args=[question.id, answer.id])

        # Order of emails is not important.
        attrs_eq(mail.outbox[0], to=['user47963@nowhere'],
                 subject='Solution found to Firefox Help question')
        starts_with(mail.outbox[0].body, SOLUTION_EMAIL % answer.id)

        attrs_eq(mail.outbox[1], to=['*****@*****.**'],
                 subject='Solution found to Firefox Help question')
        starts_with(mail.outbox[1].body,
                    SOLUTION_EMAIL_TO_ANONYMOUS % answer.id)

        self._toggle_watch_question('solution', turn_on=False)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    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'

        to = User.objects.all()[1]
        s, c = Setting.objects.get_or_create(user=to,
                                             name='email_private_messages')
        s.value = True
        s.save()
        # User has setting, and should recieve notification email.

        assert Setting.get_for_user(to, 'email_private_messages')

        self.client.login(username='******', password='******')
        res = post(self.client, 'messages.new', {
            'to': to,
            'message': 'a message'
        })
        subject = u'[SUMO] You have a new private message from [{sender}]'

        attrs_eq(mail.outbox[0],
                 to=[to.email],
                 subject=subject.format(sender='jsocol'))
        starts_with(mail.outbox[0].body,
                    PRIVATE_MESSAGE_EMAIL.format(sender='jsocol'))
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    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'

        to = User.objects.all()[1]
        s, c = Setting.objects.get_or_create(user=to,
                                             name='email_private_messages')
        s.value = True
        s.save()
        # User has setting, and should recieve notification email.

        assert Setting.get_for_user(to, 'email_private_messages')

        self.client.login(username='******', password='******')
        res = post(self.client, 'messages.new',
             {'to': to, 'message': 'a message'})
        subject = u'[SUMO] You have a new private message from [{sender}]'

        attrs_eq(mail.outbox[0], to=[to.email],
                 subject=subject.format(sender='jsocol'))
        starts_with(mail.outbox[0].body,
                    PRIVATE_MESSAGE_EMAIL.format(sender='jsocol'))
Ejemplo n.º 7
0
    def test_watch_all_then_new_post(self, get_current):
        """Watching document + thread + locale and reply to thread."""
        get_current.return_value.domain = 'testserver'

        d = self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=True)
        t = d.thread_set.all()[0]
        self._toggle_watch_thread_as('pcraciunoiu',
                                     turn_on=True,
                                     thread_id=t.id)
        # Log in as pcraciunoiu.
        self.client.login(username='******', password='******')
        post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'})

        # Reply as jsocol to document d.
        self.client.login(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=['user47963@nowhere'],
                 subject='Re: an article title - Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % p.id)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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'

        question = self._toggle_watch_question('solution', turn_on=True)
        QuestionSolvedEvent.notify('*****@*****.**', question)

        answer = question.answers.all()[0]
        # Post a reply
        self.client.login(username='******', password='******')
        post(self.client, 'questions.solve', args=[question.id, answer.id])

        # Order of emails is not important.
        attrs_eq(mail.outbox[0],
                 to=['user47963@nowhere'],
                 subject='Solution found to Firefox Help question')
        starts_with(mail.outbox[0].body, SOLUTION_EMAIL % answer.id)

        attrs_eq(mail.outbox[1],
                 to=['*****@*****.**'],
                 subject='Solution found to Firefox Help question')
        starts_with(mail.outbox[1].body,
                    SOLUTION_EMAIL_TO_ANONYMOUS % answer.id)

        self._toggle_watch_question('solution', turn_on=False)
Ejemplo n.º 10
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'

        f = self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=True)
        t = f.thread_set.all()[0]
        self.client.login(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=['user47963@nowhere'],
                 subject='Reply to: Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % p.id)
Ejemplo n.º 11
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'

        f = self._toggle_watch_forum_as('pcraciunoiu', turn_on=True)
        t = f.thread_set.all()[0]
        self.client.login(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=['user47963@nowhere'],
                 subject='Re: Test forum - Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % p.id)
Ejemplo n.º 12
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 = self._toggle_watch_thread_as('pcraciunoiu', turn_on=True)
        self.client.login(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=['user47963@nowhere'],
                 subject='Reply to: Sticky Thread',
                 body=EMAIL_CONTENT[0] % p.id)

        self._toggle_watch_thread_as('pcraciunoiu', turn_on=False)
Ejemplo n.º 13
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 = self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=True)
        self.client.login(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=['user47963@nowhere'],
                 subject=u'New thread in an article title: a title',
                 body=EMAIL_CONTENT[1] % t.id)

        self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=False)
Ejemplo n.º 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'

        f = self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=True)
        self.client.login(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=['user47963@nowhere'],
                 subject=u'New thread in an article title: a title')
        starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % t.id)

        self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=False)
Ejemplo n.º 15
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 = self._toggle_watch_thread_as('pcraciunoiu', turn_on=True)
        self.client.login(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=['user47963@nowhere'],
                 subject='Reply to: Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % p.id)

        self._toggle_watch_thread_as('pcraciunoiu', turn_on=False)
Ejemplo n.º 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'

        t = self._toggle_watch_thread_as('pcraciunoiu', turn_on=True)
        self.client.login(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=['user47963@nowhere'],
                 subject='Re: Test forum - Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % p.id)

        self._toggle_watch_thread_as('pcraciunoiu', turn_on=False)
Ejemplo n.º 17
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 = self._toggle_watch_forum_as('pcraciunoiu', turn_on=True)
        self.client.login(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=['user47963@nowhere'],
                 subject='Test forum - a title')
        starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % t.id)

        self._toggle_watch_forum_as('pcraciunoiu', turn_on=False)
Ejemplo n.º 18
0
    def test_solution_notification(self, get_current):
        get_current.return_value.domain = 'testserver'

        question = self._toggle_watch_question('solution', turn_on=True)
        answer = question.answers.all()[0]
        # Post a reply
        self.client.login(username='******', password='******')
        post(self.client, 'questions.solution', args=[question.id, answer.id])

        attrs_eq(mail.outbox[0],
                 to=['user47963@nowhere'],
                 subject='Solution to: Lorem ipsum dolor sit amet?',
                 body=SOLUTION_EMAIL_INSIDE_REQUEST % answer.id)

        self._toggle_watch_question('solution', turn_on=False)
Ejemplo n.º 19
0
    def test_watch_solution(self, get_current):
        """Watch a question for solution."""
        self.client.logout()
        get_current.return_value.domain = "testserver"

        post(self.client, "questions.watch", {"email": "*****@*****.**", "event_type": "solution"}, args=[self.question.id])
        assert QuestionSolvedEvent.is_notifying("*****@*****.**", self.question), "Watch was not created"

        attrs_eq(mail.outbox[0], to=["*****@*****.**"], subject="Please confirm your email address")
        assert "questions/confirm/" in mail.outbox[0].body
        assert "Solution found" in mail.outbox[0].body

        # Now activate the watch.
        w = Watch.objects.get()
        get(self.client, "questions.activate_watch", args=[w.id, w.secret])
        assert Watch.objects.get().is_active
Ejemplo n.º 20
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))
Ejemplo n.º 21
0
    def test_answer_notification(self, get_current):
        get_current.return_value.domain = 'testserver'

        question = self._toggle_watch_question('reply', turn_on=True)
        # Post a reply
        self.client.login(username='******', password='******')
        post(self.client,
             'questions.reply', {'content': 'an answer'},
             args=[question.id])

        answer = Answer.uncached.filter().order_by('-id')[0]
        attrs_eq(mail.outbox[0],
                 to=['user47963@nowhere'],
                 subject='New answer to: Lorem ipsum dolor sit amet?',
                 body=ANSWER_EMAIL_INSIDE_REQUEST % answer.id)

        self._toggle_watch_question('reply', turn_on=False)
Ejemplo n.º 22
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)
Ejemplo n.º 23
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)
Ejemplo n.º 24
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.objects.filter(locale='en-US')[0]
        # Log in as pcraciunoiu.
        self.client.login(username='******', password='******')
        post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'})

        # Create new thread as jsocol for document d.
        self.client.login(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=['user47963@nowhere'],
                 subject=u'New thread in an article title: a title')
        starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % t.id)
Ejemplo n.º 25
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.objects.filter(locale='en-US')[0]
        # Log in as pcraciunoiu.
        self.client.login(username='******', password='******')
        post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'})

        # Create new thread as jsocol for document d.
        self.client.login(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=['user47963@nowhere'],
                 subject=u'an article title - a title')
        starts_with(mail.outbox[0].body, NEW_THREAD_EMAIL % t.id)
Ejemplo n.º 26
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))
Ejemplo n.º 27
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 = self._toggle_watch_forum_as('pcraciunoiu', turn_on=True)
        self.client.login(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=['user47963@nowhere'],
                 subject='New thread in Test forum forum: a title',
                 body=EMAIL_CONTENT[1] % t.id)

        self._toggle_watch_forum_as('pcraciunoiu', turn_on=False)
Ejemplo n.º 28
0
    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'

        f = self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=True)
        t = f.thread_set.all()[0]
        self._toggle_watch_thread_as('pcraciunoiu', turn_on=True,
                                     thread_id=t.id)
        self.client.login(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=['user47963@nowhere'],
                 subject='Reply to: Sticky Thread',
                 body=EMAIL_CONTENT[0] % p.id)

        self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=False)
        self._toggle_watch_thread_as('pcraciunoiu', turn_on=False)
Ejemplo n.º 29
0
    def test_watch_solution(self, get_current):
        """Watch a question for solution."""
        self.client.logout()
        get_current.return_value.domain = 'testserver'

        post(self.client, 'questions.watch',
             {'email': '*****@*****.**', 'event_type': 'solution'},
             args=[self.question.id])
        assert QuestionSolvedEvent.is_notifying('*****@*****.**', self.question), (
               'Watch was not created')

        attrs_eq(mail.outbox[0], to=['*****@*****.**'],
                 subject='Please confirm your email address')
        assert 'questions/confirm/' in mail.outbox[0].body
        assert 'Solution found' in mail.outbox[0].body

        # Now activate the watch.
        w = Watch.objects.get()
        get(self.client, 'questions.activate_watch', args=[w.id, w.secret])
        assert Watch.objects.get().is_active
Ejemplo n.º 30
0
    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'

        f = self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=True)
        t = f.thread_set.all()[0]
        self._toggle_watch_thread_as('pcraciunoiu', turn_on=True,
                                     thread_id=t.id)
        self.client.login(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=['user47963@nowhere'],
                 subject='Reply to: Sticky Thread',
                 body=EMAIL_CONTENT[0] % p.id)

        self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=False)
        self._toggle_watch_thread_as('pcraciunoiu', turn_on=False)
Ejemplo n.º 31
0
    def test_watch_solution(self, get_current):
        """Watch a question for solution."""
        self.client.logout()
        get_current.return_value.domain = 'testserver'

        post(self.client, 'questions.watch',
             {'email': '*****@*****.**', 'event_type': 'solution'},
             args=[self.question.id])
        assert QuestionSolvedEvent.is_notifying('*****@*****.**', self.question), (
               'Watch was not created')

        attrs_eq(mail.outbox[0], to=['*****@*****.**'],
                 subject='Please confirm your email address')
        assert 'questions/confirm/' in mail.outbox[0].body
        assert 'Solution found' in mail.outbox[0].body

        # Now activate the watch.
        w = Watch.objects.get()
        get(self.client, 'questions.activate_watch', args=[w.id, w.secret])
        assert Watch.objects.get().is_active
Ejemplo n.º 32
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.objects.filter(locale='en-US')[0]
        t = d.thread_set.all()[0]
        # Log in as pcraciunoiu.
        self.client.login(username='******', password='******')
        post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'})

        # Reply as jsocol to document d.
        self.client.login(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=['user47963@nowhere'],
                 subject='Reply to: Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % p.id)
Ejemplo n.º 33
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.objects.filter(locale='en-US')[0]
        t = d.thread_set.all()[0]
        # Log in as pcraciunoiu.
        self.client.login(username='******', password='******')
        post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'})

        # Reply as jsocol to document d.
        self.client.login(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=['user47963@nowhere'],
                 subject='Re: an article title - Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % p.id)
Ejemplo n.º 34
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_title=t.title,
            thread_id=t.id)
        starts_with(mail.outbox[0].body, body)
Ejemplo n.º 35
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))
Ejemplo n.º 36
0
    def test_watch_all_then_new_post(self, get_current):
        """Watching document + thread + locale and reply to thread."""
        get_current.return_value.domain = 'testserver'

        d = self._toggle_watch_kbforum_as('pcraciunoiu', turn_on=True)
        t = d.thread_set.all()[0]
        self._toggle_watch_thread_as('pcraciunoiu', turn_on=True,
                                     thread_id=t.id)
        # Log in as pcraciunoiu.
        self.client.login(username='******', password='******')
        post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'})

        # Reply as jsocol to document d.
        self.client.login(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=['user47963@nowhere'],
                 subject='Reply to: Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % p.id)
Ejemplo n.º 37
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_title=t.title,
            thread_id=t.id,
            post_id=p.id)
        starts_with(mail.outbox[0].body, body)
Ejemplo n.º 38
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 (pcraciunoiu) watches:
        question = self._toggle_watch_question('reply', turn_on=True)
        # An anonymous user watches:
        QuestionReplyEvent.notify('*****@*****.**', question)
        # The question asker (jsocol) watches:
        QuestionReplyEvent.notify(question.creator, question)

        # Post a reply
        self.client.login(username='******', password='******')
        post(self.client,
             'questions.reply', {'content': 'an answer'},
             args=[question.id])

        answer = Answer.uncached.filter().order_by('-id')[0]

        # Order of emails is not important.
        attrs_eq(mail.outbox[0],
                 to=['user47963@nowhere'],
                 subject='%s commented on a Firefox question '
                 "you're watching" % answer.creator.username)
        starts_with(mail.outbox[0].body, ANSWER_EMAIL.format(answer=answer.id))

        attrs_eq(mail.outbox[1],
                 to=[question.creator.email],
                 subject='%s posted an answer to your question "%s"' %
                 (answer.creator.username, question.title))
        starts_with(mail.outbox[1].body,
                    ANSWER_EMAIL_TO_ASKER.format(answer=answer.id))

        attrs_eq(mail.outbox[2],
                 to=['*****@*****.**'],
                 subject="%s commented on a Firefox question you're watching" %
                 answer.creator.username)
        starts_with(mail.outbox[2].body,
                    ANSWER_EMAIL_TO_ANONYMOUS.format(answer=answer.id))

        self._toggle_watch_question('reply', turn_on=False)
Ejemplo n.º 39
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'

        question = Question.objects.all()[0]
        user = User.objects.get(username='******')

        # An arbitrary registered user (pcraciunoiu) watches:
        QuestionReplyEvent.notify(user, question)
        # An anonymous user watches:
        QuestionReplyEvent.notify('*****@*****.**', question)
        # The question asker (jsocol) watches:
        QuestionReplyEvent.notify(question.creator, question)

        # Post a reply
        self.client.login(username='******', password='******')
        post(self.client, 'questions.reply', {'content': 'an answer'},
             args=[question.id])

        answer = Answer.uncached.filter().order_by('-id')[0]

        # Order of emails is not important.
        attrs_eq(mail.outbox[0], to=['user47963@nowhere'],
                 subject='%s commented on a Firefox question '
                         "you're watching" % answer.creator.username)
        starts_with(mail.outbox[0].body, ANSWER_EMAIL.format(answer=answer.id))

        attrs_eq(mail.outbox[1], to=[question.creator.email],
                 subject='%s posted an answer to your question "%s"' %
                         (answer.creator.username, question.title))
        starts_with(mail.outbox[1].body, ANSWER_EMAIL_TO_ASKER.format(
            answer=answer.id))

        attrs_eq(mail.outbox[2], to=['*****@*****.**'],
                 subject="%s commented on a Firefox question you're watching" %
                         answer.creator.username)
        starts_with(mail.outbox[2].body, ANSWER_EMAIL_TO_ANONYMOUS.format(
            answer=answer.id))