Skip to content

Commit

Permalink
Add test covering Update view without queryset attribute (#9528)
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed Sep 11, 2024
1 parent 61e3376 commit a59aa2d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_prefetch_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,17 @@ def test_prefetch_related_excluding_instance_from_original_queryset(self):
'email': '[email protected]'
}
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'

0 comments on commit a59aa2d

Please sign in to comment.