python - Iterating the streaming_content attribute on django FileResponse -
i'm working on api django rest framework, , i'm writing unit tests check critical operations. i'm trying read contents of file after doing request
downloaded_file = self.client.get(textfile) the problem object returned of type: django.http.response.fileresponse inherits streaminghttpresponse.
i'm trying iterate on streaming_content attribute, supposedly iterator, cannot iterate, no method next().
i inspected object , map object. ideas on how content request?
edit:
problem solved
the returned object map, map takes function , iterable:
https://docs.python.org/3.4/library/functions.html#map
what had cast map list, access first element of list , convert bytes string. not elegant works.
list(response.streaming_content)[0].decode("utf-8")
here how extract content streaming_content map:
content = downloaded_file.getvalue() looking @ code of getvalue() method, see iterates on answer content:
class streaminghttpresponse(httpresponsebase): ... def getvalue(self): return b''.join(self.streaming_content)
Comments
Post a Comment