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.

Unit test for an UpdateAPIView subclass

Unit test for an UpdateAPIView subclass

From the course: Building RESTful Web APIs with Django

Start my 1-month free trial

Unit test for an UpdateAPIView subclass

- [Narrator] Now let's test updating a product. We write another API test case. And this one is going to be using the PATCH method for partially updating the model. Going to grab the first product, and then, we call PATCH from the client, pointing to that specific product's API URL. We're going to be updating the name to new product, updating the description, and then updating the price. Format of the request is JSON, and then we retrieve the updated product from the database, and we're going to make sure that the name has actually updated. Now let's run the test and see what happens. It looks like the product's data doesn't update. So let's try and fix this. Let's go to the serializers, and it looks like an issue with the product serializer, and in the UPDI method, it looks like we update the data with the warranty information, but then we actually forget to call the super method, so that the product is updated correctly. So let's do that now. Now with this change, let's try running…

Contents