mdel: fix status endpoint with incorrect zipfile (#78917)
gitea/passerelle/pipeline/head There was a failure building this commit Details

This commit is contained in:
Lauréline Guérin 2023-06-22 16:56:15 +02:00 committed by Lauréline Guérin
parent 468e5309a9
commit fb01b9a9ec
2 changed files with 12 additions and 1 deletions

View File

@ -16,6 +16,7 @@
import json
import os
import zipfile
from django.db import models
from django.utils.translation import gettext_lazy as _
@ -417,7 +418,10 @@ class Demand(models.Model):
path = os.path.join(self.resource.output_dir, zip_file)
content = get_file_content_from_zip(path, 'message.xml')
try:
content = get_file_content_from_zip(path, 'message.xml')
except zipfile.BadZipFile:
raise APIError('zipfile error')
element = mdel.etree.fromstring(content)
majs = element.findall('ns2:Body/*/*/*/ns2:Maj', namespace)

View File

@ -551,6 +551,13 @@ def test_get_status(app, setup):
assert data['comment'] == 'Dossier accepté'
assert Demand.objects.get(demand_id='102-2-AEC-LA').status == 'accepted'
# bad zipfile
filepath = os.path.join(get_resource_base_dir(), 'test', 'outputs', '102-2-aec-la--4.zip')
with open(filepath, 'w') as f:
f.write(' ')
resp = app.get('/mdel/test/status', params={'demand_id': '102-2-AEC-LA'}, status=200)
assert resp.json['err_desc'] == 'zipfile error'
def test_get_status_unknown_demand(app, setup):
resp = app.get('/mdel/test/status', params={'demand_id': '1-14-ILE-LA'})