Following code review

* Move test on UserTest class
* Call `super().update()` in overriding `update` method
This commit is contained in:
Vincent Simonin 2023-11-28 22:40:57 +01:00
parent 220e90e32e
commit 749e86fe91
No known key found for this signature in database
GPG Key ID: 11611F3F005E89B9
2 changed files with 9 additions and 8 deletions

View File

@ -60,7 +60,7 @@ class UserSerializer(ValidatedModelSerializer):
if password is not None: if password is not None:
instance.set_password(password) instance.set_password(password)
instance.save() super().update(instance, validated_data)
return instance return instance

View File

@ -54,24 +54,25 @@ class UserTest(APIViewTestCases.APIViewTestCase):
) )
User.objects.bulk_create(users) User.objects.bulk_create(users)
class ChangeUserPasswordTest(APITestCase):
user_permissions = ['auth.change_user']
def test_that_password_is_changed(self): def test_that_password_is_changed(self):
""" """
Test that password is changed Test that password is changed
""" """
obj_perm = ObjectPermission(
name='Test permission',
actions=['change']
)
obj_perm.save()
obj_perm.users.add(self.user)
obj_perm.object_types.add(ContentType.objects.get_for_model(self.model))
user_credentials = { user_credentials = {
'username': 'user1', 'username': 'user1',
'password': 'abc123', 'password': 'abc123',
} }
user = User.objects.create_user(**user_credentials) user = User.objects.create_user(**user_credentials)
print(user.id)
data = { data = {
'password': 'newpassword' 'password': 'newpassword'
} }