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)
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')}
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')}
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"), }
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)
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')
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"
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')
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')
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)
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")
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')
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')
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
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
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"