0001-atal-return-works-comment-and-hide-raw-data-37669.patch
passerelle/apps/atal/models.py | ||
---|---|---|
201 | 201 |
parameters={ |
202 | 202 |
'demand_number': { |
203 | 203 |
'description': _('Demande number'), 'example_value': 'DIT18050001' |
204 |
}, |
|
205 |
'full': { |
|
206 |
'description': _('Full'), |
|
207 |
'example_value': 'true', |
|
208 |
'type': 'bool', |
|
204 | 209 |
} |
205 | 210 |
} |
206 | 211 |
) |
207 |
def infos(self, request, demand_number): |
|
212 |
def infos(self, request, demand_number, full=False):
|
|
208 | 213 |
demand_details = helpers.serialize_object( |
209 | 214 |
self._soap_call( |
210 | 215 |
wsdl='DemandeService', method='retrieveDetailsDemande', |
... | ... | |
218 | 223 |
raise APIError('Could not get a status') |
219 | 224 | |
220 | 225 |
responses = (demand_details.get('reponses') or {}).get('Reponse') or [] |
221 |
comments = [] |
|
226 |
demand_comments = []
|
|
222 | 227 |
if responses: |
223 | 228 |
for response in responses: |
224 | 229 |
comment = { |
... | ... | |
227 | 232 |
} |
228 | 233 |
if 'dateReponse' in response: |
229 | 234 |
comment['date'] = dateformat.format(response['dateReponse'], DATE_FORMAT) |
230 |
comments.append(comment) |
|
235 |
demand_comments.append(comment)
|
|
231 | 236 | |
232 |
last_comment = {
|
|
237 |
demand_comment = {
|
|
233 | 238 |
'text': None, |
234 | 239 |
'date': None |
235 | 240 |
} |
236 |
if comments: |
|
237 |
last_comment = comments[-1]
|
|
241 |
if demand_comments:
|
|
242 |
demand_comment = demand_comments[-1]
|
|
238 | 243 | |
239 | 244 |
data = { |
240 | 245 |
'status': status, |
241 |
'demand_details': demand_details, |
|
242 |
'comments': comments, |
|
243 |
'last_comment': last_comment, |
|
244 | ||
246 |
'demand_comment': demand_comment, |
|
247 |
'demand_details': None, |
|
248 |
'demand_comments': [] |
|
245 | 249 |
} |
250 |
if full: |
|
251 |
data['demand_details'] = demand_details |
|
252 |
data['demand_comments'] = demand_comments |
|
253 | ||
246 | 254 |
if status not in ('PRISE EN COMPTE', 'ARCHIVEE'): |
247 | 255 |
return { |
248 | 256 |
'data': data |
... | ... | |
258 | 266 |
if not status: |
259 | 267 |
raise APIError('Could not get a status') |
260 | 268 | |
261 |
data['works_status'] = works_status |
|
262 | 269 |
data['status'] = status |
270 |
data['works_comment'] = works_status.get('commentaires', '') |
|
271 |
data['works_status'] = None |
|
272 | ||
273 |
if full: |
|
274 |
data['works_status'] = works_status |
|
275 | ||
263 | 276 |
return { |
264 | 277 |
'data': data |
265 | 278 |
} |
tests/test_atal.py | ||
---|---|---|
298 | 298 |
assert response.json['err'] == 0 |
299 | 299 |
data = response.json['data'] |
300 | 300 |
assert data['status'] == u'travaux pas commencés' |
301 |
assert data['demand_comment'] == { |
|
302 |
'text': 'bonjour atal', |
|
303 |
'date': 'Thursday 24 October 2019, 16:51' |
|
304 |
} |
|
305 |
assert data['demand_comments'] == [] |
|
306 |
assert data['works_comment'] is None |
|
307 |
assert data['works_status'] is None |
|
301 | 308 | |
302 |
assert len(data['comments']) == 2 |
|
303 |
assert data['comments'][0] == { |
|
309 |
# full in query string |
|
310 |
monkeypatch.setattr( |
|
311 |
passerelle.utils.Request, 'post', mock.Mock(side_effect=[api_response1, api_response2]) |
|
312 |
) |
|
313 |
response = app.get('/atal/slug-atal/infos/DIT18050001/?full=true') |
|
314 |
data = response.json['data'] |
|
315 |
assert len(data['demand_comments']) == 2 |
|
316 |
assert data['demand_comments'][0] == { |
|
304 | 317 |
'text': 'OK', |
305 | 318 |
'date': 'Thursday 24 October 2019, 16:48' |
306 | 319 |
} |
... | ... | |
308 | 321 |
'text': 'bonjour atal', |
309 | 322 |
'date': 'Thursday 24 October 2019, 16:51' |
310 | 323 |
} |
311 |
assert data['comments'][1] == last_comment |
|
312 |
assert data['last_comment'] == last_comment |
|
324 |
assert data['demand_comments'][1] == last_comment |
|
325 |
assert data['demand_comment'] == last_comment |
|
313 |
- |