0001-lille-urban-card-add-renewal-endpoint-61038.patch
passerelle/contrib/lille_urban_card/models.py | ||
---|---|---|
289 | 289 |
) |
290 | 290 |
response_json = response.json() |
291 | 291 |
if not isinstance(response_json, dict): |
292 |
self.logger.error('error revoking subscripton (unknown response format)') |
|
292 |
self.logger.error('error revoking subscription (unknown response format)')
|
|
293 | 293 |
raise APIError('unknown error', data=response_json) |
294 | 294 |
if response_json.get('erreur'): |
295 | 295 |
self.logger.debug('error revoking subscripton (%r)', response_json['erreur']) |
296 | 296 |
response_json['status_code'] = response.status_code |
297 | 297 |
raise APIError(response_json['erreur'], data=response_json) |
298 | 298 |
return {'data': response_json} # {"n_demande_clu":10000005} |
299 | ||
300 |
@endpoint(perm='can_access', description=_('Subscription Renewal'), methods=['post']) |
|
301 |
def subscription_renewal(self, request, *args, **kwargs): |
|
302 |
data = json_loads(request.body) |
|
303 |
response = self.requests.post( |
|
304 |
urljoin(self.base_url, '/clu/ws/renouvelerAbonnements'), |
|
305 |
json=data, |
|
306 |
auth=HttpBearerAuth(self.get_token()), |
|
307 |
) |
|
308 |
response_json = response.json() |
|
309 |
if not isinstance(response_json, dict): |
|
310 |
self.logger.error('error renewing subscription (unknown response format)') |
|
311 |
raise APIError('unknown error', data=response_json) |
|
312 |
if response_json.get('erreur'): |
|
313 |
self.logger.debug('error renewing subscripton (%r)', response_json['erreur']) |
|
314 |
response_json['status_code'] = response.status_code |
|
315 |
raise APIError(response_json['erreur'], data=response_json) |
|
316 |
return {'data': response_json} # {"n_demande_clu":10000005} |
tests/test_lille_urban_card.py | ||
---|---|---|
77 | 77 |
error = {'erreur': 'La demande xx existe...'} |
78 | 78 |
return {'content': json.dumps(error), 'status_code': 409} |
79 | 79 |
return {'content': json.dumps({'message': 'ok'}), 'status_code': 200} |
80 |
if url.path == '/clu/ws/renouvelerAbonnements': |
|
81 |
request_json = json_loads(request.body) |
|
82 |
if request_json.get('simulate_error') == 'wrong num serie': |
|
83 |
error = {'statut': 'ERREUR_NUM_SERIE', 'erreur': 'Le numero de serie...'} |
|
84 |
return {'content': json.dumps(error), 'status_code': 409} |
|
85 |
return {'content': json.dumps({'n_demande_clu': 10000507}), 'status_code': 200} |
|
80 | 86 |
if url.path == '/clu/ws/consulterCarte': |
81 | 87 |
if url.query == 'numero_serie=ERROR': |
82 | 88 |
error = {'erreur': 'Pas de carte attribuee correspondante'} |
... | ... | |
364 | 370 |
) |
365 | 371 |
assert resp.json['err'] == 1 |
366 | 372 |
assert resp.json['data']['status_code'] == 409 |
373 | ||
374 | ||
375 |
def test_subscription_renewal(app, connector): |
|
376 |
endpoint = utils.generic_endpoint_url('lille-urban-card', 'subscription_renewal', slug=connector.slug) |
|
377 |
with HTTMock(mocked_http): |
|
378 |
resp = app.post_json( |
|
379 |
endpoint, |
|
380 |
params={ |
|
381 |
'n_demande_gru': '12-123', |
|
382 |
'numero_serie': 'XXX', |
|
383 |
'date_demande': '05/02/2020', |
|
384 |
}, |
|
385 |
) |
|
386 |
assert resp.json['err'] == 0 |
|
387 | ||
388 |
# error handling |
|
389 |
resp = app.post_json( |
|
390 |
endpoint, |
|
391 |
params={ |
|
392 |
'simulate_error': 'wrong num serie', |
|
393 |
'n_demande_gru': '12-123', |
|
394 |
'numero_serie': 'XXX', |
|
395 |
'date_demande': '05/02/2020', |
|
396 |
}, |
|
397 |
status=200, |
|
398 |
) |
|
399 |
assert resp.json['err'] == 1 |
|
400 |
assert resp.json['data']['status_code'] == 409 |
|
367 |
- |