def test_invalid_vote_in_comment(self, rf, conversation, comment): request = rf.post("", {"action": "vote", "vote": "INVALID", "comment_id": comment.id}) user = User.objects.create_user("*****@*****.**", "password") conversation = comment conversation.save() request.user = user with raises(Exception): routes.detail(request, conversation)
def test_vote_in_comment(self, rf, conversation, comment, db): user = User.objects.create_user("*****@*****.**", "password") conversation.comment = comment conversation.save() request = rf.post("", {"action": "vote", "vote": "agree", "comment_id": comment.id}) request.user = user routes.detail(request, conversation) assert votes_counter(comment) == 1
def test_invalid_action_conversation_detail(self, rf, conversation, comment): request = rf.post("", {"action": "invalid"}) user = User.objects.create_user("*****@*****.**", "password") conversation.save() request.user = user response = routes.detail(request, conversation) assert isinstance(response, HttpResponseServerError)
def conversation_detail(request, board, **kwargs): return conversations.detail(request, **kwargs, check=check_board(board))
def test_user_can_add_conversation_as_favorite(self, rf, user, conversation): request = rf.post("", {"action": "favorite"}) request.user = user routes.detail(request, conversation) assert FavoriteConversation.objects.filter(user=user, conversation=conversation).exists()
def test_anonymous_user_cannot_comment(self, rf, conversation): request = rf.post("", {"action": "comment", "content": "test comment"}) request.user = AnonymousUser() with raises(PermissionError): routes.detail(request, conversation)
def test_user_post_invalid_comment(self, rf, conversation): request = rf.post("", {"action": "comment", "content": ""}) user = User.objects.create_user("*****@*****.**", "password") request.user = user response = routes.detail(request, conversation) assert response["conversation"]
def test_user_can_comment(self, rf, conversation): request = rf.post("", {"action": "comment", "content": "test comment"}) user = User.objects.create_user("*****@*****.**", "password") request.user = user routes.detail(request, conversation) assert Comment.objects.filter(author=user)[0].content == "test comment"