toulouse-foederis: allow empty degree files (#82390)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Corentin Sechet 2023-10-16 10:13:50 +02:00
parent 3d5ec0268c
commit 76f3860ad2
2 changed files with 47 additions and 29 deletions

View File

@ -35,7 +35,7 @@ ATTACHMENT_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#', '$schema': 'http://json-schema.org/draft-04/schema#',
'title': _('Attachment and degree data.'), 'title': _('Attachment and degree data.'),
'description': '', 'description': '',
'required': ['application_id', 'name', 'file'], 'required': ['application_id', 'name'],
'type': 'object', 'type': 'object',
'properties': { 'properties': {
'application_id': { 'application_id': {
@ -56,22 +56,27 @@ ATTACHMENT_SCHEMA = {
}, },
'file': { 'file': {
'description': _('File to attach.'), 'description': _('File to attach.'),
'type': 'object', 'oneOf': [
'required': ['filename', 'content_type', 'content'], {
'properties': { 'type': 'object',
'filename': { 'required': ['filename', 'content_type', 'content'],
'description': _('File name'), 'properties': {
'type': 'string', 'filename': {
'description': _('File name'),
'type': 'string',
},
'content_type': {
'description': _('MIME type'),
'type': 'string',
},
'content': {
'description': _('Content'),
'type': 'string',
},
},
}, },
'content_type': { {'type': 'null'},
'description': _('MIME type'), ],
'type': 'string',
},
'content': {
'description': _('Content'),
'type': 'string',
},
},
}, },
}, },
} }
@ -705,7 +710,7 @@ class Resource(BaseResource, HTTPResource):
def attach_degree(self, request, post_data): def attach_degree(self, request, post_data):
application_id = post_data['application_id'] application_id = post_data['application_id']
degree_label = post_data['name'] degree_label = post_data['name']
file = post_data['file'] file = post_data.get('file')
degree_data = self.http_request( degree_data = self.http_request(
'POST', 'POST',
@ -715,17 +720,18 @@ class Resource(BaseResource, HTTPResource):
degree_id = degree_data[0]['id'] degree_id = degree_data[0]['id']
self.http_request( if file is not None:
'POST', self.http_request(
f'data/diplome2/{degree_id}/fields/justificatif_diplome?viewIntegrationName=api_publik', 'POST',
data={ f'data/diplome2/{degree_id}/fields/justificatif_diplome?viewIntegrationName=api_publik',
'contentType': file['content_type'], data={
'fileName': file['filename'], 'contentType': file['content_type'],
}, 'fileName': file['filename'],
files={ },
'value': (None, file['content'], None), files={
}, 'value': (None, file['content'], None),
) },
)
return {'err': 0} return {'err': 0}

View File

@ -665,7 +665,19 @@ class TestEndpoints:
}, },
) )
assert response.json['err'] == 0 assert response.json['err'] == 0
with httmock.HTTMock(create_degree_handler, degree_file_handler, error_handler):
response = app.post_json(
'/toulouse-foederis/foederis/attach-degree',
params={
'application_id': '424242',
'name': 'DUT anarchisme',
'file': None,
},
)
assert response.json['err'] == 0
def test_migration_0003_no_null_no_charfield(migration): def test_migration_0003_no_null_no_charfield(migration):