0

I'm using a Django Unit test to try and test a file download. It works as an API call, with a required token as a GET parameter, but nothing special. Code is:

from django.test.client import Client

c = Client()

base_url = str(sample_download_resource_uri) + '?token=' + str(account_token)
response = c.get(base_url)

if response.status_code != 200:
    return False, "Status code for /download_attachment/XYZ/ is not 200"

The URL is something like: /download_attachment/1/ or /download_attachment/2/

Depending on the file ID.

When I try to run the unit test, in the line:

if response.status_code != 200:

I obtain the error: I/O exception on closed file.

I try the URL from the call in the browser and it works perfectly.

I'm not running the unit test through the tests.py file and tests command, instead using a Django view to remotely unit test the web server. But that shouldn't make a difference because all other non-download unit tests work, for both GET and POST commands.

Aya
  • 39,884
  • 6
  • 55
  • 55

0 Answers0