From 749e86fe91f5c898434f3fdfa5f7a7b5da760b2d Mon Sep 17 00:00:00 2001 From: Vincent Simonin Date: Tue, 28 Nov 2023 22:40:57 +0100 Subject: [PATCH] Following code review * Move test on UserTest class * Call `super().update()` in overriding `update` method --- netbox/users/api/serializers.py | 2 +- netbox/users/tests/test_api.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/netbox/users/api/serializers.py b/netbox/users/api/serializers.py index 8d3bffba4..3bb098beb 100644 --- a/netbox/users/api/serializers.py +++ b/netbox/users/api/serializers.py @@ -60,7 +60,7 @@ class UserSerializer(ValidatedModelSerializer): if password is not None: instance.set_password(password) - instance.save() + super().update(instance, validated_data) return instance diff --git a/netbox/users/tests/test_api.py b/netbox/users/tests/test_api.py index a43077442..090ccc263 100644 --- a/netbox/users/tests/test_api.py +++ b/netbox/users/tests/test_api.py @@ -54,24 +54,25 @@ class UserTest(APIViewTestCases.APIViewTestCase): ) User.objects.bulk_create(users) - -class ChangeUserPasswordTest(APITestCase): - - user_permissions = ['auth.change_user'] - def test_that_password_is_changed(self): """ 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 = { 'username': 'user1', 'password': 'abc123', } user = User.objects.create_user(**user_credentials) - print(user.id) - data = { 'password': 'newpassword' }