atal_rest: do not expect json when sending attachments (#79332)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Emmanuel Cazenave 2023-07-03 17:36:28 +02:00
parent 84f1b2e728
commit de3d69e2d2
2 changed files with 44 additions and 19 deletions

View File

@ -373,14 +373,14 @@ class AtalREST(BaseResource, HTTPResource):
post_data['file'].get('content_type', ''),
)
}
return {
'data': self._call(
'api/WorksRequests/%s/Attachments' % worksrequests_id,
method='post',
files=files,
)
}
# return nothing if successful
self._call(
'api/WorksRequests/%s/Attachments' % worksrequests_id,
method='post',
files=files,
return_response=True,
)
return {}
@endpoint(
description=_('Add attachments to multiple works requests'),
@ -425,15 +425,15 @@ class AtalREST(BaseResource, HTTPResource):
)
)
data = {'Ids': post_data['worksrequests_ids']}
return {
'data': self._call(
'api/WorksRequests/Attachments',
method='post',
files=files,
data=data,
)
}
# return nothing if successful
self._call(
'api/WorksRequests/Attachments',
method='post',
files=files,
data=data,
return_response=True,
)
return {}
@endpoint(
methods=['get'],

View File

@ -69,7 +69,7 @@ def test_worksrequest_status(app, connector):
def test_worksrequests_single_attachment(app, connector):
with responses.RequestsMock() as rsps:
rsps.post('https://atal.invalid/api/WorksRequests/1/Attachments', status=200, json={})
rsps.post('https://atal.invalid/api/WorksRequests/1/Attachments', status=200, body=b'')
params = {'file': {'filename': 'bla', 'content': base64.b64encode(b'bla').decode('utf-8')}}
resp = app.post_json(
'/atal-rest/test/worksrequests-single-attachment?worksrequests_id=1', params=params
@ -80,7 +80,7 @@ def test_worksrequests_single_attachment(app, connector):
def test_worksrequests_attachments(app, connector):
with responses.RequestsMock() as rsps:
rsps.post('https://atal.invalid/api/WorksRequests/Attachments', status=200, json={})
rsps.post('https://atal.invalid/api/WorksRequests/Attachments', status=200, body=b'')
params = {
'files': [
{'filename': 'bla', 'content': base64.b64encode(b'bla').decode('utf-8')},
@ -93,6 +93,31 @@ def test_worksrequests_attachments(app, connector):
assert json_resp['err'] == 0
def test_worksrequests_attachments_error(app, connector):
with responses.RequestsMock() as rsps:
rsps.post(
'https://atal.invalid/api/WorksRequests/Attachments',
status=400,
json={
'type': 'https://tools.ietf.org/html/rfc7231#section-6.5.1',
'title': 'Bad Request',
'status': 400,
'"detail': 'No content","traceId":"00-1034a23a6cfbb7c508aa7e125a8e9a52-4570fc75745b7d1d-00',
},
)
params = {
'files': [
{'filename': 'bla', 'content': base64.b64encode(b'bla').decode('utf-8')},
{'filename': 'blo', 'content': base64.b64encode(b'blo').decode('utf-8')},
],
'worksrequests_ids': ['0', '1'],
}
resp = app.post_json('/atal-rest/test/worksrequests-attachments', params=params)
json_resp = resp.json
assert json_resp['err'] == 1
assert json_resp['data']['title'] == 'Bad Request'
def test_thirdparties_requesting_departments(app, connector):
with responses.RequestsMock() as rsps:
query_params = {'RequestType': '1001'}