コード例 #1
0
 def test_dislikedit_cancels_likedit(self):
     if django.VERSION < (1, 5):
         return
     comment = django_comments_tree.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     like_url = reverse("comments-tree-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 = TreeCommentFlag.objects.filter(comment=comment,
                                            user=self.user,
                                            flag=LIKEDIT_FLAG)
     self.assertEqual(flags.count(), 1, f"Expected value to be 1")
     # Now we liked the comment again to cancel the flag.
     dislike_url = reverse("comments-tree-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 = TreeCommentFlag.objects.filter(comment=comment,
                                            user=self.user,
                                            flag=LIKEDIT_FLAG)
     self.assertEqual(flags.count(), 0, f"Expected value to be 0")
     flags = TreeCommentFlag.objects.filter(comment=comment,
                                            user=self.user,
                                            flag=DISLIKEDIT_FLAG)
     self.assertEqual(flags.count(), 1, f"Expected value to be 1")
コード例 #2
0
 def test_loggedin_user_can_dislike(self):
     if django.VERSION < (1, 5):
         return
     comment = django_comments_tree.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     dislike_url = reverse("comments-tree-dislike", args=[comment.id])
     request = request_factory.get(dislike_url)
     request.user = self.user
     response = views.dislike(request, comment.id)
     self.assertEqual(response.status_code, 200)
     self.assertTrue(response.content.find(b'value="I dislike it"') > -1)
     request = request_factory.post(dislike_url)
     request.user = self.user
     request._dont_enforce_csrf_checks = True
     response = views.dislike(request, comment.id)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url,
                      reverse("comments-tree-dislike-done") + "?c=2")
     flags = TreeCommentFlag.objects.filter(comment=comment,
                                            user=self.user,
                                            flag=DISLIKEDIT_FLAG)
     self.assertEqual(flags.count(), 1, f"Expected value to be 1")
コード例 #3
0
 def test_anonymous_user_is_redirected(self):
     comment = django_comments_tree.get_model()\
                              .objects.for_app_models('tests.diary')[0]
     # Like it.
     like_url = reverse("comments-tree-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/2/'
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url, dest_url)
     # Dislike it.
     dislike_url = reverse("comments-tree-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/2/'
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url, dest_url)