Skip to content

Commit

Permalink
Add test covering Update view without queryset attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed Sep 10, 2024
1 parent 61e3376 commit 1d11487
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 1d11487

Please sign in to comment.