Skip to content

Commit

Permalink
add tests for not founding the comment and post
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdihaghverdi committed Mar 3, 2024
1 parent 3667c9a commit f8800f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ async def _comment_not_self_not_allowed(
.where(CommentModel.id == comment_id)
)

draft = (await db.execute(stmt)).first()
if draft is not None:
comment = (await db.execute(stmt)).first()
if comment is not None:
return True
raise UnAuthorisedAccessError()

Expand Down
20 changes: 20 additions & 0 deletions tests/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ def test_add_comment(client, mahdi_auth_headers, post_id_fixture):
assert data["reply_count"] == 0


def test_add_comment_post_not_found(client, mahdi_auth_headers):
response = client.post(
f"{settings.PREFIX}/{APIPrefixesEnum.COMMENTS.value}/100",
json={"comment": "comment"},
headers=mahdi_auth_headers,
)

assert response.status_code == 404, response.text


def test_add_reply(client, mahdi_auth_headers, post_id_fixture, comment_id_fixture):
response = client.post(
f"{settings.PREFIX}/{APIPrefixesEnum.COMMENTS.value}/{post_id_fixture}/{comment_id_fixture}",
Expand All @@ -40,6 +50,16 @@ def test_add_reply(client, mahdi_auth_headers, post_id_fixture, comment_id_fixtu
assert data["reply_count"] == 0


def test_add_reply_comment_not_found(client, mahdi_auth_headers, post_id_fixture):
response = client.post(
f"{settings.PREFIX}/{APIPrefixesEnum.COMMENTS.value}/{post_id_fixture}/100",
json={"comment": "reply"},
headers=mahdi_auth_headers,
)

assert response.status_code == 404, response.text


def test_get_comments(client, mahdi_auth_headers, post_id_fixture):
c1_id = client.post(
f"{settings.PREFIX}/{APIPrefixesEnum.COMMENTS.value}/{post_id_fixture}",
Expand Down

0 comments on commit f8800f8

Please sign in to comment.