How to unit test an HTTP delete with Django Rest Framework
django, django-rest-framework, python, unit-testing
Solution
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)
Problem
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?