I am trying to test file uploading via DRF. I have found this answer, but this still does not work for me. What am I doing wrong?
from django.core.files.uploadedfile import SimpleUploadedFile
def test_file_post_view_for_superuser(self):
client = APIClient()
this_user = self.superuser
client.force_authenticate(this_user)
new_file = SimpleUploadedFile("file.jpeg", b"file_content", content_type='image/jpeg')
resp = client.post(self.file_list_url,
{'folder': self.folder2.pk,
'file': new_file.name,
'name': 'testf12',
'creator': this_user.pk,
'upload_date': datetime.datetime.now()}, format='json')
self.assertEqual(resp.status_code, 201)
I am getting 400 with error:
ErrorDetail(string='The submitted data was not a file. Check the encoding type on the form.', code='invalid')
Aucun commentaire:
Enregistrer un commentaire