@pytest.mark.django_db
def test_apiview_delete(rf):
 view = UserAPIView.as_view()
 user = UserFactory.create(username='foo')
 request = create_api_request(rf, 'delete')
 response = view(request)
 assert (response.status_code == 405)
 assert (User.objects.filter(id=user.id).count() == 1)
 response = view(request, id=user.id)
 assert (response.status_code == 200)
 assert (User.objects.filter(id=user.id).count() == 0)
 with pytest.raises(Http404):
  view(request, id=user.id)

@ pytest . mark . django_db def test_apiview_delete ( rf ) : view = UserAPIView . as_view ( ) user = UserFactory . create ( username = 'foo' ) request = create_api_request ( rf , 'delete' ) response = view ( request ) assert ( response . status_code == 405 ) assert ( User . objects . filter ( id = user . id ) . count ( ) == 1 ) response = view ( request , id = user . id ) assert ( response . status_code == 200 ) assert ( User . objects . filter ( id = user . id ) . count ( ) == 0 ) with pytest . raises ( Http404 ) : view ( request , id = user . id )
tests deleting an object using the api .