From a59aa2dfe195dcc22aca18d2a1d6995bbeb38186 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 11 Sep 2024 10:37:33 +0100 Subject: [PATCH] Add test covering Update view without queryset attribute (#9528) --- tests/test_prefetch_related.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_prefetch_related.py b/tests/test_prefetch_related.py index b07087c978..12ecbf2e6a 100644 --- a/tests/test_prefetch_related.py +++ b/tests/test_prefetch_related.py @@ -56,3 +56,17 @@ def test_prefetch_related_excluding_instance_from_original_queryset(self): 'email': 'tom@example.com' } 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'