async def test_user_can_delete_own_comment(app: FastAPI, authorized_client: Client, test_article: Article) -> None: created_comment_response = await authorized_client.post( app.url_path_for("comments:create-comment-for-article", slug=test_article.slug), json={"comment": { "body": "comment" }}, ) created_comment = CommentInResponse(**created_comment_response.json()) await authorized_client.delete( app.url_path_for( "comments:delete-comment-from-article", slug=test_article.slug, comment_id=str(created_comment.comment.id), )) comments_for_article_response = await authorized_client.get( app.url_path_for("comments:get-comments-for-article", slug=test_article.slug)) comments = ListOfCommentsInResponse(**comments_for_article_response.json()) assert len(comments.comments) == 0
async def create_comment_for_article( comment_create: CommentInCreate = Body(..., embed=True, alias="comment"), article: Article = Depends(get_article_by_slug_from_path), user: User = Depends(get_current_user_authorizer()), comments_repo: CommentsRepository = Depends(get_repository(CommentsRepository)), ) -> CommentInResponse: comment = await comments_repo.create_comment_for_article( body=comment_create.body, article=article, user=user, ) return CommentInResponse(comment=comment)
async def create_comment_for_announcement( comment_create: CommentInCreate = Body(..., embed=True, alias="comment"), user: User = Depends(get_current_user_authorizer()), comments_repo: CommentsRepository = Depends( get_repository(CommentsRepository)), ) -> CommentInResponse: comment = await comments_repo.create_comment_for_announcement( body=comment_create.body, announcement=None, user=user, ) return CommentInResponse(comment=comment)
async def test_user_can_add_comment_for_article( app: FastAPI, authorized_client: AsyncClient, test_article: Article ) -> None: created_comment_response = await authorized_client.post( app.url_path_for("comments:create-comment-for-article", slug=test_article.slug), json={"comment": {"body": "comment"}}, ) created_comment = CommentInResponse(**created_comment_response.json()) comments_for_article_response = await authorized_client.get( app.url_path_for("comments:get-comments-for-article", slug=test_article.slug) ) comments = ListOfCommentsInResponse(**comments_for_article_response.json()) assert created_comment.comment == comments.comments[0]