def test_success_reaction_karma_neutral(self): author = ProfileFactory() reaction = ContentReactionFactory(author=author.user, position=1, related_content=self.content) profile = ProfileFactory() vote = CommentVote(user=profile.user, comment=reaction, positive=True) vote.save() self.assertTrue(CommentVote.objects.filter(pk=vote.pk).exists()) self.client.force_login(profile.user) response = self.client.put(reverse("api:content:reaction-karma", args=(reaction.pk,)), {"vote": "neutral"}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertFalse(CommentVote.objects.filter(pk=vote.pk).exists())
def test_success_reaction_karma_neutral(self): author = ProfileFactory() reaction = ContentReactionFactory(author=author.user, position=1, related_content=self.content) profile = ProfileFactory() vote = CommentVote(user=profile.user, comment=reaction, positive=True) vote.save() self.assertTrue(CommentVote.objects.filter(pk=vote.pk).exists()) self.assertTrue(self.client.login(username=profile.user.username, password='******')) response = self.client.put(reverse('api:content:reaction-karma', args=(reaction.pk,)), {'vote': 'neutral'}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertFalse(CommentVote.objects.filter(pk=vote.pk).exists())
def test_success_post_karma_neutral(self): profile = ProfileFactory() category, forum = create_category_and_forum() topic = create_topic_in_forum(forum, profile) another_profile = ProfileFactory() post = PostFactory(topic=topic, author=another_profile.user, position=2) vote = CommentVote(user=profile.user, comment=post, positive=True) vote.save() self.assertTrue(CommentVote.objects.filter(pk=vote.pk).exists()) self.assertTrue(self.client.login(username=profile.user.username, password='******')) response = self.client.put(reverse('api:forum:post-karma', args=(post.pk,)), {'vote': 'neutral'}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertFalse(CommentVote.objects.filter(pk=vote.pk).exists())
def test_success_reaction_karma_like_already_disliked(self): author = ProfileFactory() reaction = ContentReactionFactory(author=author.user, position=1, related_content=self.content) profile = ProfileFactory() vote = CommentVote(user=profile.user, comment=reaction, positive=False) vote.save() self.client.force_login(profile.user) response = self.client.put(reverse("api:content:reaction-karma", args=(reaction.pk,)), {"vote": "like"}) vote.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(vote.positive)
def test_success_reaction_karma_like_already_disliked(self): author = ProfileFactory() reaction = ContentReactionFactory(author=author.user, position=1, related_content=self.content) profile = ProfileFactory() vote = CommentVote(user=profile.user, comment=reaction, positive=False) vote.save() self.assertTrue(self.client.login(username=profile.user.username, password='******')) response = self.client.put(reverse('api:content:reaction-karma', args=(reaction.pk,)), {'vote': 'like'}) vote.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(vote.positive)
def test_success_post_karma_like_already_disliked(self): profile = ProfileFactory() category, forum = create_category_and_forum() topic = create_topic_in_forum(forum, profile) another_profile = ProfileFactory() post = PostFactory(topic=topic, author=another_profile.user, position=2) vote = CommentVote(user=profile.user, comment=post, positive=False) vote.save() self.assertTrue(self.client.login(username=profile.user.username, password='******')) response = self.client.put(reverse('api:forum:post-karma', args=(post.pk,)), {'vote': 'like'}) vote.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(vote.positive)