Reputation: 4669
I have a simple ViewSet to represent a model in my database, defined as such
class EventViewSet(viewsets.ModelViewSet)
I have the following code to unit test an HTTP GET request:
client = APIClient()
client.credentials(username="test", password="test")
response = client.get("/api/events/")
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)
My question is this: How do I make the same type of test, but for HTTP delete?
Upvotes: 5
Views: 2812
Reputation: 368904
If you use rest_framework.test.APIClient
, you can use .get()
, .post()
, .put()
, .patch()
, .delete()
, .head()
and .options()
methods.
data = {...}
response = client.delete("/api/events/", data=data)
Upvotes: 4