toulouse-foederis: use multipart/form-data to attach files & diplomas (#82291)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
92f5b5f26b
commit
a3db9b1e35
|
@ -687,7 +687,7 @@ class Resource(BaseResource, HTTPResource):
|
|||
self.http_request(
|
||||
'POST',
|
||||
f'data/candidature/{application_id}/fields/{attachment_name}?viewIntegrationName=api_publik',
|
||||
json={
|
||||
files={
|
||||
'contentType': file['content_type'],
|
||||
'value': file['content'],
|
||||
'fileName': file['filename'],
|
||||
|
@ -719,7 +719,7 @@ class Resource(BaseResource, HTTPResource):
|
|||
self.http_request(
|
||||
'POST',
|
||||
f'data/diplome2/{degree_id}/fields/justificatif_diplome?viewIntegrationName=api_publik',
|
||||
json={
|
||||
files={
|
||||
'contentType': file['content_type'],
|
||||
'value': file['content'],
|
||||
'fileName': file['filename'],
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import base64
|
||||
import cgi
|
||||
import json
|
||||
import os
|
||||
import urllib.parse
|
||||
from io import BytesIO
|
||||
|
||||
import httmock
|
||||
import pytest
|
||||
|
@ -584,13 +586,18 @@ class TestEndpoints:
|
|||
def test_attach_file(self, resource, app):
|
||||
@httmock.urlmatch(path=r'^.*/data/candidature/424242/fields/cv$')
|
||||
def handler(url, request):
|
||||
assert request.headers['content-type'] == 'application/json'
|
||||
assert request.headers['content-type'].startswith('multipart/form-data')
|
||||
assert request.headers['api-key'] == APIKEY
|
||||
payload = json.loads(request.body)
|
||||
|
||||
_, headers = cgi.parse_header(request.headers['content-type'])
|
||||
headers['boundary'] = bytes(headers['boundary'], 'utf-8')
|
||||
headers['CONTENT-LENGTH'] = request.headers['Content-Length']
|
||||
payload = cgi.parse_multipart(BytesIO(request.body), headers)
|
||||
|
||||
assert payload == {
|
||||
'contentType': 'application/pdf',
|
||||
'value': 'base 64 content',
|
||||
'fileName': 'cv.pdf',
|
||||
'contentType': [b'application/pdf'],
|
||||
'value': [b'base 64 content'],
|
||||
'fileName': [b'cv.pdf'],
|
||||
}
|
||||
|
||||
return httmock.response(200, json.dumps({'code': 200, 'results': ['Field updated']}))
|
||||
|
@ -630,13 +637,18 @@ class TestEndpoints:
|
|||
|
||||
@httmock.urlmatch(path=r'^.*/data/diplome2/DEGREE_ID/fields/justificatif_diplome$')
|
||||
def degree_file_handler(url, request):
|
||||
assert request.headers['content-type'] == 'application/json'
|
||||
assert request.headers['content-type'].startswith('multipart/form-data')
|
||||
assert request.headers['api-key'] == APIKEY
|
||||
payload = json.loads(request.body)
|
||||
|
||||
_, headers = cgi.parse_header(request.headers['content-type'])
|
||||
headers['boundary'] = bytes(headers['boundary'], 'utf-8')
|
||||
headers['CONTENT-LENGTH'] = request.headers['Content-Length']
|
||||
payload = cgi.parse_multipart(BytesIO(request.body), headers)
|
||||
|
||||
assert payload == {
|
||||
'contentType': 'application/pdf',
|
||||
'value': 'base 64 content',
|
||||
'fileName': 'cv.pdf',
|
||||
'contentType': [b'application/pdf'],
|
||||
'value': [b'base 64 content'],
|
||||
'fileName': [b'cv.pdf'],
|
||||
}
|
||||
|
||||
return httmock.response(200, json.dumps({'code': 200, 'results': [{'id': 'DEGREE_ID'}]}))
|
||||
|
|
Loading…
Reference in New Issue