def test_patch_own_profile(self):
"""
A user PATCHes their own profile
"""
with mute_signals(post_save):
ProfileFactory.create(user=self.user1, filled_out=False, agreed_to_terms_of_service=False)
self.client.force_login(self.user1)
with mute_signals(post_save):
new_profile = ProfileFactory.create(filled_out=False)
new_profile.user.social_auth.create(
provider=EdxOrgOAuth2.name,
uid="{}_edx".format(new_profile.user.username)
)
patch_data = ProfileSerializer(new_profile).data
del patch_data['image']
resp = self.client.patch(self.url1, content_type="application/json", data=json.dumps(patch_data))
assert resp.status_code == 200
old_profile = Profile.objects.get(user__username=self.user1.username)
for key, value in patch_data.items():
field = ProfileSerializer().fields[key]
if isinstance(field, (ListSerializer, SerializerMethodField, ReadOnlyField)) or field.read_only is True:
# these fields are readonly
continue
elif isinstance(field, DateField):
assert getattr(old_profile, key) == parse(value).date()
else:
assert getattr(old_profile, key) == value
评论列表
文章目录