示例#1
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)
示例#2
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)
示例#3
0
文件: views.py 项目: tantek/kuma
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_ = paginate(request, question.answers.all(),
                        per_page=constants.ANSWERS_PER_PAGE)
    vocab = [t.name for t in Tag.objects.all()]  # TODO: Fetch only name.
    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,
            'tag_vocab': json.dumps(vocab),
            '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')}
示例#4
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()
    if not request.MOBILE:
        answers_ = paginate(request, answers_,
                            per_page=constants.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')}
示例#5
0
文件: views.py 项目: fox2mike/kitsune
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_ = paginate(request, question.answers.all(), per_page=constants.ANSWERS_PER_PAGE)
    vocab = [t.name for t in Tag.objects.all()]  # TODO: Fetch only name.
    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,
        "tag_vocab": json.dumps(vocab),
        "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"),
    }
示例#6
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)
示例#7
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)
示例#8
0
 def test_watch_replies_logged_in(self):
     """Watch a question for replies (logged in)."""
     self.client.login(username='******', password='******')
     user = User.objects.get(username='******')
     post(self.client,
          'questions.watch', {'event_type': 'reply'},
          args=[self.question.id])
     assert QuestionReplyEvent.is_notifying(
         user, self.question), ('Watch was not created')
示例#9
0
 def test_unwatch(self):
     """Unwatch a question."""
     # First watch question.
     self.test_watch_replies_logged_in()
     # Then unwatch it.
     self.client.login(username="******", password="******")
     user = User.objects.get(username="******")
     post(self.client, "questions.unwatch", args=[self.question.id])
     assert not QuestionReplyEvent.is_notifying(user, self.question), "Watch was not destroyed"
示例#10
0
 def test_watch_replies_logged_in(self):
     """Watch a question for replies (logged in)."""
     self.client.login(username='******', password='******')
     user = User.objects.get(username='******')
     post(self.client, 'questions.watch',
          {'event_type': 'reply'},
          args=[self.question.id])
     assert QuestionReplyEvent.is_notifying(user, self.question), (
            'Watch was not created')
示例#11
0
 def test_unwatch(self):
     """Unwatch a question."""
     # First watch question.
     self.test_watch_replies_logged_in()
     # Then unwatch it.
     self.client.login(username='******', password='******')
     user = User.objects.get(username='******')
     post(self.client, 'questions.unwatch', args=[self.question.id])
     assert not QuestionReplyEvent.is_notifying(
         user, self.question), ('Watch was not destroyed')
示例#12
0
    def test_autowatch_reply(self, get_current):
        get_current.return_value.domain = 'testserver'

        user = User.objects.get(username='******')
        t1, t2 = Question.objects.filter(is_locked=False)[0:2]
        assert not QuestionReplyEvent.is_notifying(user, t1)
        assert not QuestionReplyEvent.is_notifying(user, t2)

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

        s.value = 'False'
        s.save()
        post(self.client, 'questions.reply', data, args=[t2.id])
        assert not QuestionReplyEvent.is_notifying(user, t2)
示例#13
0
    def test_watch_replies_smtp_error(self, emailmessage_send):
        """Watch a question for replies and fail to send email."""
        emailmessage_send.side_effect = emailmessage_raise_smtp
        self.client.logout()

        r = post(
            self.client, "questions.watch", {"email": "*****@*****.**", "event_type": "reply"}, args=[self.question.id]
        )
        assert not QuestionReplyEvent.is_notifying("*****@*****.**", self.question), "Watch was created"
        self.assertContains(r, "Could not send a message to that email")
示例#14
0
    def test_autowatch_reply(self, get_current):
        get_current.return_value.domain = 'testserver'

        user = User.objects.get(username='******')
        t1, t2 = Question.objects.filter(is_locked=False)[0:2]
        assert not QuestionReplyEvent.is_notifying(user, t1)
        assert not QuestionReplyEvent.is_notifying(user, t2)

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

        s.value = 'False'
        s.save()
        post(self.client, 'questions.reply', data, args=[t2.id])
        assert not QuestionReplyEvent.is_notifying(user, t2)
示例#15
0
    def test_watch_replies_smtp_error(self, emailmessage_send):
        """Watch a question for replies and fail to send email."""
        emailmessage_send.side_effect = emailmessage_raise_smtp
        self.client.logout()

        r = post(self.client, 'questions.watch',
                 {'email': '*****@*****.**', 'event_type': 'reply'},
                 args=[self.question.id])
        assert not QuestionReplyEvent.is_notifying(
            '*****@*****.**', self.question), 'Watch was created'
        self.assertContains(r, 'Could not send a message to that email')
示例#16
0
    def test_watch_replies_smtp_error(self, emailmessage_send):
        """Watch a question for replies and fail to send email."""
        emailmessage_send.side_effect = emailmessage_raise_smtp
        self.client.logout()

        r = post(self.client,
                 'questions.watch', {
                     'email': '*****@*****.**',
                     'event_type': 'reply'
                 },
                 args=[self.question.id])
        assert not QuestionReplyEvent.is_notifying(
            '*****@*****.**', self.question), 'Watch was created'
        self.assertContains(r, 'Could not send a message to that email')
示例#17
0
    def test_watch_replies(self, get_current):
        """Watch a question for replies."""
        get_current.return_value.domain = "testserver"
        self.client.logout()

        post(self.client, "questions.watch", {"email": "*****@*****.**", "event_type": "reply"}, args=[self.question.id])
        assert QuestionReplyEvent.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 "New answers" 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
示例#18
0
    def test_watch_replies(self, get_current):
        """Watch a question for replies."""
        get_current.return_value.domain = 'testserver'
        self.client.logout()

        post(self.client, 'questions.watch',
             {'email': '*****@*****.**', 'event_type': 'reply'},
             args=[self.question.id])
        assert QuestionReplyEvent.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 'New answers' 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
示例#19
0
    def test_watch_replies(self, get_current):
        """Watch a question for replies."""
        get_current.return_value.domain = 'testserver'
        self.client.logout()

        post(self.client, 'questions.watch',
             {'email': '*****@*****.**', 'event_type': 'reply'},
             args=[self.question.id])
        assert QuestionReplyEvent.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 'New answers' 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
示例#20
0
 def test_watch_replies_logged_in(self):
     """Watch a question for replies (logged in)."""
     self.client.login(username="******", password="******")
     user = User.objects.get(username="******")
     post(self.client, "questions.watch", {"event_type": "reply"}, args=[self.question.id])
     assert QuestionReplyEvent.is_notifying(user, self.question), "Watch was not created"