atal_rest: expand data returned by worksrequest-status (#87630)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
1570ba1f3f
commit
b35b0fccd3
|
@ -494,12 +494,32 @@ class AtalREST(BaseResource, HTTPResource):
|
|||
parameters={
|
||||
'worksrequests_id': {
|
||||
'example_value': '1',
|
||||
}
|
||||
},
|
||||
'filter_responses': {
|
||||
'example_value': '501,507',
|
||||
},
|
||||
},
|
||||
)
|
||||
def worksrequest_status(self, request, worksrequests_id):
|
||||
resp_data = self._call('api/WorksRequests/%s' % worksrequests_id)
|
||||
def worksrequest_status(self, request, worksrequests_id, filter_responses=None):
|
||||
filter_responses = (
|
||||
[type_id.strip() for type_id in filter_responses.split(',') if type_id.strip()]
|
||||
if filter_responses
|
||||
else []
|
||||
)
|
||||
action_type_ids = []
|
||||
for type_id in filter_responses:
|
||||
try:
|
||||
action_type_ids.append(int(type_id))
|
||||
except ValueError:
|
||||
raise APIError('filter_responses must be a list of integer')
|
||||
|
||||
resp_data = self._call('api/WorksRequests/%s' % worksrequests_id, params={'$expand': 'Responses'})
|
||||
resp_data['RequestStateLabel'] = STATUS_MAP.get(resp_data.get('RequestState', ''), '')
|
||||
if action_type_ids:
|
||||
responses = resp_data.pop('Responses', [])
|
||||
resp_data['Responses'] = [
|
||||
resp for resp in responses if resp.get('ActionTypeId') in action_type_ids
|
||||
] or []
|
||||
return {'data': resp_data}
|
||||
|
||||
@endpoint(
|
||||
|
|
|
@ -81,6 +81,50 @@ def test_worksrequest_status(app, connector):
|
|||
assert json_resp['data']['status'] == 'foo'
|
||||
assert json_resp['data']['RequestState'] == 0
|
||||
assert json_resp['data']['RequestStateLabel'] == 'En attente'
|
||||
assert rsps.calls[0].request.params == {'$expand': 'Responses'}
|
||||
|
||||
|
||||
def test_worksrequest_status_filter_responses(app, connector):
|
||||
with responses.RequestsMock() as rsps:
|
||||
rsps.get(
|
||||
'https://atal.invalid/api/WorksRequests/1',
|
||||
status=200,
|
||||
json={
|
||||
'status': 'foo',
|
||||
'RequestState': 0,
|
||||
'Responses': [
|
||||
{
|
||||
'ActionTypeId': 501,
|
||||
'Description': 'Foo',
|
||||
},
|
||||
{
|
||||
'ActionTypeId': 507,
|
||||
'Description': 'Foo',
|
||||
},
|
||||
{
|
||||
'ActionTypeId': 516,
|
||||
'Description': 'Baz',
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
resp = app.get('/atal-rest/test/worksrequest-status?worksrequests_id=1&filter_responses=501,507')
|
||||
json_resp = resp.json
|
||||
assert json_resp['err'] == 0
|
||||
assert json_resp['data']['status'] == 'foo'
|
||||
assert json_resp['data']['RequestState'] == 0
|
||||
assert json_resp['data']['RequestStateLabel'] == 'En attente'
|
||||
assert json_resp['data']['Responses'] == [
|
||||
{
|
||||
'ActionTypeId': 501,
|
||||
'Description': 'Foo',
|
||||
},
|
||||
{
|
||||
'ActionTypeId': 507,
|
||||
'Description': 'Foo',
|
||||
},
|
||||
]
|
||||
assert rsps.calls[0].request.params == {'$expand': 'Responses'}
|
||||
|
||||
|
||||
def test_worksrequest_intervention_status(app, connector):
|
||||
|
|
Loading…
Reference in New Issue