mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 10:03:57 +03:00
Add test covering Update view without queryset attribute (#9528)
This commit is contained in:
parent
61e33761eb
commit
a59aa2dfe1
|
@ -56,3 +56,17 @@ class TestPrefetchRelatedUpdates(TestCase):
|
|||
'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'
|
||||
|
|
Loading…
Reference in New Issue
Block a user