Exemplo n.º 1
0
 def test_dislikedit_cancels_likedit(self):
     if django.VERSION < (1, 5):
         return
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     like_url = reverse("comments-xtd-like", args=[comment.id])
     request = request_factory.post(like_url)
     request.user = self.user
     request._dont_enforce_csrf_checks = True
     response = views.like(request, comment.id)
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=self.user,
                                        flag=LIKEDIT_FLAG)
     self.assertTrue(flags.count() == 1)
     # Now we liked the comment again to cancel the flag.
     dislike_url = reverse("comments-xtd-dislike", args=[comment.id])
     request = request_factory.post(dislike_url)
     request.user = self.user
     request._dont_enforce_csrf_checks = True
     response = views.dislike(request, comment.id)
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=self.user,
                                        flag=LIKEDIT_FLAG)
     self.assertTrue(flags.count() == 0)
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=self.user,
                                        flag=DISLIKEDIT_FLAG)
     self.assertTrue(flags.count() == 1)
Exemplo n.º 2
0
 def test_anonymous_user_redirected_when_flagging(self):
     self.client.logout()
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     flag_url = reverse("comments-flag", args=[comment.id])
     response = self.client.get(flag_url, follow=True)
     dest_url = '/accounts/login/?next=/comments/flag/1/'
     self.assertRedirects(response, dest_url)
Exemplo n.º 3
0
 def test_anonymous_user_redirected_when_flagging(self):
     self.client.logout()
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     flag_url = reverse("comments-flag", args=[comment.id])
     response = self.client.get(flag_url, follow=True)
     dest_url = '/accounts/login/?next=/comments/flag/1/'
     self.assertRedirects(response, dest_url)
Exemplo n.º 4
0
 def test_anonymous_user_redirected_when_flagging(self):
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     flag_url = reverse("comments-flag", args=[comment.id])
     request = request_factory.get(flag_url)
     request.user = AnonymousUser()
     response = views.flag(request, comment.id)
     dest_url = '/accounts/login/?next=/comments/flag/1/'
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url, dest_url)
Exemplo n.º 5
0
 def test_moderation_with_registered_user(self):
     User.objects.create_user("bob", "*****@*****.**", "pwd")
     self.client.login(username="******", password="******")
     self.post_valid_data()
     # Moderation class:
     # django_comments_xtd.tests.models.DiaryCommentModerator
     # must trigger an email once comment has passed moderation.
     self.assert_(self.mailer_app1.call_count == 1)
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     self.assert_(comment.is_public is False)
Exemplo n.º 6
0
 def test_moderation_with_registered_user(self):
     user = User.objects.create_user("bob", "*****@*****.**", "pwd")
     self.assertTrue(self.mailer_app1.call_count == 0)
     self.post_valid_data(user)
     # Moderation class:
     # django_comments_xtd.tests.models.DiaryCommentModerator
     # must trigger an email once comment has passed moderation.
     self.assertTrue(self.mailer_app1.call_count == 1)
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     self.assertTrue(comment.is_public is True)
Exemplo n.º 7
0
 def test_anonymous_user_is_redirected(self):
     self.client.logout()
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     like_url = reverse("comments-xtd-like", args=[comment.id])
     response = self.client.get(like_url, follow=True)
     dest_url = '/accounts/login/?next=/comments/like/1/'
     self.assertRedirects(response, dest_url)
     dislike_url = reverse("comments-xtd-dislike", args=[comment.id])
     response = self.client.get(dislike_url, follow=True)
     dest_url = '/accounts/login/?next=/comments/dislike/1/'
     self.assertRedirects(response, dest_url)
Exemplo n.º 8
0
 def test_anonymous_user_is_redirected(self):
     self.client.logout()
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     like_url = reverse("comments-xtd-like", args=[comment.id])
     response = self.client.get(like_url, follow=True)
     dest_url = '/accounts/login/?next=/comments/like/1/'
     self.assertRedirects(response, dest_url)
     dislike_url = reverse("comments-xtd-dislike", args=[comment.id])
     response = self.client.get(dislike_url, follow=True)
     dest_url = '/accounts/login/?next=/comments/dislike/1/'
     self.assertRedirects(response, dest_url)
Exemplo n.º 9
0
 def test_moderation_with_unregistered_user(self):
     self.post_valid_data()
     self.assert_(self.mailer_app1.call_count == 0)
     self.assert_(self.mailer_app2.call_count == 1)
     mail_msg = self.mailer_app2.call_args[0][1]
     key = str(re.search(r'http://.+/confirm/(?P<key>[\S]+)',
                         mail_msg).group("key"))
     self.get_confirm_comment_url(key)
     self.assert_(self.mailer_app1.call_count == 1)
     self.assert_(self.mailer_app2.call_count == 1)
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     self.assert_(comment.is_public is True)
Exemplo n.º 10
0
 def test_loggedin_user_can_flag_comment(self):
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     flag_url = reverse("comments-flag", args=[comment.id])
     response = self.client.get(flag_url)
     self.assertTemplateUsed(response, 'comments/flag.html')
     response = self.client.post(flag_url)
     self.assertRedirects(response, reverse("comments-flag-done") + "?c=1")
     user = User.objects.get(username='******')
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=user,
                                        flag=CommentFlag.SUGGEST_REMOVAL)
     self.assert_(flags.count() == 1)
Exemplo n.º 11
0
 def test_loggedin_user_can_flag_comment(self):
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     flag_url = reverse("comments-flag", args=[comment.id])
     response = self.client.get(flag_url)
     self.assertTemplateUsed(response, 'comments/flag.html')
     response = self.client.post(flag_url)
     self.assertRedirects(response, reverse("comments-flag-done") + "?c=1")
     user = User.objects.get(username='******')
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=user,
                                        flag=CommentFlag.SUGGEST_REMOVAL)
     self.assert_(flags.count() == 1)
Exemplo n.º 12
0
 def test_loggedin_user_can_dislike(self):
     if django.VERSION < (1, 5):
         return
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     dislike_url = reverse("comments-xtd-dislike", args=[comment.id])
     response = self.client.get(dislike_url)
     self.assertTemplateUsed(response, 'django_comments_xtd/dislike.html')
     response = self.client.post(dislike_url)
     self.assertRedirects(response,
                          reverse("comments-xtd-dislike-done") + "?c=1")
     user = User.objects.get(username='******')
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=user,
                                        flag=DISLIKEDIT_FLAG)
     self.assert_(flags.count() == 1)
Exemplo n.º 13
0
 def test_loggedin_user_can_dislike(self):
     if django.VERSION < (1, 5):
         return
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     dislike_url = reverse("comments-xtd-dislike", args=[comment.id])
     response = self.client.get(dislike_url)
     self.assertTemplateUsed(response, 'django_comments_xtd/dislike.html')
     response = self.client.post(dislike_url)
     self.assertRedirects(response,
                          reverse("comments-xtd-dislike-done") + "?c=1")
     user = User.objects.get(username='******')
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=user,
                                        flag=DISLIKEDIT_FLAG)
     self.assert_(flags.count() == 1)
Exemplo n.º 14
0
 def test_dislikedit_can_be_cancelled(self):
     if django.VERSION < (1, 5):
         return
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     dislike_url = reverse("comments-xtd-dislike", args=[comment.id])
     self.client.post(dislike_url, follow=True)
     user = User.objects.get(username='******')
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=user,
                                        flag=DISLIKEDIT_FLAG)
     self.assert_(flags.count() == 1)
     # Now we liked the comment again to cancel the flag.
     self.client.post(dislike_url)
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=user,
                                        flag=DISLIKEDIT_FLAG)
     self.assert_(flags.count() == 0)
Exemplo n.º 15
0
 def test_dislikedit_can_be_cancelled(self):
     if django.VERSION < (1, 5):
         return
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     dislike_url = reverse("comments-xtd-dislike", args=[comment.id])
     self.client.post(dislike_url, follow=True)
     user = User.objects.get(username='******')
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=user,
                                        flag=DISLIKEDIT_FLAG)
     self.assert_(flags.count() == 1)
     # Now we liked the comment again to cancel the flag.
     self.client.post(dislike_url)
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=user,
                                        flag=DISLIKEDIT_FLAG)
     self.assert_(flags.count() == 0)
Exemplo n.º 16
0
 def test_anonymous_user_is_redirected(self):
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     # Like it.
     like_url = reverse("comments-xtd-like", args=[comment.id])
     request = request_factory.get(like_url)
     request.user = AnonymousUser()
     response = views.like(request, comment.id)
     dest_url = '/accounts/login/?next=/comments/like/1/'
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url, dest_url)
     # Dislike it.
     dislike_url = reverse("comments-xtd-dislike", args=[comment.id])
     request = request_factory.get(dislike_url)
     request.user = AnonymousUser()
     response = views.dislike(request, comment.id)
     dest_url = '/accounts/login/?next=/comments/dislike/1/'
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url, dest_url)
Exemplo n.º 17
0
 def test_loggedin_user_can_flag_comment(self):
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     flag_url = reverse("comments-flag", args=[comment.id])
     request = request_factory.get(flag_url)
     request.user = self.user
     response = views.flag(request, comment.id)
     self.assertEqual(response.status_code, 200)
     self.assertTrue(response.content.find(b'Flag comment') > -1)
     request = request_factory.post(flag_url)
     request.user = self.user
     request._dont_enforce_csrf_checks = True
     response = views.flag(request, comment.id)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url, reverse("comments-flag-done") + "?c=1")
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=self.user,
                                        flag=CommentFlag.SUGGEST_REMOVAL)
     self.assertTrue(flags.count() == 1)
Exemplo n.º 18
0
 def test_loggedin_user_can_like(self):
     if django.VERSION < (1, 5):
         return
     comment = django_comments.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     like_url = reverse("comments-xtd-like", args=[comment.id])
     request = request_factory.get(like_url)
     request.user = self.user
     response = views.like(request, comment.id)
     self.assertEqual(response.status_code, 200)
     self.assertTrue(response.content.find(b'value="I like it"') > -1)
     request = request_factory.post(like_url)
     request.user = self.user
     request._dont_enforce_csrf_checks = True
     response = views.like(request, comment.id)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url, reverse("comments-xtd-like-done") + "?c=1")
     flags = CommentFlag.objects.filter(comment=comment,
                                        user=self.user,
                                        flag=LIKEDIT_FLAG)
     self.assert_(flags.count() == 1)