Replies: 4 comments 1 reply
-
.json()이 실제 클라이언트가 마주하는 응답값과 유사하므로 .json()을 사용하는 것은 어떨까요? |
Beta Was this translation helpful? Give feedback.
-
API 테스트가 end to end test인가?서비스를 모킹, 입력과 출력부만 테스트 client 생성 방법pyest client (객체 django client와 동일) API 테스트 필수 사항
|
Beta Was this translation helpful? Give feedback.
-
테스트 코드 가독성을 좋게 만들면 테스트에 관심을 가지게 되지 않을까? |
Beta Was this translation helpful? Give feedback.
-
Factory를 보완하여 자주 사용되는 객체를 한 방에 생성해주는 기능을 제공하자. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
JSON을 반환하는 API 테스트를 할 때 rest_framework.test.APIClient 혹은 django.test.Client 객체(이하 client 객체)를 활용하여 응답 결과를 비교합니다.
client의 get()/post()/put()/patch()/delete() 같은 메서드의 반환 값을 response라 할 때, response에서 API 응답 JSON을 가져오는 방법이 두 가지 있습니다.
response.data
response.json()
아래는
/my-api/
라는 가상의 API에 대한 테스트 예제입니다.위 예제에서처럼
.data
와.json()
에는 두 가지 차이가 있습니다..json()
에는 settings에 설정된 CamelCaseJSONRenderer가 적용되나.data
는 아님.json()
은 직렬화된 결과가 담기나.data
에는 직렬화되기 전 파이썬 객체가 담김직렬화 및 Renderer의 테스트 범위 포함 여부에 따라 적절한 방법을 선택하면 좋을 것 같습니다.
Beta Was this translation helpful? Give feedback.
All reactions