예제 #1
0
def test_get_user_post_given_post_with_one_comment_with_one_reply_returns_post_details(
    post_with_one_comment_with_one_reply,
    single_comment_post_fields
):
    #Arrange
    user_id = 1
    all_fields = post_with_one_comment_with_one_reply
    post_fields = single_comment_post_fields
    storage = create_autospec(PostStorageInterface)
    presenter = create_autospec(PresenterInterface)
    interactor = GetUserPostsInteractor(storage, presenter)
    get_user_post_dto = UserPostDetailsDto(
        post_dto=post_fields["post_dto"],
        users_dto=all_fields["user_dtos"],
        comments_dto=all_fields["comment_dtos"],
        reactions_dto=all_fields["reaction_dtos"]
    )
    get_user_post_presenter_dto = UserPostsCompleteDto(
        user_post_details_dto = get_user_post_dto,
        post_reactions_dtos=post_fields["post_reactions_dtos"],
        post_comments_count_dtos=post_fields["post_comments_count_dtos"],
        comment_reactions_dtos = all_fields["comment_reaction_metrics_dto"],
        comment_replies_count_dtos = all_fields["comment_replies_count_dtos"]
    )
    storage.get_user_posts.return_value = get_user_post_dto

    #Act
    interactor.get_user_posts_interactor(
        user_id=user_id,
    )

    #Assert
    presenter.get_response_for_user_posts.assert_called_once_with(
        get_user_post_presenter_dto
    )
예제 #2
0
    def get_complete_user_posts_dto(self, user_posts_dto):
        comment_reaction_fields_dtos = []
        replies_count_dtos = []
        posts_dtos = user_posts_dto.post_dto
        reactions_dto = user_posts_dto.reactions_dto
        comments_dto = user_posts_dto.comments_dto
        posts_reactions_dtos = self.get_posts_reactions_dtos(
            posts_dtos, reactions_dto)
        posts_comments_count_dtos = self.get_posts_comments_count_dtos(
            posts_dtos, comments_dto)
        for comment in comments_dto:
            comment_reaction_fields_dtos.append(self.\
             get_comment_reactions_metrics_dto(comment.id, reactions_dto))
            is_comment = not comment.parent_comment_id
            if is_comment:
                replies_count_dtos.append(
                    self.get_reply_count_dto(comment.id, comments_dto))

        post_complete_dto = UserPostsCompleteDto(
            user_post_details_dto=user_posts_dto,
            post_reactions_dtos=posts_reactions_dtos,
            post_comments_count_dtos=posts_comments_count_dtos,
            comment_reactions_dtos=comment_reaction_fields_dtos,
            comment_replies_count_dtos=replies_count_dtos)
        return post_complete_dto