def test_validate_post_reaction_if_not_exists_raise_exception():
    user_id = 1
    post_id = 1
    sql_storage = StorageImplementation()

    with pytest.raises(ReactionDoesNotExist):
        sql_storage.validate_post_reaction_if_exists_get_reaction_type(
            user_id=user_id, post_id=post_id)
示例#2
0
def test_validate_comment_reaction_given_invalid_details_raises_exception():
    comment_id = 1
    user_id = 1
    sql_storage = StorageImplementation()

    with pytest.raises(ReactionDoesNotExist):
        sql_storage.validate_comment_reaction_if_exists_get_reaction_type(
            comment_id=comment_id, user_id=user_id)
示例#3
0
def test_get_total_reactions_count(create_post, create_comments,
                                   create_post_reactions,
                                   create_comment_reactions):
    sql_storage = StorageImplementation()
    expected_reactions_count = 2

    reaction_count = sql_storage.get_total_reactions_count()

    assert reaction_count == expected_reactions_count
def test_get_user_reacted_posts_given_user_id_returns_list_of_post_ids(
        create_users, create_post):
    user_id = 1
    expected_post_ids = [1]
    storage = StorageImplementation()

    actual_post_ids = storage.get_user_reacted_posts(user_id=user_id)

    assert actual_post_ids == expected_post_ids
示例#5
0
def test_get_parent_comment_id(create_replies):
    comment_id = 3
    expected_parent_comment_id = 2
    sql_storage = StorageImplementation()

    actual_parent_comment_id = sql_storage.get_parent_comment_id(
        comment_id=comment_id)

    assert actual_parent_comment_id == expected_parent_comment_id
示例#6
0
def test_get_posts_with_more_positive_reaction(create_users, create_post,
                                               create_post_reactions):

    expected_post_ids = [1]
    storage = StorageImplementation()

    post_ids = storage.get_posts_with_more_positive_reactions()

    assert expected_post_ids == post_ids
def test_create_post_and_get_id_method_given_valid_details_returns_post_id():
    user_id = 1
    post_content = "Post Content"
    storage = StorageImplementation()

    post_id = storage.create_post(user_id=user_id, post_content=post_content)

    post = Post.objects.get(id=post_id)

    assert post_id == post.id
示例#8
0
def test_validate_comment_reaction_if_exist_get_reaction_type(
        create_users, create_post, create_comments, create_comment_reactions):
    comment_id = 1
    user_id = 1
    sql_storage = StorageImplementation()
    expected_reaction_type = ReactionType.HAHA.value

    reaction_type = sql_storage.validate_comment_reaction_if_exists_get_reaction_type(
        comment_id=comment_id, user_id=user_id)

    assert expected_reaction_type == reaction_type
def test_undo_comment_reaction_given_dup_reaction_type(
        create_post, create_comments, create_comment_reactions):
    user_id = 1
    comment_id = 1
    comment_not_exist = False
    sql_storage = StorageImplementation()

    sql_storage.undo_comment_reaction(user_id=user_id, comment_id=comment_id)
    actual_result = Reactions.objects.filter(user_id=user_id,
                                             comment_id=comment_id).exists()

    assert actual_result == comment_not_exist
示例#10
0
def test_get_comment_replies_dto(create_users, create_post, create_comments,
                                 user_dtos, replies_dtos):
    comment_id = 2
    sql_storage = StorageImplementation()
    user_dtos = user_dtos
    replies_dtos = replies_dtos

    comment_replies_dtos = sql_storage.get_comment_replies_dto(
        comment_id=comment_id)

    assert user_dtos == comment_replies_dtos.users_dto
    assert replies_dtos == comment_replies_dtos.replies_dtos
def test_undo_post_reaction_given_dup_reaction_results_undo_reaction(
        create_post, create_post_reactions):
    user_id = 1
    post_id = 1
    reaction_not_exists = False
    sql_storage = StorageImplementation()

    sql_storage.undo_post_reaction(user_id=user_id, post_id=post_id)

    actual_result = Reactions.objects.filter(user_id=user_id,
                                             post_id=post_id).exists()

    assert actual_result == reaction_not_exists
def test_get_post_reaction_dtos_given_post_id_returns_reactions_dto(
        create_users, create_post, create_post_reactions, user_dtos,
        post_reaction_dtos):

    post_id = 1
    user_dtos = user_dtos
    reactions_dtos = post_reaction_dtos
    sql_storage = StorageImplementation()

    post_reaction_dtos = sql_storage.get_post_reaction_dtos(post_id=post_id)

    assert user_dtos == post_reaction_dtos.user_dtos
    assert reactions_dtos == post_reaction_dtos.reaction_dtos
def test_reaction_metrics_of_a_post_given_post_id_returns_reaction_metrics():
    post_id = 1
    expected_reaction_metrics_dto = [
        ReactionMetricsDetailsDto(reaction_type=ReactionType.WOW.value,
                                  reaction_count=3)
    ]
    sql_storage = StorageImplementation()

    reaction_metrics_dto = sql_storage.get_reaction_metrics_of_a_post_dto(
        post_id=post_id)

    assert reaction_metrics_dto.reaction_metrics_details_dto == \
           expected_reaction_metrics_dto
示例#14
0
def test_get_user_posts_dto_given_user_id_returns_user_posts_dtos(
        get_user_dtos, post_dtos, comment_dtos, reaction_dtos, user_dtos):
    user_id = 1
    expected_user_post_dtos = GetUserPostDtos(post_dto=post_dtos,
                                              users_dto=user_dtos,
                                              comments_dto=comment_dtos,
                                              reactions_dto=reaction_dtos)
    sql_storage = StorageImplementation()

    user_post_dtos = sql_storage.get_user_posts_dto(user_id=user_id)

    assert user_post_dtos.post_dto == expected_user_post_dtos.post_dto
    assert user_post_dtos.users_dto == expected_user_post_dtos.users_dto
    assert user_post_dtos.comments_dto == expected_user_post_dtos.comments_dto
    assert user_post_dtos.reactions_dto == expected_user_post_dtos.reactions_dto
示例#15
0
def test_create_comment_reaction_given_valid_details_creates_comment(
        create_users, create_post, create_comments):
    user_id = 1
    comment_id = 1
    reaction_type = ReactionType.HAHA.value
    sql_storage = StorageImplementation()

    sql_storage.create_comment_reaction(user_id=user_id,
                                        comment_id=comment_id,
                                        reaction_type=reaction_type)
    reaction = Reactions.objects.get(user_id=user_id, comment_id=comment_id)

    assert reaction.user_id == user_id
    assert reaction.comment_id == comment_id
    assert reaction.reaction_type == reaction_type
def test_update_comment_reaction_given_different_reaction_type(
        create_post, create_comment_reactions):
    user_id = 1
    comment_id = 1
    reaction_type = ReactionType.HAHA.value
    sql_storage = StorageImplementation()

    sql_storage.update_comment_reaction(user_id=user_id,
                                        comment_id=comment_id,
                                        reaction_type=reaction_type)
    reaction = Reactions.objects.get(user_id=user_id,
                                     comment_id=comment_id,
                                     reaction_type=reaction_type)
    assert reaction.user_id == user_id
    assert reaction.comment_id == comment_id
    assert reaction.reaction_type == reaction_type
def test_create_comment_given_valid_details_creates_comment_triangulation(
        create_post):
    user_id = 1
    post_id = 1
    comment_text = "Nice Post"
    storage = StorageImplementation()

    comment_id = storage.create_comment(user_id=user_id,
                                        post_id=post_id,
                                        comment_text=comment_text)

    comment = Comment.objects.get(id=comment_id)
    assert comment.id == comment_id
    assert comment.user_id == user_id
    assert comment.post.id == post_id
    assert comment.comment_text == comment_text
示例#18
0
def test_get_post_details_dto_given_post_id(
        create_post, create_comments, create_replies, create_post_reactions,
        create_comment_reactions, post_dtos, comment_dtos, reaction_dtos):

    post_id = 1
    post_dtos = post_dtos
    user_ids = [1, 2]
    comment_dtos = comment_dtos
    reaction_dtos = reaction_dtos
    sql_storage = StorageImplementation()

    post_details_dtos = sql_storage.get_post_details_dto(post_id=post_id)

    assert post_dtos == post_details_dtos.post_dto
    assert user_ids == post_details_dtos.user_ids
    assert comment_dtos == post_details_dtos.comments_dto
    assert reaction_dtos == post_details_dtos.reactions_dto
示例#19
0
def test_update_post_reaction_given_diff_reaction_updates_reaction(
    create_post,
    create_post_reactions,
):
    user_id = 1
    post_id = 1
    reaction_type = ReactionType.HAHA.value
    sql_storage = StorageImplementation()

    sql_storage.update_post_reaction(user_id=user_id,
                                     post_id=post_id,
                                     reaction_type=reaction_type)
    reaction = Reactions.objects.get(user_id=user_id, post_id=post_id)

    assert reaction.user_id == user_id
    assert reaction.post_id == post_id
    assert reaction.reaction_type == reaction_type
def test_create_comment_reply_given_valid_details_creates_comment(
        create_users, create_post, create_comments):
    comment_id = 1
    reply_user_id = 2
    reply_text = "Nice Post"
    sql_storage = StorageImplementation()

    sql_storage.create_comment_reply(comment_id=comment_id,
                                     reply_user_id=reply_user_id,
                                     reply_text=reply_text)

    comment = Comment.objects.get(parent_comment_id=comment_id,
                                  user_id=reply_user_id)

    assert comment.parent_comment.id == comment_id
    assert comment.user.id == reply_user_id
    assert comment.comment_text == reply_text
def test_create_post_reaction_given_valid_details_creates_post_reaction(
create_post
):
    user_id = 1
    post_id = 1
    reaction_type = ReactionType.HAHA.value
    sql_storage = StorageImplementation()

    sql_storage.create_post_reaction(user_id=user_id,
                                     post_id=post_id,
                                     reaction_type=reaction_type)

    reaction = Reactions.objects.get(user_id=user_id,
                                     post_id=post_id)

    assert reaction.user_id == user_id
    assert reaction.post.id == post_id
    assert reaction.reaction_type == reaction_type
def api_wrapper(*args, **kwargs):
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    comment_id = kwargs['comment_id']
    interactor = GetCommentRepliesInteractor(storage=storage)
    comment_replies = interactor.get_comment_replies_response(
        comment_id=comment_id, presenter=presenter)
    response_data = json.dumps(comment_replies)

    return HttpResponse(response_data, status=200)
示例#23
0
def api_wrapper(*args, **kwargs):
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = GetPostsWithMorePositiveReactionsInteractor(storage=storage)
    post_ids_dict = interactor.get_posts_with_more_positive_reactions_wrapper(
        presenter=presenter)

    response_data = json.dumps(post_ids_dict)

    return HttpResponse(response_data, status=200)
def api_wrapper(*args, **kwargs):
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = PrintHelloWorld(storage=storage)

    hellow_world = interactor.get_print_hello_world(
        presenter=presenter
        )
    response_data = json.dumps(hellow_world)
    return response_data
def api_wrapper(*args, **kwargs):
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = GetTotalReactionsCountInteractor(storage=storage)

    reaction_count_dict = interactor.get_total_reactions_count_response(
        presenter=presenter)
    response_data = json.dumps(reaction_count_dict)

    return HttpResponse(response_data, status=200)
def api_wrapper(*args, **kwargs):
    post_id = kwargs['post_id']
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = GetReactionMetricsOfAPostInteractor(storage=storage)
    reaction_metrics = interactor.get_reaction_metrics_of_a_post_response(
        post_id=post_id, presenter=presenter)
    response_data = json.dumps(reaction_metrics)

    return HttpResponse(response_data, status=200)
示例#27
0
def api_wrapper(*args, **kwargs):
    post_id = kwargs['post_id']
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = GetPostReactionsInteractor(storage=storage)
    post_reactions = interactor.get_post_reactions_wrapper(post_id=post_id,
                                                           presenter=presenter)
    response_data = json.dumps(post_reactions)

    return HttpResponse(response_data, status=200)
def test_validate_post_reaction_if_exists_get_reaction_type(
        create_users, create_post, create_post_reactions):
    user_id = 1
    post_id = 1
    sql_storage = StorageImplementation()

    reaction_type = sql_storage. \
        validate_post_reaction_if_exists_get_reaction_type(user_id=user_id,
                                                           post_id=post_id)

    assert reaction_type == "LIKE"
示例#29
0
def api_wrapper(*args, **kwargs):
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    user = kwargs['user']
    user_id = user.id
    interactor = DeletePostInteractor(storage=storage, presenter=presenter)
    post_id = kwargs['post_id']

    interactor.get_response_for_delete_post(user_id=user_id, post_id=post_id)

    return HttpResponse(status=200)
示例#30
0
def api_wrapper(*args, **kwargs):
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    user = kwargs['user']
    user_id = user.id
    interactor = GetUserReactedPostInteractor(storage=storage)

    user_reacted_posts = interactor.get_response_for_user_reacted_posts(
        user_id=user_id, presenter=presenter)
    response_data = json.dumps(user_reacted_posts)

    return HttpResponse(response_data, status=200)