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