Skip to content

Commit

Permalink
resolve: added test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rolin999 committed Sep 3, 2024
1 parent 2d41b05 commit e6a2fe6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/bk-user/tests/apis/web/personal_center/test_personal_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ def test_update_phone_success(self, api_client, tenant_user):
assert tenant_user.custom_phone_country_code == "86"
assert not tenant_user.is_inherited_phone

def test_update_with_inherited_blank_custom_phone(self, api_client, tenant_user):
tenant_user.custom_phone = "12345678901"
tenant_user.save()

data = {
"is_inherited_phone": "True",
"custom_phone": "",
"custom_phone_country_code": "86",
}

with override_settings(
TENANT_PHONE_UPDATE_RESTRICTIONS={"default": PhoneOrEmailUpdateRestrictionEnum.EDITABLE_DIRECTLY}
):
resp = api_client.put(
reverse("personal_center.tenant_users.phone.update", kwargs={"id": tenant_user.id}), data=data
)
tenant_user.refresh_from_db()
assert resp.status_code == status.HTTP_204_NO_CONTENT
assert tenant_user.custom_phone == "12345678901"
assert tenant_user.custom_phone_country_code == "86"
assert tenant_user.is_inherited_phone

def test_update_phone_not_editable(self, api_client, tenant_user):
data = {
"is_inherited_phone": "False",
Expand Down Expand Up @@ -233,6 +255,26 @@ def test_update_email_success(self, api_client, tenant_user):
assert tenant_user.custom_email == "123456@qq.com"
assert not tenant_user.is_inherited_email

def test_update_with_inherited_blank_custom_email(self, api_client, tenant_user):
tenant_user.custom_email = "123456@qq.com"
tenant_user.save()

data = {
"is_inherited_email": "True",
"custom_email": "",
}

with override_settings(
TENANT_EMAIL_UPDATE_RESTRICTIONS={"default": PhoneOrEmailUpdateRestrictionEnum.EDITABLE_DIRECTLY}
):
resp = api_client.put(
reverse("personal_center.tenant_users.email.update", kwargs={"id": tenant_user.id}), data=data
)
tenant_user.refresh_from_db()
assert resp.status_code == status.HTTP_204_NO_CONTENT
assert tenant_user.custom_email == "123456@qq.com"
assert tenant_user.is_inherited_email

def test_update_email_not_editable(self, api_client, tenant_user):
data = {
"is_inherited_email": "False",
Expand Down

0 comments on commit e6a2fe6

Please sign in to comment.