From 61e4f3c5b7a1185e089bee3f88ecd08a807bd388 Mon Sep 17 00:00:00 2001 From: sahayana Date: Tue, 21 Nov 2023 19:08:11 +0900 Subject: [PATCH] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8:=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=EC=83=9D=EC=84=B1=20api=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20=EC=A4=91=EB=B3=B5=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EB=B0=8F=20ImageField=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/account/v1/apis/user_api.py | 5 ++-- tests/account/v1/apis/test_mypage_api.py | 35 ++++++++++++------------ tests/account/v1/apis/test_user_api.py | 27 ++++++++---------- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/apps/account/v1/apis/user_api.py b/apps/account/v1/apis/user_api.py index fe68666..816e45e 100644 --- a/apps/account/v1/apis/user_api.py +++ b/apps/account/v1/apis/user_api.py @@ -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"]) @@ -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} diff --git a/tests/account/v1/apis/test_mypage_api.py b/tests/account/v1/apis/test_mypage_api.py index 036c32b..e71ae3f 100644 --- a/tests/account/v1/apis/test_mypage_api.py +++ b/tests/account/v1/apis/test_mypage_api.py @@ -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() diff --git a/tests/account/v1/apis/test_user_api.py b/tests/account/v1/apis/test_user_api.py index 2d4bedb..1260783 100644 --- a/tests/account/v1/apis/test_user_api.py +++ b/tests/account/v1/apis/test_user_api.py @@ -48,32 +48,29 @@ def test_유저_생성시_transaction_callback_및_메일전송_확인( assert mail.outbox[0].subject == EMAIL_VERIFY_TITLE -def test_유저_생성시_프로필_이미지_업로드_레코드_생성_및_시리얼라이저_데이터_반환(client: Client): - - user = UserFactory.create(email="test_email234@alaltalk.com") - - 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 )