0001-lille-urban-card-add-endpoint-for-card-revocation-39.patch
passerelle/contrib/lille_urban_card/models.py | ||
---|---|---|
172 | 172 |
response_json['status_code'] = response.status_code |
173 | 173 |
raise APIError(response_json['erreur'], data=response_json) |
174 | 174 |
return {'data': response_json} |
175 | ||
176 |
@endpoint(perm='can_access', description=_('Card Revocation'), methods=['post']) |
|
177 |
def card_revocation(self, request, *args, **kwargs): |
|
178 |
data = json_loads(request.body) |
|
179 |
if data.get('civilite'): |
|
180 |
if data['civilite'] == 'Monsieur': |
|
181 |
data['civilite'] = 1 |
|
182 |
else: |
|
183 |
data['civilite'] = 2 |
|
184 |
if data.get('code_postal'): |
|
185 |
data['code_postal'] = int(data['code_postal']) |
|
186 |
if data.get('ville'): |
|
187 |
data['ville'] = data['ville'].upper() |
|
188 |
response = self.requests.post( |
|
189 |
urljoin(self.base_url, '/clu/ws/revoquerCarte'), |
|
190 |
json=data, |
|
191 |
auth=HttpBearerAuth(self.get_token())) |
|
192 |
response_json = response.json() |
|
193 |
if response_json.get('erreur'): |
|
194 |
self.logger.error('error revoking card (%r)', response_json['erreur']) |
|
195 |
response_json['status_code'] = response.status_code |
|
196 |
raise APIError(response_json['erreur'], data=response_json) |
|
197 |
return {'data': response_json} # {"message": "La demande..."} |
tests/test_lille_urban_card.py | ||
---|---|---|
64 | 64 |
error = {'statut': 'ERREUR_NUM_SERIE', 'erreur': 'Le numero de serie...'} |
65 | 65 |
return {'content': json.dumps(error), 'status_code': 404} |
66 | 66 |
return {'content': json.dumps({}), 'status_code': 200} |
67 |
if url.path == '/clu/ws/revoquerCarte': |
|
68 |
request_json = json_loads(request.body) |
|
69 |
if request_json.get('simulate_error') == 'doublon': |
|
70 |
error = {'erreur': 'La demande xx existe...'} |
|
71 |
return {'content': json.dumps(error), 'status_code': 409} |
|
72 |
return {'content': json.dumps({'message': 'ok'}), 'status_code': 200} |
|
67 | 73 | |
68 | 74 | |
69 | 75 |
@mock.patch('passerelle.utils.Request.post') |
... | ... | |
204 | 210 |
}, status=200) |
205 | 211 |
assert resp.json['err'] == 1 |
206 | 212 |
assert resp.json['data']['status_code'] == 404 |
213 | ||
214 | ||
215 |
def test_card_revocation(app, connector): |
|
216 |
endpoint = utils.generic_endpoint_url('lille-urban-card', 'card_revocation', slug=connector.slug) |
|
217 |
with HTTMock(mocked_http): |
|
218 |
resp = app.post_json(endpoint, params={ |
|
219 |
'n_demande_gru': '12-123', |
|
220 |
'numero_serie': 'XXX', |
|
221 |
'ate_demande': '05/02/2020', |
|
222 |
}) |
|
223 |
assert resp.json['err'] == 0 |
|
224 | ||
225 |
# error handling |
|
226 |
resp = app.post_json(endpoint, params={ |
|
227 |
'simulate_error': 'doublon', |
|
228 |
'n_demande_gru': '12-123', |
|
229 |
'numero_serie': 'XXX', |
|
230 |
'ate_demande': '05/02/2020', |
|
231 |
}, status=200) |
|
232 |
assert resp.json['err'] == 1 |
|
233 |
assert resp.json['data']['status_code'] == 409 |
|
207 |
- |