adullact_pastell: add endpoint to run an action on document (#80835)

This commit is contained in:
Serghei Mihai 2023-09-04 16:14:36 +02:00
parent e549db488f
commit 2916fb7c32
2 changed files with 51 additions and 0 deletions

View File

@ -232,3 +232,32 @@ class AdullactPastell(BaseResource, HTTPResource):
response = HttpResponse(document.content, content_type=document.headers['Content-Type'])
response['Content-Disposition'] = document.headers['Content-disposition']
return response
@endpoint(
post={
'description': _('Run action on document'),
'request_body': {
'schema': {
'application/json': {
'$schema': 'http://json-schema.org/draft-04/schema#',
'type': 'object',
'required': ['action_name'],
'additionalProperties': False,
'properties': {
'action_name': {'type': 'string', 'description': _('Action name')},
},
}
}
},
},
name='run-document-action',
parameters={
'entity_id': {'description': _('Entity ID'), 'example_value': '42'},
'document_id': {'description': _('Document ID'), 'example_value': 'hDWtdSC'},
},
)
def run_document_action(self, request, entity_id, document_id, post_data):
response = self.call(
'entite/%s/document/%s/action/%s' % (entity_id, document_id, post_data['action_name']), 'post'
)
return {'data': response.json()}

View File

@ -343,3 +343,25 @@ def test_get_document_file(app, setup):
assert resp.headers.get('Content-Disposition') == 'attachment; filename=test.txt'
assert resp.headers.get('Content-Type') == 'text/plain'
assert resp.body == b'test'
@responses.activate
def test_run_document_action(app, setup):
responses.add(
responses.POST,
'http://example.com/api/v2/entite/7/document/13fgg3E/action/orientation',
body='{"result": true, "message": "sélection automatique de l\'action suivante"}',
status=200,
)
url = reverse(
'generic-endpoint',
kwargs={'connector': 'adullact-pastell', 'endpoint': 'run-document-action', 'slug': setup.slug},
)
resp = app.post_json(
'%s?entity_id=7&document_id=13fgg3E' % url,
params={'action_name': 'orientation'},
)
print(resp.request.url)
assert resp.json['data']['result']
assert resp.json['data']['message']