My client uses the requests library to make this call to my Django server
import requests
response = requests.post(url, files=dict({
'value': 'key',
}))
This will create a requests that inserts the dictionary into the field request.FILES
as a <MultiValueDict: {}>
I am trying to recreate this with django.test
.
I keep seeing to try something like
from django.test import TestCase, Client
client = Client()
response = client.post('/sign', dict(request_data))
but the request.FILES
object is empty
edit ----
I have also tried with the same result ( request.FILES -> <MultiValueDict: {}>
)
client.post('/sign', {'file': dict({
'key' : 'value'
})})
Edit 2---
A look at the midldleware where I am checking the value
class ApiAuthenticationMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request: HttpRequest):
print(request.FILES)
question from:
https://stackoverflow.com/questions/65940236/django-testing-post-request-with-multipart-form-data-and-a-dictionary 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…