Skip to content
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

Open
wants to merge 8 commits into
base: legacy
Choose a base branch
from
Open

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

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

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

@@ -43,3 +42,31 @@ def retrieve_post_detail(request, id):
},
status=200,
)


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