tests: give an explicit name when creating files (#53755)

Django 2.2.21 introduced the validation of FieldFile.save() name
argument, which cannot contain a path separator anymore.

ref. https://docs.djangoproject.com/en/3.2/releases/2.2.21/
This commit is contained in:
Frédéric Péters 2021-05-13 09:15:24 +02:00
parent 43c7cf6fcc
commit 156ff794f4
2 changed files with 5 additions and 3 deletions

View File

@ -182,7 +182,8 @@ def forwardfile_1(fake_conf, db, atreal_openads, collectivite_1):
orig_filename=os.path.basename(fake_conf['TEST_FILE_CERFA_DIA']),
content_type='application/pdf',
file_hash='ffdf456fdsvgb4bgfb6g4f5b',
upload_file=File(open(fake_conf['TEST_FILE_CERFA_DIA'], 'rb')),
upload_file=File(open(fake_conf['TEST_FILE_CERFA_DIA'], 'rb'),
name=os.path.basename(fake_conf['TEST_FILE_CERFA_DIA'])),
upload_status='pending'
)
@ -200,7 +201,8 @@ def forwardfile_2(fake_conf, connecteur=None, collectivite=None):
orig_filename=os.path.basename(fake_conf['TEST_FILE_CERFA_DIA']),
content_type='application/pdf',
file_hash='ffdf456fdsvgb4bgfb6g4f5b',
upload_file=File(open(fake_conf['TEST_FILE_CERFA_DIA'], 'rb')),
upload_file=File(open(fake_conf['TEST_FILE_CERFA_DIA'], 'rb'),
name=os.path.basename(fake_conf['TEST_FILE_CERFA_DIA'])),
upload_status='pending'
)

View File

@ -76,7 +76,7 @@ def build_forwardfile_from_path(connecteur, path, numero_dossier, type_fichier):
fwd_file.content_type = magic.from_file(path, mime=True)
with open(path, 'rb') as file_pt:
fwd_file.file_hash = get_file_digest(file_pt)
fwd_file.upload_file = File(open(path, 'rb'))
fwd_file.upload_file = File(open(path, 'rb'), name=fwd_file.orig_filename)
fwd_file.upload_status = 'pending'
return fwd_file
return None