From the course: Building RESTful Web APIs with Django

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Test case for a DestroyAPIView subclass

Test case for a DestroyAPIView subclass

From the course: Building RESTful Web APIs with Django

Start my 1-month free trial

Test case for a DestroyAPIView subclass

- [Narrator] We tested creating products through the API, so let's test destroying and deleting products through the API. We write a new test case (typing) for ProductDestroy. (typing) We're going to be checking the product count... (typing) and making sure that the product doesn't exist anymore (typing) after we delete it. So we use the client, called the delete method, on it, (typing) and then we make sure that there's one less object in the database. (typing) And we also make sure that if we try and retrieve that particular product, it no longer exists. (typing) In the real world, we would also check to ensure that caches or any other data related to the product model are also destroyed and cleaned up. So now let's run the test. (typing) It looks like all test paths and products can be deleted.

Contents