I want to test a view that is suppose to receive files attached with the request. my django test:
TEST_DIR = "myapp/tests/test_data/"
file_name = "some_resume.pdf"
email_data = {
"sender": "somedude@someprovidercom",
"recipient": "someotherdude@someotherprovider.com",
"subject": "New candidate",
"stripped-html": "Check out this new candidate."
}
api = APIClient()
with open(FILE_DIR + file_name, "rb") as fp:
response = api.post(
"/api/v1.0/emails/receive/",
data=email_data,
files={"resume": fp}, # pass file handler open with byte mode
format="multipart", # use multipart format
)
print(response)
# test some stuff
the api response is correct: <Response status_code=200, "application/json">
but when I print the files attached to the request in the View I get nothing:
print(request.FILES)
# <MultiValueDict: {}>
I checked everywhere and the format for my api request looks file.
Also, my view works fine when I test with shell sending request with with python requests
library.
Am I missing anything? Could id be somehow related to my test environment or some obscure middlewares?