Add test covering Update view without queryset attribute (#9528)

This commit is contained in:
Bruno Alla 2024-09-11 10:37:33 +01:00 committed by GitHub
parent 61e33761eb
commit a59aa2dfe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -56,3 +56,17 @@ class TestPrefetchRelatedUpdates(TestCase):
'email': 'tom@example.com' 'email': 'tom@example.com'
} }
assert response.data == expected assert response.data == expected
def test_can_update_without_queryset_on_class_view(self):
class UserUpdateWithoutQuerySet(generics.UpdateAPIView):
serializer_class = UserSerializer
def get_object(self):
return User.objects.get(pk=self.kwargs['pk'])
request = factory.patch('/', {'username': 'new'})
response = UserUpdateWithoutQuerySet.as_view()(request, pk=self.user.pk)
assert response.data['id'] == self.user.id
assert response.data['username'] == 'new'
self.user.refresh_from_db()
assert self.user.username == 'new'