Django Rest Framework - Unit test image file upload
<p>I am trying to unit test my file uploading REST API. I found online some code generating the image with Pillow but it can't be serialized.</p>

<p>This is my code for generating the image :</p>

<pre><code>image = Image.new('RGBA', size=(50, 50), color=(155, 0, 0))
file = BytesIO(image.tobytes())
file.name = 'test.png'
file.seek(0)
</code></pre>

<p>Then I try to upload this image fille :</p>

<pre><code>return self.client.post("/api/images/", data=json.dumps({
     "image": file,
     "item": 1
}), content_type="application/json", format='multipart')
</code></pre>

<p>And I get the following error:</p>

<pre><code>&lt;ContentFile: Raw content&gt; is not JSON serializable
</code></pre>

<p>How can I transform the Pillow image so it's serializable?</p>