atal: return works comment and hide raw data (#37669)

This commit is contained in:
Emmanuel Cazenave 2019-11-14 19:39:53 +01:00
parent 336b49b7fd
commit 9c68cf8d4a
2 changed files with 41 additions and 15 deletions

View File

@ -201,10 +201,15 @@ class ATALConnector(BaseResource):
parameters={
'demand_number': {
'description': _('Demande number'), 'example_value': 'DIT18050001'
},
'full': {
'description': _('Full'),
'example_value': 'true',
'type': 'bool',
}
}
)
def infos(self, request, demand_number):
def infos(self, request, demand_number, full=False):
demand_details = helpers.serialize_object(
self._soap_call(
wsdl='DemandeService', method='retrieveDetailsDemande',
@ -218,7 +223,7 @@ class ATALConnector(BaseResource):
raise APIError('Could not get a status')
responses = (demand_details.get('reponses') or {}).get('Reponse') or []
comments = []
demand_comments = []
if responses:
for response in responses:
comment = {
@ -227,22 +232,25 @@ class ATALConnector(BaseResource):
}
if 'dateReponse' in response:
comment['date'] = dateformat.format(response['dateReponse'], DATE_FORMAT)
comments.append(comment)
demand_comments.append(comment)
last_comment = {
demand_comment = {
'text': None,
'date': None
}
if comments:
last_comment = comments[-1]
if demand_comments:
demand_comment = demand_comments[-1]
data = {
'status': status,
'demand_details': demand_details,
'comments': comments,
'last_comment': last_comment,
'demand_comment': demand_comment,
'demand_details': None,
'demand_comments': []
}
if full:
data['demand_details'] = demand_details
data['demand_comments'] = demand_comments
if status not in ('PRISE EN COMPTE', 'ARCHIVEE'):
return {
'data': data
@ -258,8 +266,13 @@ class ATALConnector(BaseResource):
if not status:
raise APIError('Could not get a status')
data['works_status'] = works_status
data['status'] = status
data['works_comment'] = works_status.get('commentaires', '')
data['works_status'] = None
if full:
data['works_status'] = works_status
return {
'data': data
}

View File

@ -298,9 +298,22 @@ def test_infos(app, connector, monkeypatch):
assert response.json['err'] == 0
data = response.json['data']
assert data['status'] == u'travaux pas commencés'
assert data['demand_comment'] == {
'text': 'bonjour atal',
'date': 'Thursday 24 October 2019, 16:51'
}
assert data['demand_comments'] == []
assert data['works_comment'] is None
assert data['works_status'] is None
assert len(data['comments']) == 2
assert data['comments'][0] == {
# full in query string
monkeypatch.setattr(
passerelle.utils.Request, 'post', mock.Mock(side_effect=[api_response1, api_response2])
)
response = app.get('/atal/slug-atal/infos/DIT18050001/?full=true')
data = response.json['data']
assert len(data['demand_comments']) == 2
assert data['demand_comments'][0] == {
'text': 'OK',
'date': 'Thursday 24 October 2019, 16:48'
}
@ -308,5 +321,5 @@ def test_infos(app, connector, monkeypatch):
'text': 'bonjour atal',
'date': 'Thursday 24 October 2019, 16:51'
}
assert data['comments'][1] == last_comment
assert data['last_comment'] == last_comment
assert data['demand_comments'][1] == last_comment
assert data['demand_comment'] == last_comment