コード例 #1
0
def test_react_to_post_create_reaction_for_the_post(users_data, posts_data):
    # Arrange
    user_id = 4
    post_id = 2
    reaction_type = "HAHA"
    # Act
    react_to_post(user_id, post_id, reaction_type)

    # Assert
    react = Reaction.objects.get(id=1)
    assert react.reaction == reaction_type
    assert react.reacted_by_id == user_id
    assert react.post_id == post_id
コード例 #2
0
def api_wrapper(*args, **kwargs):
    user = kwargs['user']
    post_id = kwargs['post_id']
    request_data = kwargs['request_data']
    reaction_type = request_data['reaction_type']

    try:
        react_to_post(user_id=user.id,
                      post_id=post_id,
                      reaction_type=reaction_type)
    except InvalidReactionTypeException:
        raise BadRequest(*INVALID_REACTION_TYPE)
    except InvalidPostException:
        raise BadRequest(*INVALID_POST)

    return HttpResponse(status=200)
コード例 #3
0
def test_react_to_post_for_the_second_time_with_same_reaction_type_deletes_reaction(
        users_data, posts_data, comments_data, reactions_data):
    # Arrange
    user_id = 3
    post_id = 2
    reaction_type = "ANGRY"
    false = False

    # Act
    react_to_post(user_id=user_id,
                  post_id=post_id,
                  reaction_type=reaction_type)

    # Assert
    assert Reaction.objects.filter(reacted_by_id=user_id,
                                   post_id=post_id,
                                   reaction=reaction_type).exists() == false
コード例 #4
0
def get_react_to_post_view(request, post_id):
    request_serializer = ReacttoPostRequestSerializer(data=request.data)
    is_valid_data = request_serializer.is_valid()
    if is_valid_data:
        request_object = request_serializer.save()
        try:
            react_to_post(
                user_id=request_object.user_id,
                post_id=post_id,
                reaction_type=request_object.reaction_type
            )
        except InvalidUserException:
            return Response(status=404)
        except InvalidPostException:
            return Response(status=404)
        except InvalidReactionTypeException:
            return Response(status=400)
        return Response(status=200)
コード例 #5
0
def test_react_to_post_for_the_second_time_with_another_reaction_type_updates_reaction(
        users_data, posts_data, comments_data, reactions_data, reactions_type):
    # Arrange
    user_id = 1
    post_id = 1
    reaction_type = reactions_type

    # Act
    react_to_post(user_id=user_id,
                  post_id=post_id,
                  reaction_type=reaction_type)

    # Assert
    reaction = Reaction.objects.get(reacted_by_id=user_id,
                                    post_id=post_id,
                                    reaction=reaction_type)
    assert reaction.reaction == reaction_type
    assert reaction.reacted_by_id == user_id
    assert reaction.post_id == post_id
コード例 #6
0
def test_react_to_post_with_invalid_post_returns_exception(user):
    # Arrange
    post_id = 1
    reaction_type = "ANGRY"

    # Act
    with pytest.raises(InvalidPostException):
        assert react_to_post(user_id=user.id,
                             post_id=post_id,
                             reaction_type=reaction_type)
コード例 #7
0
def test_react_to_post_with_invalid_reaction_type_returns_exception(
        user, user2, post):
    # Arrange
    user_id = 2
    post_id = 1
    reaction_type = "SMILE"

    # Act
    with pytest.raises(InvalidReactionTypeException):
        assert react_to_post(user_id=user_id,
                             post_id=post_id,
                             reaction_type=reaction_type)