Skip to content

Commit

Permalink
테스트: 유저생성 api 테스트 이메일 중복 오류 및 ImageField 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahayana committed Nov 21, 2023
1 parent a80d238 commit 61e4f3c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
5 changes: 3 additions & 2 deletions apps/account/v1/apis/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def post(self, request, *args, **kwargs):
request_data = request.data.copy()

if request.data.get("img"):
request_data.update({"profile_image": request.data["img"]})
profile_image = request.data["img"]
request_data.update({"profile_image": profile_image})

is_present = UserSelector.check_email_duplication(email=request_data["email"])

Expand All @@ -62,7 +63,7 @@ def post(self, request, *args, **kwargs):
nickname=validated_data["nickname"],
bio=validated_data["bio"],
password=validated_data["password"],
img=validated_data.get("profile_image", None),
img=validated_data.get("profile_image"),
)

data = {"msg": "sent", "user": UserReadSerializer(instance=user).data}
Expand Down
35 changes: 17 additions & 18 deletions tests/account/v1/apis/test_mypage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,32 +93,31 @@ def test_유저_마이페이지_유튜브_뉴스_책_쇼핑_데이터_반환(cli
)


# def test_유저_회원정보_이미지_제외한_정보_업데이트(client: Client):
def test_유저_회원정보_이미지_제외한_정보_업데이트(client: Client):

# user = UserFactory.create(is_active=True)

# nickname = "updated"
user = UserFactory.create(is_active=True)

# data = {
# "nickname": nickname
# }
nickname = "updated"

# res = client.patch(f"/account/v1/mypage/{user.id}/",
# **authorization_header(user),
# data=data,
# content_type="application/json")
data = {"nickname": nickname}

res = client.post(
reverse("account:v1:mypage-list"),
**authorization_header(user),
data=data,
media_type="multipart/form-data"
)

# res_data = res.data['data']
res_data = res.data["data"]

# assert res.status_code == status.HTTP_200_OK
# assert res.data['msg'] == 'ok'
# assert res_data['nickname'] == nickname
# assert res_data['email'] == user.email
# assert res_data['bio'] == user.bio
assert res.status_code == status.HTTP_200_OK
assert res.data["msg"] == "ok"
assert res_data["nickname"] == nickname
assert res_data["email"] == user.email
assert res_data["bio"] == user.bio


def test_유저_회원정보_프로필_이미지_업데이트_확인(client: Client, get_test_image):
def test_유저_회원정보_프로필_이미지_업데이트_확인(client: Client):

user = UserFactory.create(is_active=True)
user_img = UserProfileImageFactory.create()
Expand Down
27 changes: 12 additions & 15 deletions tests/account/v1/apis/test_user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,29 @@ def test_유저_생성시_transaction_callback_및_메일전송_확인(
assert mail.outbox[0].subject == EMAIL_VERIFY_TITLE


def test_유저_생성시_프로필_이미지_업로드_레코드_생성_및_시리얼라이저_데이터_반환(client: Client):

user = UserFactory.create(email="[email protected]")

user_image = UserProfileImageFactory.create()
def test_유저_생성시_프로필_이미지_업로드_레코드_생성_및_시리얼라이저_데이터_반환(
client: Client, create_user_data: Callable, get_test_image
):

data = {
"email": user.email,
"password": user.password,
"nickname": user.nickname,
"bio": user.bio,
}
user = UserFactory.build()

data.update({"img": user_image.img})
data = create_user_data(user)
data.update({"img": get_test_image})

res = client.post(
reverse("account:v1:signup"), data=data, media_type="multipart/form-data"
)

assert res.data is None
assert res.status_code == status.HTTP_201_CREATED
assert res.data["user"]["email"] == user.email
assert UserProfileImage.objects.filter(user=user).exists() is True
assert (
UserProfileImage.objects.filter(user_id=res.data["user"]["id"]).exists() is True
)
assert (
res.data["user"]["profile_image"]
== UserProfileImage.objects.get(user_id=user.id).img
== UserProfileImage.objects.filter(user_id=res.data["user"]["id"])
.first()
.img.url
)


Expand Down

0 comments on commit 61e4f3c

Please sign in to comment.