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.

Handling image uploads in a unit test

Handling image uploads in a unit test

From the course: Building RESTful Web APIs with Django

Start my 1-month free trial

Handling image uploads in a unit test

- [Man] We're able to update the product, so let's test updating a product with a new product image upload. We begin by importing OS.Path, since we are dealing with files and images. And we're going to import Django settings. And then we go to the product update Test Case, and we add a New Test Case to it, for Upload Product Photo. We're going to use the first product in the database. We're going to store the original photo. And then we're going to create the Path to the new photo, and just re-use an existing product photo from our Media Root. And then, with that photo, Path open, going to to store that photo data, and use it to update the product photo. And the format is not Json, but it is Multipart because it is an upload. And immediately after that, we're going to be checking to ensure that the Response Status Code was a 200 and okay. After that, we want to make sure that the photo from the response is no longer the original photo. We also want to try an assertion here, we're…

Contents