Mock in Django a Binary file retrieved from an API

Viewed 23

I'm using Django and DRF, and I have a view that retrieves a Binary File (Using BinaryFileRenderer) from an external API. This external API brings the binary data from S3.

I need to mock this call so I could test the logic by isolating the API call, but every time I tried I received some error. For example, I tried creating a MockFile class with content, mime_type, and name fields. And I started to receive the error "AssertionError: renderer returned Unicode, and did not specify a charset value."

After some investigation, apparently, it was expecting some kind of Renderer file. But this is when I got confused. Because Python is dynamic, I'm never sure what kind of file I received and I'm not sure how I can mock the binary file I'm receiving.

Anyone can point me to how correctly mock this binary file?

0 Answers
Related