Beispiel #1
0
def test_react_to_comment_create_reaction_for_the_comment(
        users_data, posts_data, comments_data):
    # Arrange
    user_id = 4
    comment_id = 2
    reaction_type = "HAHA"

    # Act
    react_to_comment(user_id, comment_id, reaction_type)

    # Assert
    react = Reaction.objects.get(id=1)
    assert react.reaction == reaction_type
    assert react.reacted_by_id == user_id
    assert react.comment_id == comment_id
Beispiel #2
0
def new_react_to_comment(request, comment_id):
    serializer = CreateReactToCommentRequestSerializer(data=request.data)
    is_serializer_valid = serializer.is_valid()
    if is_serializer_valid:
        request_obj = serializer.save()
        from fb_post.utils import react_to_comment
        try:
            react_to_comment(request_obj.user_id, comment_id,
                             request_obj.reaction_type)
        except InvalidUserException:
            return Response(status=404)
        except InvalidCommentException:
            return Response(status=404)
        return Response(status=201)
    else:
        Response(serializer.errors)
def api_wrapper(*args, **kwargs):
    user = kwargs['user']
    comment_id = kwargs['comment_id']
    request_data = kwargs['request_data']
    reaction_type = request_data['reaction_type']

    try:
        react_to_comment(user_id=user.id,
                         comment_id=comment_id,
                         reaction_type=reaction_type)
    except InvalidReactionTypeException:
        raise BadRequest(*INVALID_REACTION_TYPE)
    except InvalidCommentException:
        raise BadRequest(*INVALID_COMMENT)

    return HttpResponse(status=200)
def get_react_to_comment_view(request, comment_id):
    request_serializer = ReacttoCommentRequestSerializer(data=request.data)
    is_valid_data = request_serializer.is_valid()
    if is_valid_data:
        request_object = request_serializer.save()
        try:
            react_to_comment(user_id=request_object.user_id,
                             comment_id=comment_id,
                             reaction_type=request_object.reaction_type)
        except InvalidUserException:
            return Response(status=404)
        except InvalidCommentException:
            return Response(status=404)
        except InvalidReactionTypeException:
            return Response(status=400)
        return Response(status=200)
Beispiel #5
0
def test_react_to_comment_for_the_second_time_with_same_reaction_type_deletes_reaction(
        users_data, posts_data, comments_data, reactions_data):
    # Arrange
    user_id = 3
    comment_id = 2
    reaction_type = "ANGRY"
    false = False

    # Act
    react_to_comment(user_id=user_id,
                     comment_id=comment_id,
                     reaction_type=reaction_type)

    # Assert
    assert Reaction.objects.filter(reacted_by_id=user_id,
                                   comment_id=comment_id,
                                   reaction=reaction_type).exists() == false
Beispiel #6
0
def test_react_to_comment_for_the_second_time_with_another_reaction_type_updates_reaction(
        users_data, posts_data, comments_data, reactions_data, reactions_type):
    # Arrange
    user_id = 1
    comment_id = 1
    reaction_type = reactions_type

    # Act
    react_to_comment(user_id=user_id,
                     comment_id=comment_id,
                     reaction_type=reaction_type)

    # Assert
    reaction = Reaction.objects.get(reacted_by_id=user_id,
                                    comment_id=comment_id,
                                    reaction=reaction_type)
    assert reaction.reaction == reaction_type
    assert reaction.reacted_by_id == user_id
    assert reaction.comment_id == comment_id
Beispiel #7
0
def test_react_to_comment_with_invalid_user_returns_exception():
    # Arrange
    user_id = 3
    comment_id = 1
    reaction_type = "ANGRY"

    # Act
    with pytest.raises(InvalidUserException):
        assert react_to_comment(user_id=user_id,
                                comment_id=comment_id,
                                reaction_type=reaction_type)
Beispiel #8
0
def test_react_to_comment_with_invalid_reaction_type_returns_exception(
        user, user2, post, comment):
    # Arrange
    user_id = 2
    comment_id = 1
    reaction_type = "BAD"

    # Act
    with pytest.raises(InvalidReactionTypeException):
        assert react_to_comment(user_id=user_id,
                                comment_id=comment_id,
                                reaction_type=reaction_type)