From 1d11487c36e76b444ca59c5d74ae3959cfe9d8cf Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 10 Sep 2024 22:11:29 +0100 Subject: [PATCH] Add test covering Update view without queryset attribute --- 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'