Ejemplo n.º 1
0
    def test_solution_notification_deleted(self, get_current):
        """Calling QuestionSolvedEvent.fire() should not query the
        questions_question table.

        This test attempts to simulate the replication lag presumed to cause
        bug 585029.

        """
        get_current.return_value.domain = 'testserver'

        a = AnswerFactory()
        q = a.question
        q.solution = a
        q.save()

        a_user = a.creator
        QuestionSolvedEvent.notify(a_user, q)
        event = QuestionSolvedEvent(a)

        # Delete the question, pretend it hasn't been replicated yet
        Question.objects.get(pk=q.pk).delete()

        event.fire(exclude=q.creator)

        # There should be a reply notification and a solved notification.
        eq_(2, len(mail.outbox))
        eq_('Solution found to Firefox Help question', mail.outbox[1].subject)
Ejemplo n.º 2
0
    def test_solution_notification_deleted(self, get_current):
        """Calling QuestionSolvedEvent.fire() should not query the
        questions_question table.

        This test attempts to simulate the replication lag presumed to cause
        bug 585029.

        """
        get_current.return_value.domain = 'testserver'

        a = answer(save=True)
        q = a.question
        q.solution = a
        q.save()

        a_user = a.creator
        QuestionSolvedEvent.notify(a_user, q)
        event = QuestionSolvedEvent(a)

        # Delete the question, pretend it hasn't been replicated yet
        Question.objects.get(pk=q.pk).delete()

        event.fire(exclude=q.creator)

        # There should be a reply notification and a solved notification.
        eq_(2, len(mail.outbox))
        eq_('Solution found to Firefox Help question', mail.outbox[1].subject)
Ejemplo n.º 3
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])
Ejemplo n.º 4
0
def watch_question(request, question_id):
    """Start watching a question for replies or solution."""

    question = get_object_or_404(Question, pk=question_id, is_spam=False)
    form = WatchQuestionForm(request.user, request.POST)

    # Process the form
    msg = None
    if form.is_valid():
        user_or_email = (request.user if request.user.is_authenticated else
                         form.cleaned_data["email"])
        try:
            if form.cleaned_data["event_type"] == "reply":
                QuestionReplyEvent.notify(user_or_email, question)
            else:
                QuestionSolvedEvent.notify(user_or_email, question)
        except ActivationRequestFailed:
            msg = _("Could not send a message to that email address.")

    # Respond to ajax request
    if request.is_ajax():
        if form.is_valid():
            msg = msg or (_("You will be notified of updates by email.")
                          if request.user.is_authenticated else _(
                              "You should receive an email shortly "
                              "to confirm your subscription."))
            return HttpResponse(json.dumps({"message": msg}))

        if request.POST.get("from_vote"):
            tmpl = "questions/includes/question_vote_thanks.html"
        else:
            tmpl = "questions/includes/email_subscribe.html"

        html = render_to_string(tmpl,
                                context={
                                    "question": question,
                                    "watch_form": form
                                },
                                request=request)
        return HttpResponse(json.dumps({"html": html}))

    if msg:
        messages.add_message(request, messages.ERROR, msg)

    return HttpResponseRedirect(question.get_absolute_url())
Ejemplo n.º 5
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/",
            ),
        )
Ejemplo n.º 6
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/'))
Ejemplo n.º 7
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.
        # 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/'))