def test_get_reactions_to_post_dto_with_valid_details_return_dto( create_users, create_posts, create_comments, create_post_reactions ): # Arrange post_id = 1 user_dto1 = UserDto(user_id=1, name="che", profile_pic="che/profile_pic") user_dto2 = UserDto(user_id=2, name="stevejobs", profile_pic="stevjobs/profile_pic") expected_post_reaction_dtos = [ PostReactionsDto(user_dto=user_dto1, reaction=ReactionTypeEnum.WOW.value), PostReactionsDto(user_dto=user_dto2, reaction=ReactionTypeEnum.LOVE.value)] storage = StorageImplementation() # Act actual_post_reaction_dtos = storage.get_reactions_to_post_dto( post_id=post_id ) # Assert assert actual_post_reaction_dtos == expected_post_reaction_dtos
def test_validate_post_reaction_if_not_exists_raise_exception(): user_id = 1 post_id = 1 sql_storage = StorageImplementation() with pytest.raises(ReactionDoesNotExist): sql_storage.validate_post_reaction_if_exists_get_reaction_type( user_id=user_id, post_id=post_id)
def test_is_valid_post_id_with_valid_details_returns_true( create_users, create_posts): # Arrange post_id = 1 storage = StorageImplementation() # Act is_valid_post_id = storage.is_valid_post_id(post_id=post_id) # Assert assert is_valid_post_id is True
def test_create_post_and_get_id_method_given_valid_details_returns_post_id(create_users ): user_id = 1 post_content = "Post Content" storage = StorageImplementation() post_id = storage.create_post(user_id=user_id, post_content=post_content) post = Post.objects.get(id=post_id) assert post_id == post.id
def test_validate_comment_reaction_if_exists_get_reaction_type_if_reaction_not_exists_raise_exception( create_users, create_posts, create_comments, create_reactions): # Arrange user_id = -1 comment_id = -1 storage = StorageImplementation() # Act with pytest.raises(ReactionDoesNotExists): storage.validate_comment_reaction_if_exists_get_reaction_type( user_id=user_id, comment_id=comment_id)
def test_is_valid_post_id_with_invalid_details_returns_false( create_users, create_posts): # Arrange invalid_post_id = -1 storage = StorageImplementation() # Act is_valid_post_id = storage.is_valid_post_id(post_id=invalid_post_id) # Assert assert is_valid_post_id is False
def test_get_posts_reacted_by_with_valid_details_return_ids_list( create_users, create_posts, create_comments, create_reactions): # Arrange user_id = 1 expected_post_ids_list = [1] storage = StorageImplementation() # Act actual_post_ids_list = storage.get_posts_reacted_by_user(user_id=user_id) # Assert assert actual_post_ids_list.sort() == expected_post_ids_list.sort()
def test_create_post_with_valid_details_returns_post_id(create_users): # Arrange user_id = 1 post_content = 'Post content' storage = StorageImplementation() # Act post_id = storage.create_post(user_id=user_id, post_content=post_content) # Assert post = Post.objects.get(id=post_id) assert post_id == post.id
def test_create_reaction_to_comment_with_valid_details(create_users, create_posts, create_comments, create_reactions): # Arrange expected_post_ids_list = [1] storage = StorageImplementation() # Act actual_post_ids_list = storage.get_posts_with_more_positive_reactions() # Assert assert actual_post_ids_list == expected_post_ids_list
def test_delete_post_with_valid_details(create_users, create_posts): # Arrange post_id = 1 storage = StorageImplementation() # Act storage.delete_post(post_id=post_id) # Assert is_post_exists = Post.objects.filter(id=post_id).exists() is_post_deleted = not is_post_exists assert is_post_deleted is True
def test_is_post_created_by_user_with_valid_details_return_true( create_users, create_posts, create_comments, create_reactions ): # Arrange user_id = 1 post_id = 1 storage = StorageImplementation() # Act is_post_created_by_user = storage.is_post_created_by_user(user_id=user_id, post_id=post_id) # Assert assert is_post_created_by_user is True
def test_create_post_reaction_given_valid_details_creates_post_reaction( create_users, create_post): user_id = 1 post_id = 1 reaction_type = ReactionType.HAHA.value sql_storage = StorageImplementation() sql_storage.create_post_reaction(user_id=user_id, post_id=post_id, reaction_type=reaction_type) reaction = Reactions.objects.get(user_id=user_id, post_id=post_id) assert reaction.user.id == user_id assert reaction.post.id == post_id assert reaction.reaction_type == reaction_type
def test_undo_post_reaction_with_valid_details_delete_reaction( create_users, create_posts, create_comments, create_reactions): # Arrange user_id = 1 post_id = 1 storage = StorageImplementation() # Act storage.undo_post_reaction(user_id=user_id, post_id=post_id) # Assert is_reaction_exits = Reaction.objects.filter(reacted_by_id=user_id, post_id=post_id).exists() assert is_reaction_exits is False
def test_get_total_reaction_count_dto_with_valid_details_return_dto( create_users, create_posts, create_comments, create_reactions): # Arrange expected_total_reaction_count_dto = TotalReactionCountDto(count=2) storage = StorageImplementation() # Act actual_total_reation_count_dto = storage.get_total_reaction_count_dto() # Assert assert actual_total_reation_count_dto.count == \ expected_total_reaction_count_dto.count assert actual_total_reation_count_dto == \ expected_total_reaction_count_dto
def test_reply_to_comment_with_valid_details_return_reply_id( create_users, create_posts, create_comments): # Arrange user_id = 1 comment_id = 1 reply_content = 'Reply Content' storage = StorageImplementation() # Act reply_id = storage.reply_to_comment(user_id=user_id, comment_id=comment_id, reply_content=reply_content) # Assert reply = Comment.objects.get(id=reply_id) assert reply_id == reply.id
def test_get_post_dto_with_valid_details_return_dto( create_users, create_posts, get_post_create_comments, create_reactions, get_post_user_dtos, get_post_comment_dtos, get_post_reaction_dtos, get_post_post_dto): # Arrange post_id = 1 expected = PostCompleteDetailsDto(post_dto=get_post_post_dto, user_dtos=get_post_user_dtos, comment_dtos=get_post_comment_dtos, reaction_dtos=get_post_reaction_dtos) storage = StorageImplementation() # Act actual_post_complete_dto = storage.get_post_dto(post_id=post_id) # Assert assert actual_post_complete_dto == expected
def test_create_comment_given_valid_details_creates_comment_triangulation( create_users, create_post): user_id = 1 post_id = 1 comment_text = "Nice Post" sql_storage = StorageImplementation() comment_id = sql_storage.create_comment( user_id=user_id, post_id=post_id, comment_text=comment_text) comment = Comment.objects.get(id=comment_id) assert comment.id == comment_id assert comment.user.id == user_id assert comment.post.id == post_id assert comment.comment_text == comment_text
def test_create_comment_with_valid_details_returns_comment_id( create_users, create_posts): # Arrange user_id = 1 post_id = 1 comment_content = 'Comment content' storage = StorageImplementation() # Act comment_id = storage.create_comment(user_id=user_id, post_id=post_id, comment_content=comment_content) # Assert comment = Comment.objects.get(id=comment_id) assert comment_id == comment.id
def test_validate_post_reaction_if_exists_get_reaction_type( create_users, create_post, create_post_reactions): user_id = 1 post_id = 1 sql_storage = StorageImplementation() reaction_type = sql_storage. \ validate_post_reaction_if_exists_get_reaction_type(user_id=user_id, post_id=post_id) assert reaction_type == "LIKE"
def test_create_reaction_to_post_with_valid_details(create_users, create_posts, create_comments, create_reactions): # Arrange user_id = 1 post_id = 1 reaction_type = ReactionTypeEnum.LIT.value storage = StorageImplementation() # Act reaction_id = storage.create_reaction_to_post(user_id=user_id, post_id=post_id, reaction_type=reaction_type) # Assert reaction = Reaction.objects.get(id=reaction_id) assert reaction_id == reaction.id
def test_get_reaction_metrics_dto_with_valid_details_returrn_dto( create_users, create_posts, create_comments, create_reactions): # Arrange post_id = 1 expected_reaction_metrics_dtos = [ ReactionMetricsDto(reaction_type=ReactionTypeEnum.WOW.value, count=1) ] storage = StorageImplementation() # Act actual_reaction_metrics_dtos = storage.get_reaction_metrics_dto( post_id=post_id) # Assert assert actual_reaction_metrics_dtos[0].reaction_type == \ expected_reaction_metrics_dtos[0].reaction_type assert actual_reaction_metrics_dtos[0].count == \ expected_reaction_metrics_dtos[0].count assert actual_reaction_metrics_dtos == expected_reaction_metrics_dtos
def test_update_comment_reaction_with_valid_details(create_users, create_posts, create_comments, create_reactions): # Arrange user_id = 1 comment_id = 1 reaction_type = ReactionTypeEnum.THUMBS_UP.value storage = StorageImplementation() # Act storage.update_comment_reaction(user_id=user_id, comment_id=comment_id, reaction_type=reaction_type) # Assert reaction = Reaction.objects.get(reacted_by_id=user_id, comment_id=comment_id, reaction=reaction_type) assert user_id == reaction.reacted_by_id assert comment_id == reaction.comment_id assert reaction_type == reaction.reaction
def test_validate_comment_reaction_if_exists_get_reaction_type_with_valid_details_return_reaction_type( create_users, create_posts, create_comments, create_reactions): # Arrange user_id = 1 comment_id = 1 expected_reaction_type = "LOVE" storage = StorageImplementation() # Act actual_reaction_type = storage. \ validate_comment_reaction_if_exists_get_reaction_type( user_id=user_id, comment_id=comment_id) # Assert assert actual_reaction_type == expected_reaction_type
def test_return_comment_id_if_is_comment_id_or_return_parent_comment_id_with_comment_id( create_users, create_posts, create_comments ): # Arrange comment_id = 1 storage = StorageImplementation() # Act returned_comment_id = storage. \ return_comment_id_if_is_comment_id_or_return_parent_comment_id( comment_id=comment_id ) # Assert comment = Comment.objects.get(id=returned_comment_id) assert comment.parent_comment_id is None assert comment_id == returned_comment_id
def test_validate_post_id_given_invalid_post_id_raises_exception(): post_id = 3 sql_storage = StorageImplementation() with pytest.raises(InvalidPostId): sql_storage.validate_post_id(post_id=post_id)
def test_validate_post_id_given_invalid_comment_id_raises_exception(): comment_id = 10 sql_storage = StorageImplementation() with pytest.raises(InvalidCommentId): sql_storage.validate_comment_id(comment_id=comment_id)