api_views: set extension of validation attachment from mime_type (#29508)
This commit is contained in:
parent
eabdb36bf5
commit
2c5563ee91
|
@ -128,12 +128,14 @@ def validate_cut(self, request, uuid):
|
|||
'max-size': max_size,
|
||||
})
|
||||
accepted_mime_types = _get_cut_validation_accepted_mime_types()
|
||||
if magic.from_buffer(content.read(10000), mime=True) not in accepted_mime_types:
|
||||
mime_type = magic.from_buffer(content.read(10000), mime=True)
|
||||
if mime_type not in accepted_mime_types:
|
||||
errors.append({
|
||||
'code': 'justificatifs-bad-format',
|
||||
'page': i,
|
||||
'accepted': accepted_mime_types,
|
||||
})
|
||||
content.name = content.name.rsplit('.', 1)[0] + '.' + mime_type.rsplit('/', 1)[1]
|
||||
# rewind cursor
|
||||
content.seek(0)
|
||||
if models.ValidationRequest.objects.filter(
|
||||
|
|
|
@ -7,6 +7,7 @@ import pytest
|
|||
import pathlib2
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from authentic2_cut import models
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
@ -67,7 +68,7 @@ def pdf_file():
|
|||
yield fd.read()
|
||||
|
||||
|
||||
def helper_test_validation_image(glc_app, john, image_file):
|
||||
def helper_test_validation_image(glc_app, john, image_file, extension):
|
||||
external_id = uuid.uuid4().hex
|
||||
response = glc_app.post_json('/api/users/%s/validate/' % john._oidc_sub, params={
|
||||
'external_id': external_id,
|
||||
|
@ -82,15 +83,18 @@ def helper_test_validation_image(glc_app, john, image_file):
|
|||
'external_id': external_id,
|
||||
'sub': john._oidc_sub,
|
||||
}
|
||||
validation_request = models.ValidationRequest.objects.get(id=response.json['id'])
|
||||
attachment = models.ValidationRequestAttachment.objects.get(validation_request=validation_request)
|
||||
assert attachment.image.name.endswith(extension)
|
||||
|
||||
|
||||
def test_validation_jpg(glc_app, john, jpeg_file):
|
||||
helper_test_validation_image(glc_app, john, jpeg_file)
|
||||
helper_test_validation_image(glc_app, john, jpeg_file, 'jpeg')
|
||||
|
||||
|
||||
def test_validation_png(glc_app, john, png_file):
|
||||
helper_test_validation_image(glc_app, john, png_file)
|
||||
helper_test_validation_image(glc_app, john, png_file, 'png')
|
||||
|
||||
|
||||
def test_validation_pdf(glc_app, john, pdf_file):
|
||||
helper_test_validation_image(glc_app, john, pdf_file)
|
||||
helper_test_validation_image(glc_app, john, pdf_file, 'pdf')
|
||||
|
|
Loading…
Reference in New Issue