def test_get_comment_id(self, setup_data): post_storage = Storage() reply_id = self.first_reply.id comment_id = post_storage.get_comment_id(reply_id) assert comment_id == self.first_comment.id
def test_post_reaction_not_exists(self, mock_post_reaction): post_storage = Storage() mock_post_reaction.objects.get.side_effect = ObjectDoesNotExist with self.assertRaises(ObjectDoesNotExist): response = post_storage.post_reaction_exists(1, 1)
def test_post_not_exists(self, mock_post): post_storage = Storage() mock_post.objects.get.side_effect = ObjectDoesNotExist response = post_storage.post_exists(1) assert response is False
def test_delete_comment_reaction(self, setup_data): post_storage = Storage() reaction_id = post_storage.update_comment_reaction( self.first_comment.id, self.user.id, "LOVE") assert reaction_id == self.first_comment_reaction.id
def test_delete_comment_reaction(self, setup_data): post_storage = Storage() reaction_id = post_storage.delete_comment_reaction( self.first_comment.id, self.user.id) assert reaction_id is None
def test_get_comment_dto(self, setup_data): post_storage = Storage() comment = { 'id': self.first_comment.id, 'user_id': self.first_comment.user_id, 'user__username': self.first_comment.user.username, 'user__profile_pic': self.first_comment.user.profile_pic, 'message': self.first_comment.message, 'comment_create_date': self.first_comment.comment_create_date } comment_reactions = { self.first_comment.id: { 'count': 2, 'types': ['LIKE', 'LOVE'] } } comment_dto = post_storage.get_comment_dto(comment, comment_reactions) assert comment_dto.id == comment['id'] assert comment_dto.user.user_id == comment['user_id'] assert comment_dto.comment_content == comment['message'] assert comment_dto.comment_create_date == comment[ 'comment_create_date']
def test_post_exists(self, mock_post): post_storage = Storage() post = Mock() mock_post.objects.get.return_value = post response = post_storage.post_exists(1) assert response is True
def test_posts_with_more_positive_reactions(self, setup_data): post_storage = Storage() posts_list = post_storage.get_positive_reaction_posts() post_ids = [post_id for post_id in posts_list] assert self.first_post.id in post_ids assert self.second_post.id not in post_ids
def test_comment(self, mock_comment): post_storage = Storage() comment_id = 2 comment = Mock() comment.commented_on = None mock_comment.objects.get.return_value = comment response = post_storage.is_comment_or_reply(comment_id) assert response is True
def test_create_reply(self, setup_data): post_storage = Storage() comment_content = "first reply" reply_id = post_storage.create_reply(self.first_comment.id, self.user.id, comment_content) comment = Comment.objects.get(id=reply_id) assert reply_id == 2 assert comment.commented_on_id == self.first_comment.id
def test_create_post(self, setup_data): post_storage = Storage() post_content = "first post" post_id = post_storage.create_post(post_content, self.user.id) post = Post.objects.get(id=post_id) assert post_id == post.id assert post.post_description == post_content
def test_posts_reacted_by_user(self, setup_data): post_storage = Storage() posts_reacted = post_storage.get_user_reacted_posts(self.user.id) assert len(posts_reacted) == 2 posts_ids = [post_id for post_id in posts_reacted] assert self.post.id in posts_ids assert self.post2.id in posts_ids
def test_create_comment(self, setup_data): post_storage = Storage() comment_content = "first comment" comment_id = post_storage.create_comment(self.post.id, self.user.id, comment_content) comment = Comment.objects.get(id=comment_id) assert comment_id == 1 assert comment.message == comment_content
def test_react_to_comment(self, setup_data): post_storage = Storage() reaction = "LOVE" reaction_id = post_storage.add_comment_reaction( self.first_comment.id, self.user.id, reaction) react = CommentReaction.objects.get(id=reaction_id) assert reaction_id == react.id assert react.comment_id == self.first_comment.id assert react.reaction == reaction
def test_react_to_post(self, setup_data): post_storage = Storage() reaction = "LIKE" reaction_id = post_storage.add_post_reaction(self.post.id, self.user.id, reaction) react = PostReaction.objects.get(id=reaction_id) assert reaction_id == react.id assert react.post_id == self.post.id assert react.reaction == reaction
def test_get_replies(self, setup_data): post_storage = Storage() replies_dto = post_storage.get_comment_replies(self.first_comment.id, offset=0, limit=1) assert len(replies_dto) == 1 assert replies_dto[0].comment_id in [ self.first_reply.id, self.second_reply.id ]
def test_get_post_post_content(self, setup_data): post_storage = Storage() get_post_dto = post_storage.get_post(post_id=1) post = get_post_dto.post user = get_post_dto.posted_by reactions = get_post_dto.reactions assert post.id == self.post.id assert post.post_content == self.post.post_description assert post.post_create_date == self.post.post_create_date assert user.user_id == self.post.user_id assert user.username == self.post.user.username assert user.profile_pic == self.post.user.profile_pic assert reactions.count == 2 assert sorted(["LOVE"]) == reactions.types comments = get_post_dto.comments assert self.first_comment.id in [comment.id for comment in comments] test_comment = None for comment in comments: if comment.id == self.first_comment.id: test_comment = comment commenter = test_comment.user assert commenter.user_id == self.first_comment.user_id assert commenter.username == self.first_comment.user.username assert commenter.profile_pic == self.first_comment.user.profile_pic assert test_comment.comment_content == self.first_comment.message comment_reactions = test_comment.comment_reactions assert comment_reactions.count == 2 assert sorted(comment_reactions.types) == sorted(['LIKE', 'LOVE']) assert test_comment.replies_count == 1 test_reply = None for reply in test_comment.replies: if reply.id == self.first_reply.id: test_reply = reply commenter = test_reply.user assert commenter.user_id == self.first_reply.user_id assert commenter.username == self.first_reply.user.username assert commenter.profile_pic == self.first_reply.user.profile_pic assert test_reply.comment_content == self.first_reply.message reply_reactions = test_reply.comment_reactions assert reply_reactions.count == 1 assert reply_reactions.types == ['LIKE']
def test_reactions_to_post(self, setup_data): post_storage = Storage() reactions = post_storage.get_post_reactions(self.post.id, offset=0, limit=2) assert len(reactions) == 2 reactions = [reaction_dto.reaction for reaction_dto in reactions] assert self.first_reaction.reaction in reactions assert self.second_reaction.reaction in reactions
def test_reaction_metrics(self, setup_data): post_storage = Storage() reaction_metrics = post_storage.get_reaction_metrics( self.first_post.id) reactions = [[reaction_dto.count, reaction_dto.reaction] for reaction_dto in reaction_metrics] assert [1, 'LIKE'] in reactions assert [1, 'LOVE'] in reactions assert [1, 'HAHA'] in reactions assert [1, 'SAD'] in reactions
def test_user_posts(self, setup_data): post_storage = Storage() userposts_dto = post_storage.get_user_posts(user_id=self.user.id, offset=0, limit=2) assert len(userposts_dto.posts) == 2 post_ids = [userpost.post.id for userpost in userposts_dto.posts] assert self.post.id in post_ids assert self.post2.id in post_ids assert self.post3.id not in post_ids assert self.post4.id not in post_ids
def test_get_comment_with_replies_dto(self, setup_data): post_storage = Storage() post_comments = [{ 'id': self.first_comment.id, 'user_id': self.first_comment.user_id, 'user__username': self.first_comment.user.username, 'user__profile_pic': self.first_comment.user.profile_pic, 'message': self.first_comment.message, 'comment_create_date': self.first_comment.comment_create_date }, { 'id': self.second_comment.id, 'user_id': self.second_comment.user_id, 'user__username': self.second_comment.user.username, 'user__profile_pic': self.second_comment.user.profile_pic, 'message': self.second_comment.message, 'comment_create_date': self.second_comment.comment_create_date }] comment_reactions = { self.first_comment.id: { 'count': 2, 'types': ['LIKE', 'LOVE'] } } replies_dto = [] replies_count = 0 comment_with_replies_dto = post_storage.get_comment_with_replies_dto( post_comments[0], comment_reactions, replies_count, replies_dto) assert comment_with_replies_dto.id == post_comments[0]['id'] assert comment_with_replies_dto.user.user_id == post_comments[0][ 'user_id'] assert comment_with_replies_dto.comment_content == post_comments[0][ 'message'] assert comment_with_replies_dto.replies == replies_dto assert comment_with_replies_dto.replies_count == replies_count
def test_all_comment_replies(self, setup_data): post_storage = Storage() replies = [{ 'id': self.first_reply.id, 'user_id': self.first_reply.user_id, 'user__username': self.first_reply.user.username, 'user__profile_pic': self.first_reply.user.profile_pic, 'commented_on_id': self.first_comment.id, 'message': self.first_reply.message, 'comment_create_date': self.first_reply.comment_create_date }] all_replies = post_storage.get_all_comment_replies_dict(replies) assert all_replies[self.first_comment.id] == replies
def test_comment_reactions_dto(self, setup_data): post_storage = Storage() comment_reactions = { self.first_comment.id: { 'count': 2, 'types': ['LIKE', 'LOVE'] } } reaction_dto = post_storage.get_comment_reactions_dto( self.first_comment.id, comment_reactions) assert reaction_dto.count == comment_reactions[ self.first_comment.id]['count'] assert sorted(reaction_dto.types) == sorted( comment_reactions[self.first_comment.id]['types'])
def test_commenter_dto(self, setup_data): post_storage = Storage() comment = { 'id': self.first_comment.id, 'user_id': self.first_comment.user_id, 'user__username': self.first_comment.user.username, 'user__profile_pic': self.first_comment.user.profile_pic, 'commented_on_id': self.first_comment.commented_on_id, 'comment_create_date': self.first_comment.comment_create_date, 'message': self.first_comment.message } user_dto = post_storage.get_commenter_dto(comment) assert user_dto.user_id == comment['user_id'] assert user_dto.username == comment['user__username'] assert user_dto.profile_pic == comment['user__profile_pic']
def api_wrapper(*args, **kwargs): post_storage = Storage() presenter = Presenter() interactor = GetTotalReactionCountInteractor(post_storage, presenter) response = interactor.get_total_reaction_count() import json return json.dumps(response)
def api_wrapper(*args, **kwargs): post_storage = Storage() presenter = Presenter() interactor = GetPostsWithPositiveReactionsInteractor( post_storage, presenter) response = interactor.get_posts_with_more_positive_reactions() import json return json.dumps(response)
def test_post_reaction_exists(self, mock_post_reaction): post_storage = Storage() reaction = Mock() id = 1 post_id = 1 reacted_by = 1 reaction.id = id reaction.post_id = post_id reaction.user_id = reacted_by reaction.reaction = "LIKE" reaction_dto = ReactionDTO(id=id, react_on_id=post_id, reacted_by=reacted_by, reaction="LIKE") mock_post_reaction.objects.get.return_value = reaction response = post_storage.post_reaction_exists(post_id, reacted_by) assert response == reaction_dto
def api_wrapper(*args, **kwargs): post_id = kwargs['postid'] post_storage = Storage() presenter = Presenter() interactor = DeletePostInteractor(post_storage, presenter) response = interactor.delete_post(post_id) import json return json.dumps(response)
def api_wrapper(*args, **kwargs): post_id = kwargs['postid'] post_storage = Storage() presenter = Presenter() interactor = GetReactionMetricsInteractor(post_storage, presenter) response = interactor.get_reaction_metrics(post_id) import json return json.dumps(response)
def api_wrapper(*args, **kwargs): user = kwargs['username'] post_storage = Storage() presenter = Presenter() interactor = GetPostsReactedByUserInteractor(post_storage, presenter) response = interactor.get_posts_reacted_by_user(user) import json return json.dumps(response)