-
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
Sehwa step2 comment list #50
base: legacy
Are you sure you want to change the base?
Conversation
comment_list = [{"author": comment.author, "text": comment.text} for comment in comments] | ||
|
||
return JsonResponse({"data": comment_list}) |
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.
nipick,
comment_list = [{"author": comment.author, "text": comment.text} for comment in comments] | |
return JsonResponse({"data": comment_list}) | |
return JsonResponse({"data": [{"author": comment.author, "text": comment.text} for comment in comments]}) |
변수 선언안해줘도 코드로 인지 가능해서 인라인해서 써줘도 될거 같애~
@@ -243,3 +244,112 @@ def test_delete_post_with_invalid_author_id(self): | |||
# And: 응답 메세지가 유효하지 않은 사용자 id입니다. 여야 한다. | |||
response = json.loads(response.content) | |||
self.assertEqual(response["message"], "유효하지 않은 사용자 id입니다.") | |||
|
|||
|
|||
class TestCommentList(TestPostMixin, TestCase): |
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.
굳 테스트 잘짰네~ ㅋㅋ 👍
for i in range(comment_count): | ||
comment = self._create_comment_on_post(self.post, f"author{i}", f"comment{i}") | ||
comment.approve() |
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.
이 부분은 extract method 할 수 있을 것 같애
* 다른 테스트들과 연관된 부분이 아니라서 굳이 뺄 필욘 없지만, 가독성 측면 혹은 나중에 혹시 재활용할 측면에서는 뺴는게 좋다고 생각함
...
def _create_comments_with_approve(self, comment_count):
for i in range(comment_count):
comment = self._create_comment_on_post(self.post, f"author{i}", f"comment{i}")
comment.approve()
...
@@ -43,3 +42,31 @@ def retrieve_post_detail(request, id): | |||
}, | |||
status=200, | |||
) | |||
|
|||
|
|||
class CommentListCreate(View): |
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.
CBV 쓴건 좋은 선택인거 같애~
comment list
url
GET /posts/{post_id}
설명
결과
성공 (200)
실패 (404)
post_id
가 유효하지 않을 때테스트
post_id
입력post_id
입력comment create
input
POST /posts/{post_id}
{ "author": "test author", "text": "test text" }
설명
post id
와author, text
를 json으로 입력받아 comment 생성결과
성공 (201)
comment가 생성된 post의 id와 comment 정보 return
실패
post_id
가 유효하지 않을 때 (404){ "message": "post가 없습니다." }
author
가 공백일 때 (400){ "message": "author가 없습니다." }
text
가 공백일 때 (400){ "message": "text가 없습니다." }
테스트
post_id
입력post_id
입력author
를 미입력text
를 미입력