-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add remove post method #32
base: main
Are you sure you want to change the base?
Conversation
if body["author"] != to_delete_post.author_id: | ||
return JsonResponse({"message": "권한이 없습니다."}, status=UNAUTHORIZED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이때는 인증이 아니라 권한과 관련된 부분이라 401 보다는 403이 맞을 것 같애 403 FORBIDDEN
return JsonResponse( | ||
{ | ||
"post": | ||
{ | ||
"title": to_delete_post.title, | ||
"text": to_delete_post.text, | ||
} | ||
}, status=OK) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
200으로 줘도 무방하지만, 대개는 204 NO_CONTENT
로 주고, data는 따로 보내지 않음
return JsonResponse( | |
{ | |
"post": | |
{ | |
"title": to_delete_post.title, | |
"text": to_delete_post.text, | |
} | |
}, status=OK) | |
return JsonResponse(status=204) |
response = json.loads(response.content)["post"] | ||
self.assertEqual(response["title"], "test title") | ||
self.assertEqual(response["text"], "test text") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 요구사항이 title, text를 리턴해달라고 했다면, 추가되는게 맞지만 대개의 경우에는 204에 data는 따로 응답으로 보내진 않음 - 참고만
def test_post_remove_with_error_about_author(self): | ||
# Given: 유효하지 않은 author 생성 | ||
request_body = json.dumps({"author": 12314}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위에 적은 것 처럼, 테스트 코드에서 given 설정해줄 때, author id도 invalid 하다는 것을 확실히 명시해주면 좋을 것 같애
invalid_author_id = 12314
self.assertEqual(response.status_code, UNAUTHORIZED) | ||
# And: 실제 post는 삭제되지 않는다. | ||
self.assertEqual(Post.objects.all().count(), 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위에서 말한대로 403으로 수정~
…IT/CtrlF_Backend into jinho-step2-remove-post
9a69ce2
to
043b6d0
Compare
테스트 생성
post_id
값과 post의author
와 request_body의author
이 같을 때* 삭제 하고, 응답으로 삭제한 post의 제목과 내용을 리턴한다.
post_id
가 유효하지 않을 때* 삭제를 하지 않고,
post를 찾을 수 없습니다.
라는 메세지를 리턴한다.post_id
는 유효하지만, post의author
와 request_body의author
이 다를 때* 삭제를 하지 않고,
권한이 없습니다.
라는 메세지를 리턴한다.구현 코드 작성
테스트
통과