Exemplo n.º 1
0
    def test_get_replies_to_comment(self):

        user_one_dto = UserDTO(user_id=1,
                               name='user_1',
                               profile_pic_url='https://user_1.png')
        user_two_dto = UserDTO(user_id=2,
                               name='user_2',
                               profile_pic_url='https://user_2.png')
        reply_one_dto = RepliesDTO(comment_id=1,
                                   user=user_one_dto,
                                   commented_at=datetime.now(),
                                   comment_content="This is first reply")
        reply_two_dto = RepliesDTO(comment_id=2,
                                   user=user_two_dto,
                                   commented_at=datetime.now(),
                                   comment_content="This is second reply")
        replies_dto_list = [reply_one_dto, reply_two_dto]

        json_presenter = JsonPresenterImpl()
        response = json_presenter.get_comment_replies_response(
            replies_dto_list)

        reply_one_data = None
        for reply in response:
            if reply['comment_id'] == reply_one_dto.comment_id:
                reply_one_data = reply

        assert reply_one_data['commenter']['user_id'] == user_one_dto.user_id
        assert reply_one_data['commenter']['name'] == user_one_dto.name
        assert reply_one_data['commenter']['profile_pic_url'] == user_one_dto\
            .profile_pic_url
        assert reply_one_data['commented_at'] == reply_one_dto.commented_at\
            .strftime('%y-%m-%d %H:%M:%S.%f')
        assert reply_one_data['comment_content'] == reply_one_dto\
            .comment_content

        reply_two_data = None
        for reply in response:
            if reply['comment_id'] == reply_two_dto.comment_id:
                reply_two_data = reply

        assert reply_two_data['commenter']['user_id'] == user_two_dto.user_id
        assert reply_two_data['commenter']['name'] == user_two_dto.name
        assert reply_two_data['commenter']['profile_pic_url'] == user_two_dto\
            .profile_pic_url
        assert reply_two_data['commented_at'] == reply_two_dto.commented_at\
            .strftime('%y-%m-%d %H:%M:%S.%f')
        assert reply_two_data['comment_content'] == reply_two_dto\
            .comment_content
    def test_comment_replies(self):
        presenter = Presenter()
        user = UserDTO(user_id=1, username="******", profile_pic="")
        reply_1 = ReplyDTO(comment_id=1,
                           user=user,
                           comment_content="first reply",
                           comment_create_date=datetime.now())

        reply_2 = ReplyDTO(comment_id=2,
                           user=user,
                           comment_content="second reply",
                           comment_create_date=datetime.now())

        replies = [reply_1, reply_2]

        response = presenter.get_comment_replies_response(replies)

        assert len(response["replies"]) == len(replies)

        reply_ids = [reply["comment_id"] for reply in response["replies"]]

        assert reply_1.comment_id in reply_ids
        assert reply_2.comment_id in reply_ids

        test_reply = {}
        for reply in response["replies"]:
            if reply["comment_id"] == reply_1.comment_id:
                test_reply = reply

        assert test_reply["commenter"]["userid"] == user.user_id
        assert test_reply["commenter"]["username"] == user.username
        assert test_reply["comment_message"] == reply_1.comment_content
        assert test_reply["comment_create_date"] == datetime.now().strftime(
            "%Y-%m-%d %H:%M:%S")
    def test_get_comment_response_with_out_replies(self):

        user_dto = UserDTO(user_id=1,
                           name='user_1',
                           profile_pic_url='https://user_1.png')
        comment_reactions_dto = ReactionStatsDTO(count=3,
                                                 type=["LOVE", "LIKE"])
        comment_dto = CommentDetailsDTO(
            comment_id=1,
            user=user_dto,
            commented_at=datetime.datetime.now(),
            comment_content="This is a comment",
            comment_reactions=comment_reactions_dto)

        json_presenter = JsonPresenterImpl()
        response = json_presenter\
            .convert_comment_with_out_replies_dto_to_dict(comment_dto)

        assert response['comment_id'] == comment_dto.comment_id
        assert response['commenter']['user_id'] == user_dto.user_id
        assert response['commenter']['name'] == user_dto.name
        assert response['commenter']['profile_pic_url'] == user_dto\
            .profile_pic_url
        assert response['commented_at'] == comment_dto.commented_at\
            .strftime('%y-%m-%d %H:%M:%S.%f')
        assert response['comment_content'] == comment_dto.comment_content
        assert response['reactions']['count'] == comment_reactions_dto.count
        assert response['reactions']['type'] == comment_reactions_dto.type
Exemplo n.º 4
0
 def convert_reply_object_to_reply_dto(reply):
     user_dto = UserDTO(user_id=reply.user_id, name=reply.user.username,
                        profile_pic_url=reply.user.profile_pic_url)
     reply_dto = RepliesDTO(comment_id=reply.id, user=user_dto,
                            commented_at=reply.commented_time,
                            comment_content=reply.comment_text)
     return reply_dto
    def setup_data(self):
        user = UserDTO(user_id=1, username='******', profile_pic="")
        post = PostDTO(id=1, post_content="first post",
                       post_create_date=datetime.now())
        post_reaction = ReactionStatsDTO(count=2, types=["LOVE", "LIKE"])
        comments = []
        comment_count = 0

        self.get_post_dto = GetPostDTO(post, user, post_reaction, comments,
                                       comment_count)
    def test_get_user_response(self):

        user_dto = UserDTO(user_id=1,
                           name='user_1',
                           profile_pic_url='https://user_1.png')

        json_presenter = JsonPresenterImpl()
        response = json_presenter.convert_user_dto_to_dict(user_dto)

        assert response['user_id'] == user_dto.user_id
        assert response['name'] == user_dto.name
        assert response['profile_pic_url'] == user_dto.profile_pic_url
    def test_get_comment_response_with_replies(self):

        user_dto = UserDTO(user_id=1,
                           name='user_1',
                           profile_pic_url='https://user_1.png')
        comment_reactions_dto = ReactionStatsDTO(count=2, type=["SAD", "LIKE"])
        reply_reactions_dto = ReactionStatsDTO(count=3, type=["LOVE", "LIKE"])
        reply_dto = CommentDetailsDTO(comment_id=2,
                                      user=user_dto,
                                      commented_at=datetime.datetime.now(),
                                      comment_content="This is a reply",
                                      comment_reactions=reply_reactions_dto)
        comment_dto = CommentDetailsWithRepliesDTO(
            comment_id=1,
            user=user_dto,
            commented_at=datetime.datetime.now(),
            comment_content="This is a comment",
            comment_reactions=comment_reactions_dto,
            replies=[reply_dto],
            replies_count=1)

        json_presenter = JsonPresenterImpl()
        response = json_presenter\
            .convert_comment_with_replies_dto_to_dict(comment_dto)

        assert response['comment_id'] == comment_dto.comment_id
        assert response['commenter']['user_id'] == user_dto.user_id
        assert response['commenter']['name'] == user_dto.name
        assert response['commenter']['profile_pic_url'] == user_dto\
            .profile_pic_url
        assert response['commented_at'] == comment_dto.commented_at\
            .strftime('%y-%m-%d %H:%M:%S.%f')
        assert response['comment_content'] == comment_dto.comment_content
        assert response['reactions']['count'] == comment_reactions_dto.count
        assert response['reactions']['type'] == comment_reactions_dto.type
        assert response['replies_count'] == 1

        reply_data = None
        for reply in response["replies"]:
            if reply["comment_id"] == reply_dto.comment_id:
                reply_data = reply

        assert reply_data['comment_id'] == reply_dto.comment_id
        assert reply_data['commenter']['user_id'] == user_dto.user_id
        assert reply_data['commenter']['name'] == user_dto.name
        assert reply_data['commenter'][
            'profile_pic_url'] == user_dto.profile_pic_url
        assert reply_data['commented_at'] == reply_dto\
            .commented_at.strftime('%y-%m-%d %H:%M:%S.%f')
        assert reply_data['comment_content'] == reply_dto.comment_content
        assert reply_data['reactions']['count'] == reply_reactions_dto.count
        assert reply_data['reactions']['type'] == reply_reactions_dto.type
Exemplo n.º 8
0
    def get_all_users_dto_list(post_id, post_user_id):
        all_user_ids = list(Comment.objects.filter(post_id=post_id)
                            .values_list('user', flat=True))
        all_user_ids.append(post_user_id)
        all_user_ids = list(set(all_user_ids))

        users = User.objects.filter(id__in=all_user_ids)

        user_dto_list = []
        for user in users:
            user_dto = UserDTO(user.id, user.username, user.profile_pic_url)
            user_dto_list.append(user_dto)

        return user_dto_list
Exemplo n.º 9
0
    def get_all_user_dtos_list(post_id, post_user_id):
        all_user_ids = [post_user_id]
        comment_users = Comment.objects.filter(post_id=post_id).values_list(
            'user', flat=True)
        all_user_ids.extend(comment_users)
        all_user_ids = list(set(all_user_ids))

        users = User.objects.filter(id__in=all_user_ids)

        users_dtos = []
        for user in users:
            users_dtos.append(
                UserDTO(user_id=user.id,
                        username=user.username,
                        profile_pic=user.profile_pic))

        return users_dtos
    def setup_get_post_dto(self):
        post_dto = PostDTO(post_id=1,
                           user_id=1,
                           post_content='1',
                           created_time=datetime.datetime.now())
        posted_user_dto = UserDTO(user_id=1,
                                  name='user_1',
                                  profile_pic_url='profile_pic')
        post_reaction_dto = ReactionStatsDTO(count=1, type=['HAHA'])
        comments_dto_list = []
        comments_count = 2

        get_post_dto = GetPostDTO(post_details=post_dto,
                                  posted_by=posted_user_dto,
                                  post_reaction_data=post_reaction_dto,
                                  comments=comments_dto_list,
                                  comments_count=comments_count)

        return get_post_dto
Exemplo n.º 11
0
    def get_comment_replies(self, comment_id: int, offset: int, limit: int) -> \
            List[ReplyDTO]:

        replies = Comment.objects.filter(
            commented_on_id=comment_id)[offset:offset + limit]

        replies_list = []
        for reply in replies:
            userdto = UserDTO(user_id=reply.user_id,
                              username=reply.user.username,
                              profile_pic=reply.user.profile_pic)

            replies_dto = ReplyDTO(comment_id=reply.id,
                                   user=userdto,
                                   comment_content=reply.message,
                                   comment_create_date=tz.localtime(
                                       reply.comment_create_date))

            replies_list.append(replies_dto)

        return replies_list