Skip to content

Sehwa step2 comment list#50

Open
jrhong95 wants to merge 8 commits intolegacyfrom
sehwa-step2-comment-list
Open

Sehwa step2 comment list#50
jrhong95 wants to merge 8 commits intolegacyfrom
sehwa-step2-comment-list

Conversation

@jrhong95
Copy link
Contributor

comment list

  1. url GET /posts/{post_id}

  2. 설명

    • post id를 받아 post의 comment list를 반환
  3. 결과

    1. 성공 (200)

      {
          "data": [
              {
                  "author": "test author",
                  "text": "test text"
              },
              {...},
              ...
          ]
      }
    2. 실패 (404)

      • post_id가 유효하지 않을 때

        {
            "message": "post가 없습니다."
        }
  4. 테스트

    1. 유효한 post_id입력
    2. 유효하지 않은 post_id입력

comment create

  1. input

    • url POST /posts/{post_id}
    • body { "author": "test author", "text": "test text" }
  2. 설명

    • post idauthor, text를 json으로 입력받아 comment 생성
  3. 결과

    1. 성공 (201)

      • comment가 생성된 post의 id와 comment 정보 return

        {
            "post_id": 123,
            "author": "test author", 
            "text": "test text"
        }
    2. 실패

      1. post_id가 유효하지 않을 때 (404)
        { "message": "post가 없습니다." }

      2. author가 공백일 때 (400)
        { "message": "author가 없습니다." }

      3. text가 공백일 때 (400)
        { "message": "text가 없습니다." }

  4. 테스트

    1. 유효한 post_id입력
    2. 유효하지 않은 post_id입력
    3. author를 미입력
    4. text를 미입력

Comment on lines +55 to +57
comment_list = [{"author": comment.author, "text": comment.text} for comment in comments]

return JsonResponse({"data": comment_list})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nipick,

Suggested change
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]})

변수 선언안해줘도 코드로 인지 가능해서 인라인해서 써줘도 될거 같애~

self.assertEqual(response["message"], "유효하지 않은 사용자 id입니다.")


class TestCommentList(TestPostMixin, TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳 테스트 잘짰네~ ㅋㅋ 👍

Comment on lines +258 to +260
for i in range(comment_count):
comment = self._create_comment_on_post(self.post, f"author{i}", f"comment{i}")
comment.approve()
Copy link
Contributor

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()
...

)


class CommentListCreate(View):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CBV 쓴건 좋은 선택인거 같애~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments