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(
|
self.http_request(
|
||||||
'POST',
|
'POST',
|
||||||
f'data/candidature/{application_id}/fields/{attachment_name}?viewIntegrationName=api_publik',
|
f'data/candidature/{application_id}/fields/{attachment_name}?viewIntegrationName=api_publik',
|
||||||
json={
|
files={
|
||||||
'contentType': file['content_type'],
|
'contentType': file['content_type'],
|
||||||
'value': file['content'],
|
'value': file['content'],
|
||||||
'fileName': file['filename'],
|
'fileName': file['filename'],
|
||||||
|
@ -719,7 +719,7 @@ class Resource(BaseResource, HTTPResource):
|
||||||
self.http_request(
|
self.http_request(
|
||||||
'POST',
|
'POST',
|
||||||
f'data/diplome2/{degree_id}/fields/justificatif_diplome?viewIntegrationName=api_publik',
|
f'data/diplome2/{degree_id}/fields/justificatif_diplome?viewIntegrationName=api_publik',
|
||||||
json={
|
files={
|
||||||
'contentType': file['content_type'],
|
'contentType': file['content_type'],
|
||||||
'value': file['content'],
|
'value': file['content'],
|
||||||
'fileName': file['filename'],
|
'fileName': file['filename'],
|
||||||
|
|
|
@ -15,9 +15,11 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import cgi
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import httmock
|
import httmock
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -584,13 +586,18 @@ class TestEndpoints:
|
||||||
def test_attach_file(self, resource, app):
|
def test_attach_file(self, resource, app):
|
||||||
@httmock.urlmatch(path=r'^.*/data/candidature/424242/fields/cv$')
|
@httmock.urlmatch(path=r'^.*/data/candidature/424242/fields/cv$')
|
||||||
def handler(url, request):
|
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
|
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 == {
|
assert payload == {
|
||||||
'contentType': 'application/pdf',
|
'contentType': [b'application/pdf'],
|
||||||
'value': 'base 64 content',
|
'value': [b'base 64 content'],
|
||||||
'fileName': 'cv.pdf',
|
'fileName': [b'cv.pdf'],
|
||||||
}
|
}
|
||||||
|
|
||||||
return httmock.response(200, json.dumps({'code': 200, 'results': ['Field updated']}))
|
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$')
|
@httmock.urlmatch(path=r'^.*/data/diplome2/DEGREE_ID/fields/justificatif_diplome$')
|
||||||
def degree_file_handler(url, request):
|
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
|
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 == {
|
assert payload == {
|
||||||
'contentType': 'application/pdf',
|
'contentType': [b'application/pdf'],
|
||||||
'value': 'base 64 content',
|
'value': [b'base 64 content'],
|
||||||
'fileName': 'cv.pdf',
|
'fileName': [b'cv.pdf'],
|
||||||
}
|
}
|
||||||
|
|
||||||
return httmock.response(200, json.dumps({'code': 200, 'results': [{'id': 'DEGREE_ID'}]}))
|
return httmock.response(200, json.dumps({'code': 200, 'results': [{'id': 'DEGREE_ID'}]}))
|
||||||
|
|
Loading…
Reference in New Issue