Пример #1
0
    def test_autowatch_reply(self, get_current):
        """
        Tests the autowatch setting of users.

        If a user has the setting turned on, they should get
        notifications after posting in a thread for that thread. If they
        have that setting turned off, they should not.
        """

        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = question(save=True)
        t2 = question(save=True)
        assert not QuestionReplyEvent.is_notifying(u, t1)
        assert not QuestionReplyEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password='******')
        s = Setting.objects.create(user=u, name='questions_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'questions.reply', data, args=[t1.id])
        assert QuestionReplyEvent.is_notifying(u, t1)

        s.value = 'False'
        s.save()
        post(self.client, 'questions.reply', data, args=[t2.id])
        assert not QuestionReplyEvent.is_notifying(u, t2)
Пример #2
0
    def test_autowatch_reply(self, get_current):
        """
        Tests the autowatch setting of users.

        If a user has the setting turned on, they should get
        notifications after posting in a thread for that thread. If they
        have that setting turned off, they should not.
        """

        get_current.return_value.domain = "testserver"

        u = user(save=True)
        t1 = question(save=True)
        t2 = question(save=True)
        assert not QuestionReplyEvent.is_notifying(u, t1)
        assert not QuestionReplyEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password="******")
        s = Setting.objects.create(user=u, name="questions_watch_after_reply", value="True")
        data = {"content": "some content"}
        post(self.client, "questions.reply", data, args=[t1.id])
        assert QuestionReplyEvent.is_notifying(u, t1)

        s.value = "False"
        s.save()
        post(self.client, "questions.reply", data, args=[t2.id])
        assert not QuestionReplyEvent.is_notifying(u, t2)
Пример #3
0
    def test_autowatch_reply(self, get_current):
        """
        Tests the autowatch setting of users.

        If a user has the setting turned on, they should get
        notifications after posting in a thread for that thread. If they
        have that setting turned off, they should not.
        """

        get_current.return_value.domain = 'testserver'

        u = UserFactory()
        t1 = QuestionFactory()
        t2 = QuestionFactory()
        assert not QuestionReplyEvent.is_notifying(u, t1)
        assert not QuestionReplyEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password='******')
        s = Setting.objects.create(user=u, name='questions_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'questions.reply', data, args=[t1.id])
        assert QuestionReplyEvent.is_notifying(u, t1)

        s.value = 'False'
        s.save()
        post(self.client, 'questions.reply', data, args=[t2.id])
        assert not QuestionReplyEvent.is_notifying(u, t2)
Пример #4
0
    def test_no_notification_on_update(self):
        """Saving an existing question does not watch it."""

        q = Question.objects.get(pk=1)
        assert not QuestionReplyEvent.is_notifying(q.creator, q)

        q.save()
        assert not QuestionReplyEvent.is_notifying(q.creator, q)
Пример #5
0
    def test_no_notification_on_update(self):
        """Saving an existing question does not watch it."""

        q = question(save=True)
        QuestionReplyEvent.stop_notifying(q.creator, q)
        assert not QuestionReplyEvent.is_notifying(q.creator, q)

        q.save()
        assert not QuestionReplyEvent.is_notifying(q.creator, q)
Пример #6
0
    def test_no_notification_on_update(self):
        """Saving an existing question does not watch it."""

        q = QuestionFactory()
        QuestionReplyEvent.stop_notifying(q.creator, q)
        assert not QuestionReplyEvent.is_notifying(q.creator, q)

        q.save()
        assert not QuestionReplyEvent.is_notifying(q.creator, q)
Пример #7
0
    def test_notification_created(self):
        """Creating a new question auto-watches it for answers."""

        u = user(save=True)
        q = question(creator=u, title='foo', content='bar', save=True)

        assert QuestionReplyEvent.is_notifying(u, q)
Пример #8
0
    def test_notification_created(self):
        """Creating a new question auto-watches it for answers."""

        u = UserFactory()
        q = QuestionFactory(creator=u, title='foo', content='bar')

        assert QuestionReplyEvent.is_notifying(u, q)
Пример #9
0
    def test_notification_created(self):
        """Creating a new question auto-watches it for answers."""

        u = UserFactory()
        q = QuestionFactory(creator=u, title='foo', content='bar')

        assert QuestionReplyEvent.is_notifying(u, q)
Пример #10
0
    def test_notification_created(self):
        """Creating a new question auto-watches it for answers."""

        u = user(save=True)
        q = question(creator=u, title='foo', content='bar', save=True)

        assert QuestionReplyEvent.is_notifying(u, q)
Пример #11
0
    def test_notification_created(self):
        """Creating a new question auto-watches it for answers."""

        u = User.objects.get(pk=118533)
        q = Question(creator=u, title='foo', content='bar')
        q.save()

        assert QuestionReplyEvent.is_notifying(u, q)
Пример #12
0
    def test_autowatch_reply(self, get_current):
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = question(save=True)
        t2 = question(save=True)
        assert not QuestionReplyEvent.is_notifying(u, t1)
        assert not QuestionReplyEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password='******')
        s = Setting.objects.create(user=u, name='questions_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'questions.reply', data, args=[t1.id])
        assert QuestionReplyEvent.is_notifying(u, t1)

        s.value = 'False'
        s.save()
        post(self.client, 'questions.reply', data, args=[t2.id])
        assert not QuestionReplyEvent.is_notifying(u, t2)
Пример #13
0
    def test_autowatch_reply(self, get_current):
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = question(save=True)
        t2 = question(save=True)
        assert not QuestionReplyEvent.is_notifying(u, t1)
        assert not QuestionReplyEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password='******')
        s = Setting.objects.create(user=u, name='questions_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'questions.reply', data, args=[t1.id])
        assert QuestionReplyEvent.is_notifying(u, t1)

        s.value = 'False'
        s.save()
        post(self.client, 'questions.reply', data, args=[t2.id])
        assert not QuestionReplyEvent.is_notifying(u, t2)
Пример #14
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"),
    }