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(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.º 3
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)

        eq_('Solution found to Firefox Help question', mail.outbox[0].subject)
Ejemplo n.º 4
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.º 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 = 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/'))
Ejemplo n.º 6
0
    def set_solution(self, answer, solver):
        """
        Sets the solution, and fires any needed events.

        Does not check permission of the user making the change.
        """
        # Avoid circular import
        from kitsune.questions.events import QuestionSolvedEvent

        self.solution = answer
        self.save()
        self.add_metadata(solver_id=str(solver.id))
        statsd.incr('questions.solution')
        QuestionSolvedEvent(answer).fire(exclude=self.creator)
        SolutionAction(user=answer.creator, day=answer.created).save()
Ejemplo n.º 7
0
    def set_solution(self, answer, solver):
        """
        Sets the solution, and fires any needed events.

        Does not check permission of the user making the change.
        """
        # Avoid circular import
        from kitsune.questions.events import QuestionSolvedEvent

        self.solution = answer
        self.save()
        self.add_metadata(solver_id=str(solver.id))
        statsd.incr('questions.solution')
        QuestionSolvedEvent(answer).fire(exclude=self.creator)
        actstream.action.send(
            solver, verb='marked as a solution', action_object=answer, target=self)
Ejemplo n.º 8
0
def _answers_data(request,
                  question_id,
                  form=None,
                  watch_form=None,
                  answer_preview=None):
    """Return a map of the minimal info necessary to draw an answers page."""
    question = get_object_or_404(Question, pk=question_id)
    answers_ = question.answers.all()

    # Remove spam flag if an answer passed the moderation queue
    if not settings.READ_ONLY:
        answers_.filter(flags__status=2).update(is_spam=False)

    if not request.user.has_perm("flagit.can_moderate"):
        answers_ = answers_.filter(is_spam=False)

    answers_ = paginate(request, answers_, per_page=config.ANSWERS_PER_PAGE)
    feed_urls = ((
        reverse("questions.answers.feed", kwargs={"question_id": question_id}),
        AnswersFeed().title(question),
    ), )
    frequencies = dict(FREQUENCY_CHOICES)

    is_watching_question = request.user.is_authenticated and (
        QuestionReplyEvent.is_notifying(request.user, question)
        or QuestionSolvedEvent.is_notifying(request.user, question))
    return {
        "question": question,
        "answers": answers_,
        "form": form or AnswerForm(),
        "answer_preview": answer_preview,
        "watch_form": watch_form or _init_watch_form(request, "reply"),
        "feeds": feed_urls,
        "frequencies": frequencies,
        "is_watching_question": is_watching_question,
        "can_tag": request.user.has_perm("questions.tag_question"),
        "can_create_tags": request.user.has_perm("taggit.add_tag"),
    }
Ejemplo n.º 9
0
def unwatch_question(request, question_id):
    """Stop watching a question."""
    question = get_object_or_404(Question, pk=question_id)
    QuestionReplyEvent.stop_notifying(request.user, question)
    QuestionSolvedEvent.stop_notifying(request.user, question)
    return HttpResponseRedirect(question.get_absolute_url())