def test_get_comment_reactions(self):

        all_comment_reactions = [{
            'comment_id': 1,
            'reaction_type': "WOW"
        }, {
            'comment_id': 1,
            'reaction_type': "WOW"
        }, {
            'comment_id': 2,
            'reaction_type': "SAD"
        }, {
            'comment_id': 2,
            'reaction_type': "WOW"
        }]

        post_storage_object = PostStorageImpl()
        comment_reactions = post_storage_object.get_comment_wise_reactions(
            all_comment_reactions)

        comment_one_reactions = comment_reactions[1]
        assert comment_one_reactions['count'] == 2
        assert comment_one_reactions['type'] == set(['WOW'])

        comment_two_reactions = comment_reactions[2]
        assert comment_two_reactions['count'] == 2
        assert comment_two_reactions['type'] == set(['WOW', 'SAD'])
    def test_get_all_comment_replies(self):

        all_comment_replies = [{
            "comment_id": 4,
            "commented_on": 1
        }, {
            "comment_id": 5,
            "commented_on": 1
        }, {
            "comment_id": 6,
            "commented_on": 2
        }]

        post_storage_object = PostStorageImpl()
        comment_replies = post_storage_object.get_comment_wise_replies(
            all_comment_replies)

        reply_ids_of_comment_one = [
            replies['comment_id'] for replies in comment_replies[1]
        ]
        assert 4 in reply_ids_of_comment_one
        assert 5 in reply_ids_of_comment_one
        assert 6 not in reply_ids_of_comment_one

        reply_ids_of_comment_two = [
            replies['comment_id'] for replies in comment_replies[2]
        ]
        assert 6 in reply_ids_of_comment_two
        assert 4 not in reply_ids_of_comment_two
        assert 5 not in reply_ids_of_comment_two
    def test_get_positive_posts_response(self, setup_data):

        post_storage_object = PostStorageImpl()
        post_ids = post_storage_object.get_posts_with_more_positive_reactions()

        assert self.post.id in post_ids
        assert self.post_2.id in post_ids
Beispiel #4
0
    def test_post_exists_returns_false(self, post_mock):

        post_mock.objects.get.side_effect = ObjectDoesNotExist

        post_storage_object = PostStorageImpl()
        response = post_storage_object.post_exists(post_id=1)

        post_mock.objects.get.assert_called_once_with(pk=1)
        assert response == False
Beispiel #5
0
    def test_post_exists_returns_true(self, post_mock):

        post = create_autospec(Post)
        post_mock.objects.get.return_value = post

        post_storage_object = PostStorageImpl()
        response = post_storage_object.post_exists(post_id=1)

        post_mock.objects.get.assert_called_once_with(pk=1)
        assert response == True
Beispiel #6
0
    def test_is_reply_with_comment(self, comment_mock):

        comment = create_autospec(Comment)
        comment.commented_on = None
        comment_mock.objects.get.return_value = comment

        post_storage_object = PostStorageImpl()
        response = post_storage_object.is_reply(3)

        comment_mock.objects.get.assert_called_once_with(pk=3)
        assert response == False
Beispiel #7
0
    def test_is_reply_with_reply(self, comment_mock):

        comment = Mock()
        comment.commented_on = 2
        comment_mock.objects.get.return_value = comment

        post_storage_object = PostStorageImpl()
        response = post_storage_object.is_reply(3)

        comment_mock.objects.get.assert_called_once_with(pk=3)
        assert response == True
    def test_post_reaction_exists_returns_true(self, post_reaction_mock):

        post_reaction = create_autospec(PostReactions)
        post_reaction_mock.objects.get.return_value = post_reaction

        post_storage_object = PostStorageImpl()
        response = post_storage_object.post_reaction_exists(user_id=1,
                                                            post_id=1)

        post_reaction_mock.objects.get.assert_called_once_with(user_id=1,
                                                               post_id=1)
        assert response == True
    def test_create_post_response(self, setup_data):

        post_storage_object = PostStorageImpl()
        post_dto = post_storage_object.create_post("This is a testing post",
                                                   self.user_1.id)

        post = Post.objects.get(pk=1)

        assert post_dto.post_id == post.id
        assert post_dto.user_id == self.user_1.id
        assert post_dto.post_content == post.post_content
        assert post_dto.created_time == post.posted_time
    def test_get_user_dto(self):

        comment = {
            "user": 1,
            "user__username": "******",
            "user__profile_pic_url": "http://profile_pic"
        }
        post_storage_object = PostStorageImpl()
        user_dto = post_storage_object.convert_user_dict_to_dto(comment)

        assert user_dto.user_id == comment['user']
        assert user_dto.name == comment['user__username']
        assert user_dto.profile_pic_url == comment['user__profile_pic_url']
Beispiel #11
0
    def test_add_comment_to_post_response(self, setup_data):

        post_storage_object = PostStorageImpl()
        comment_dto = post_storage_object.add_comment_to_post(
            self.post.id, self.user_1.id, "This is comment")

        comment = Comment.objects.filter(post_id=self.post.id).first()

        assert comment_dto.comment_id == comment.id
        assert comment_dto.user_id == comment.user_id
        assert comment_dto.commented_at == comment.commented_time
        assert comment_dto.comment_content == comment.comment_text
        assert comment_dto.commented_on_id == comment.commented_on_id
    def test_update_post_reaction_response(self, setup_data):

        post_storage_object = PostStorageImpl()
        post_reaction_dto = post_storage_object.update_post_reaction(
            user_id=self.user_1.id, post_id=self.post.id, reaction_type="LIKE")

        post_reaction = PostReactions.objects.filter(post_id=self.post.id)\
            .first()

        assert post_reaction_dto.reaction_id == post_reaction.id
        assert post_reaction_dto.user_id == post_reaction.user_id
        assert post_reaction_dto.reaction_type == post_reaction.reaction_type
        assert post_reaction_dto.post_id == post_reaction.post_id
    def test_add_reply_to_comment_response(self, setup_data):

        post_storage_object = PostStorageImpl()
        reply_dto = post_storage_object.add_reply_to_comment(
            self.comment.id, self.user_1.id, "This is reply")

        reply = Comment.objects.filter(post_id=self.post.id,
                                       commented_on=self.comment).first()

        assert reply_dto.comment_id == reply.id
        assert reply_dto.user_id == reply.user_id
        assert reply_dto.commented_at == reply.commented_time
        assert reply_dto.comment_content == reply.comment_text
        assert reply_dto.commented_on_id == reply.commented_on_id
    def test_update_comment_reaction_response(self, setup_data):

        post_storage_object = PostStorageImpl()
        comment_reaction_dto = post_storage_object.update_comment_reaction(
            user_id=self.user_1.id,
            comment_id=self.comment.id,
            reaction_type="LIKE")

        comment_reaction = CommentReactions.objects.filter(
            comment_id=self.comment.id).first()

        assert comment_reaction_dto.reaction_id == comment_reaction.id
        assert comment_reaction_dto.user_id == comment_reaction.user_id
        assert comment_reaction_dto.reaction_type == \
               comment_reaction.reaction_type
        assert comment_reaction_dto.comment_id == comment_reaction.comment_id
    def test_get_comment_dto_with_replies(self):
        comment_reactions = {"count": 1, "type": ["WOW", "LOVE"]}
        comment = {
            "id": 1,
            "commented_time": datetime.now(),
            "comment_text": "This is comment data",
            "user": 1,
            "user__username": "******",
            "user__profile_pic_url": "http://profile_pic"
        }
        replies = []
        replies_count = 0

        post_storage_object = PostStorageImpl()
        comment_dto_with_replies = post_storage_object.\
            convert_comment_dict_to_comment_details_with_replies_dto(
            comment, comment_reactions, replies, replies_count)

        assert comment_dto_with_replies.comment_id == comment['id']
        assert comment_dto_with_replies.commented_at == comment[
            'commented_time']
        assert comment_dto_with_replies.comment_content == \
               comment['comment_text']

        comment_user = comment_dto_with_replies.user
        assert comment_user.user_id == comment['user']
        assert comment_user.name == comment['user__username']
        assert comment_user.profile_pic_url == comment['user__profile_pic_url']

        reactions = comment_dto_with_replies.comment_reactions
        assert reactions.count == comment_reactions['count']
        assert reactions.type == comment_reactions['type']

        assert comment_dto_with_replies.replies == replies
        assert comment_dto_with_replies.replies_count == replies_count
    def test_get_reactions_dto(self):

        comment_reactions = {"count": 1, "type": ["WOW", "LOVE"]}
        post_storage_object = PostStorageImpl()
        reaction_dto = post_storage_object\
            .convert_reaction_stats_dict_to_dto(comment_reactions)

        assert reaction_dto.count == comment_reactions["count"]
        assert reaction_dto.type == comment_reactions["type"]
Beispiel #17
0
def api_wrapper(*args, **kwargs):

    post_id = kwargs["post_id"]

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = DeletePostInteractor(post_storage, json_presenter)

    response = interactor.delete_post(post_id)
    return HttpResponse(json.dumps(response), status=201)
def api_wrapper(*args, **kwargs):

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = GetTotalReactionCountInteractor(post_storage, json_presenter)

    response = interactor.get_total_reaction_count()

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
def api_wrapper(*args, **kwargs):

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = GetPostsWithMorePositiveReactionsInteractor(post_storage,
                                                             json_presenter)

    response = interactor.get_positive_posts()

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
def api_wrapper(*args, **kwargs):
    post_id = kwargs["post_id"]

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = GetReactionMetricsInteractor(post_storage, json_presenter)

    response = interactor.get_reaction_metrics(post_id)

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
def api_wrapper(*args, **kwargs):
    user = kwargs["user"]

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = GetUserReactedPostsInteractor(post_storage, json_presenter)

    response = interactor.get_posts_reacted_by_user(user.id)

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
Beispiel #22
0
    def test_get_reaction_metrics(self, setup_data):

        post_storage_object = PostStorageImpl()
        reaction_metrics_dto = post_storage_object.get_reaction_metrics(
            self.post.id)

        reaction_metrics_of_love = None
        for metric in reaction_metrics_dto:
            if metric.reaction_type == "LOVE":
                reaction_metrics_of_love = metric
                break

        assert reaction_metrics_of_love.count == 1

        reaction_metrics_of_like = None
        for metric in reaction_metrics_dto:
            if metric.reaction_type == "LIKE":
                reaction_metrics_of_like = metric
                break

        assert reaction_metrics_of_like == None
Beispiel #23
0
def api_wrapper(*args, **kwargs):

    request_data = kwargs["request_data"]
    user = kwargs["user"]

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = CreatePostInteractor(post_storage, json_presenter)

    response = interactor.create_post(request_data["post_content"], user.id)

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
Beispiel #24
0
def api_wrapper(*args, **kwargs):
    comment_id = kwargs["comment_id"]
    request_query_params = kwargs["request_query_params"]
    offset = request_query_params.offset
    limit = request_query_params.limit

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = GetCommentRepliesInteractor(post_storage, json_presenter)

    response = interactor.get_comment_replies(comment_id, offset, limit)

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
def api_wrapper(*args, **kwargs):
    user = kwargs["user"]
    request_query_params = kwargs["request_query_params"]
    offset = request_query_params.offset
    limit = request_query_params.limit

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = GetUserPostsInteractor(post_storage, json_presenter)

    response = interactor.get_user_posts(user.id, offset, limit)

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
Beispiel #26
0
    def test_get_replies_to_comment_response(self, setup_data):

        post_storage_object = PostStorageImpl()
        replies_dto = post_storage_object.get_comment_replies(
            self.comment.id, 0, 2)

        reply_ids = [reply.comment_id for reply in replies_dto]

        assert self.reply_1.id in reply_ids
        assert self.reply_2.id in reply_ids

        reply_one_data = None
        for reply in replies_dto:
            if reply.comment_id == self.reply_1.id:
                reply_one_data = reply
                break

        reply_user = reply_one_data.user
        assert reply_user.user_id == self.user_1.id
        assert reply_user.name == self.user_1.username
        assert reply_user.profile_pic_url == self.user_1.profile_pic_url

        assert reply_one_data.commented_at == self.reply_1.commented_time
        assert reply_one_data.comment_content == self.reply_1.comment_text
Beispiel #27
0
def api_wrapper(*args, **kwargs):
    user = kwargs["user"]
    comment_id = kwargs["comment_id"]
    request_data = kwargs["request_data"]

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = ReactionInteractor(post_storage, json_presenter)

    response = interactor.react_to_comment(user.id, comment_id,
                                           request_data["reaction_type"])

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
def api_wrapper(*args, **kwargs):
    comment_id = kwargs["comment_id"]
    user = kwargs["user"]
    request_data = kwargs["request_data"]

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = AddCommentInteractor(post_storage, json_presenter)

    response = interactor.add_reply_to_comment(comment_id, user.id,
                                               request_data["comment_text"])

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
    def test_get_reactions_to_post(self, setup_data):

        post_storage_object = PostStorageImpl()
        post_reactions_dto = post_storage_object\
            .get_post_reactions(self.post.id, 0, 2)

        reaction_one_data = None
        for reaction in post_reactions_dto:
            if reaction.user_id == self.user_1.id:
                reaction_one_data = reaction

        assert reaction_one_data.name == self.user_1.username
        assert reaction_one_data.profile_pic_url == self.user_1.profile_pic_url
        assert reaction_one_data.reaction_type == \
               self.post_reaction_1.reaction_type
    def test_total_reaction_count_response(self, setup_data):

        post_storage_object = PostStorageImpl()
        total_reactions_count = post_storage_object.get_total_reaction_count()

        assert total_reactions_count == 2