示例#1
0
def test_get_response_for_get_post_reactions_given_reaction_dtos_returns_dict(
        user_dtos,
        post_reaction_dtos):
    user_dtos = user_dtos
    reactions_dtos = post_reaction_dtos
    post_reaction_dto = PostReactionDto(user_dtos=user_dtos,
                                        reaction_dtos=reactions_dtos)
    json_presenter = PresenterImplementation()
    expected_post_reactions = [
        {
            "user_id": 1,
            "user_name": "James",
            "profile_pic": " ",
            "reaction_type": ReactionType.LIKE.value
        }
    ]

    post_reactions = json_presenter.get_response_for_get_post_reactions(
        post_reactions_dto=post_reaction_dto
    )

    index = 0
    for user in post_reactions:
        assert user["user_id"] == expected_post_reactions[index]["user_id"]
        assert user["reaction_type"] == expected_post_reactions[index][
            "reaction_type"]
        index += 1
示例#2
0
def test_get_response_for_create_post_given_post_id_returns_post_id_dict():
    post_id = 1
    expected_post_id_dict = {"post_id": post_id}
    json_presenter = PresenterImplementation()

    post_id_dict = json_presenter.get_create_post_response(post_id=post_id)

    assert post_id_dict == expected_post_id_dict
示例#3
0
def test_get_response_for_user_reacted_posts_given_post_ids_returns_post_ids_dict(
):
    post_ids = [1, 2, 3]
    expected_post_ids_dict = {"post_ids": post_ids}
    json_presenter = PresenterImplementation()

    post_ids_dict = json_presenter.get_response_for_user_reacted_posts(
        post_ids=post_ids)

    assert expected_post_ids_dict == post_ids_dict
示例#4
0
def test_get_response_for_create_comment_given_comment_id_returns_comment_dict(
):
    json_presenter = PresenterImplementation()
    comment_id = 1
    expected_comment_id_dict = {"comment_id": comment_id}

    comment_id_dict = json_presenter.get_create_comment_response(
        comment_id=comment_id)

    assert comment_id_dict == expected_comment_id_dict
示例#5
0
def test_get_response_for_invalid_comment_id_method_raises_exception():
    json_presenter = PresenterImplementation()
    exception_message = INVALID_COMMENT_ID[0]
    exception_res_status = INVALID_COMMENT_ID[1]

    with pytest.raises(NotFound) as exception:
        json_presenter.raise_exception_for_invalid_comment_id()

    assert exception.value.message == exception_message
    assert exception.value.res_status == exception_res_status
示例#6
0
def test_get_total_reactions_count_method_given_reactions_count_returns_reactions_count_dict(
):
    json_presenter = PresenterImplementation()
    reactions_count = 6
    expected_reactions_count = {"reactions_count": reactions_count}

    reactions_count_dict = json_presenter.get_response_for_get_total_reactions_count(
        reactions_count=reactions_count)

    assert reactions_count_dict == expected_reactions_count
def test_get_response_for_get_posts_with_more_positive_reaction_given_list_of_post_ids_returns_post_ids_dict(
):
    json_presenter = PresenterImplementation()
    post_ids = [1, 2, 3]
    expected_post_ids_dict = {"post_ids": post_ids}

    actual_post_ids_dict = json_presenter.get_response_for_get_posts_with_more_positive_reaction(
        post_ids=post_ids)

    assert expected_post_ids_dict == actual_post_ids_dict
def test_raise_exception_for_invalid_access():
    json_presenter = PresenterImplementation()

    exception_message = INVALID_ACCESS[0]
    exception_res_status = INVALID_ACCESS[1]

    with pytest.raises(Forbidden) as exception:
        json_presenter.raise_exception_for_invalid_access()

    assert exception.value.message == exception_message
    assert exception.value.res_status == exception_res_status
def test_get_response_for_get_reaction_metrics_of_a_post_method_given_reaction_metrics_dto_returns_reaction_metrics(
):
    reaction_metrics_dtos = [
        ReactionMetricsDto(reaction_type=ReactionType.WOW.value,
                           reaction_count=3)
    ]

    json_presenter = PresenterImplementation()
    expected_reaction_metrics = [{"reaction_type": "WOW", "reaction_count": 3}]

    reaction_metrics = json_presenter.get_response_for_get_reaction_metrics_of_a_post(
        reaction_metrics_details_dto=reaction_metrics_dtos)

    assert reaction_metrics == expected_reaction_metrics
示例#10
0
def test_get_response_for_get_post_details_given_get_post_dto_returns_post_details(
        user_dtos, reaction_dtos, comment_dtos, post_dto, get_post_response):
    post_details_dto = PostCompleteDetailsDto(post_dto=post_dto,
                                              users_dto=user_dtos,
                                              reactions_dto=reaction_dtos,
                                              comments_dto=comment_dtos)

    expected_output = get_post_response

    presenter = PresenterImplementation()
    result = presenter.get_response_for_get_post_details(post_details_dto)

    assert result["post_id"] == expected_output["post_id"]
    assert result["posted_by"] == expected_output["posted_by"]
    assert result["reactions"] == expected_output["reactions"]
    assert result["comments"] == expected_output["comments"]
    assert result["comments_count"] == expected_output["comments_count"]
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)
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
示例#13
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 = 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)
示例#16
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)
示例#17
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)
示例#18
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)
def test_get_response_for_get_comment_replies_given_replied_dto_returns_replies_dict(
        user_dtos, replies_dtos):
    comment_replies_dtos = CommentRepliesDto(users_dto=user_dtos,
                                             comments_dto=replies_dtos)

    expected_replies_dict = [{
        "comment_id": 3,
        "commenter": {
            "user_id": 1,
            "user_name": "John",
            "profile_pic_url": " "
        },
        "commented_at": '04-22-2019,00:00:1555871400.000000',
        "comment_content": "nice"
    }]
    json_presenter = PresenterImplementation()

    replies_dict = json_presenter.get_response_for_get_comment_replies(
        comment_replies_dto=comment_replies_dtos)

    assert replies_dict == expected_replies_dict
示例#20
0
def test_get_response_for_get_user_posts_given_user_posts_dtos_returns_user_posts(
        user_dtos, reaction_dtos, comment_dtos, post_dtos,
        get_user_posts_response):
    user_posts_dto = GetUserPostsDto(post_dto=post_dtos,
                                     users_dto=user_dtos,
                                     reactions_dto=reaction_dtos,
                                     comments_dto=comment_dtos)

    expected_output = get_user_posts_response

    presenter = PresenterImplementation()
    result = presenter.get_response_for_get_user_posts(
        user_posts_dto=user_posts_dto)
    for user_post in range(0, len(result), 1):
        assert result[user_post]["post_id"] == expected_output[user_post][
            "post_id"]
        assert result[user_post]["posted_by"] == expected_output[user_post][
            "posted_by"]
        assert result[user_post]["reactions"] == expected_output[user_post][
            "reactions"]
        assert result[user_post]["comments"] == expected_output[user_post][
            "comments"]
示例#21
0
def api_wrapper(*args, **kwargs):
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = ReactToPostInteractor(storage=storage)
    user = kwargs['user']
    user_id = user.id
    post_id = kwargs['post_id']
    request_data = kwargs['validation_output']['some_key']
    reaction_type = request_data['reaction_type']

    interactor.react_to_post_wrapper(user_id=user_id,
                                     post_id=post_id,
                                     reaction_type=reaction_type,
                                     presenter=presenter)

    return HttpResponse(status=201)
def api_wrapper(*args, **kwargs):
    request_data = kwargs['request_data']
    post_id = request_data['post_id']
    comment_text = request_data['comment_text']
    user = kwargs['user']
    user_id = user.id
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = CreateCommentInteractor(storage=storage)

    comment_id_dict = interactor.create_comment(post_id=post_id,
                                                comment_text=comment_text,
                                                user_id=user_id,
                                                presenter=presenter)

    response_data = json.dumps(comment_id_dict)
    return HttpResponse(response_data, status=201)
示例#23
0
def api_wrapper(*args, **kwargs):
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = ReactToCommentInteractor()
    user = kwargs['user']
    user_id = user.id
    comment_id = kwargs['comment_id']
    request_data = kwargs['validation_output']['some_key']
    reaction_type = request_data['reaction_type']

    interactor.get_create_comment_response(user_id=user_id,
                                           comment_id=comment_id,
                                           reaction_type=reaction_type,
                                           presenter=presenter,
                                           storage=storage)

    return HttpResponse(status=201)
示例#24
0
def api_wrapper(*args, **kwargs):
    user = kwargs['user']
    request_data = kwargs['request_data']
    post_content = request_data['post_content']
    user_id = user.id

    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = CreatePostInteractor(storage=storage)

    post_id_dict = interactor.create_post(user_id=user_id,
                                          post_content=post_content,
                                          presenter=presenter)

    response_data = json.dumps(post_id_dict)

    return HttpResponse(response_data, status=201)
示例#25
0
def api_wrapper(*args, **kwargs):
    storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = ReplyToACommentInteractor(storage=storage)
    user = kwargs['user']
    user_id = user.id
    comment_id = kwargs['comment_id']
    request_data = kwargs['validation_output']['some_key']
    comment_text = request_data['comment_text']

    comment_id_dict = interactor.get_response_for_reply_to_a_comment(
        comment_id=comment_id,
        reply_user_id=user_id,
        reply_text=comment_text,
        presenter=presenter)

    response_data = json.dumps(comment_id_dict)

    return HttpResponse(response_data, status=201)
示例#26
0
 def create_post_wrapper(self, user_id: int,
                         post_content: str,
                         presenter: PresenterImplementation):
     post_id = self.create_post(user_id=user_id,
                                post_content=post_content)
     return presenter.get_create_post_response(post_id=post_id)