0001-lille-urban-card-add-new-code-change-endpoint-39528.patch
passerelle/contrib/lille_urban_card/models.py | ||
---|---|---|
158 | 158 |
response_json['status_code'] = response.status_code |
159 | 159 |
raise APIError(response_json['erreur'], data=response_json) |
160 | 160 |
return {'data': response_json} # {"n_demande_clu":10000005} |
161 | ||
162 |
@endpoint(perm='can_access', description=_('Code Change'), methods=['post']) |
|
163 |
def code_change(self, request, *args, **kwargs): |
|
164 |
data = json_loads(request.body) |
|
165 |
response = self.requests.post( |
|
166 |
urljoin(self.base_url, '/clu/ws/modifierCodeSecret'), |
|
167 |
json=data, |
|
168 |
auth=HttpBearerAuth(self.get_token())) |
|
169 |
response_json = response.json() |
|
170 |
if response_json.get('erreur'): |
|
171 |
self.logger.error('error changing code (%r)', response_json['erreur']) |
|
172 |
response_json['status_code'] = response.status_code |
|
173 |
raise APIError(response_json['erreur'], data=response_json) |
|
174 |
return {'data': response_json} |
tests/test_lille_urban_card.py | ||
---|---|---|
58 | 58 |
'request': request_json, # for tests |
59 | 59 |
} |
60 | 60 |
return {'content': json.dumps(content), 'status_code': 200} |
61 |
if url.path == '/clu/ws/modifierCodeSecret': |
|
62 |
request_json = json_loads(request.body) |
|
63 |
if request_json.get('simulate_error') == 'wrong num serie': |
|
64 |
error = {'statut': 'ERREUR_NUM_SERIE', 'erreur': 'Le numero de serie...'} |
|
65 |
return {'content': json.dumps(error), 'status_code': 404} |
|
66 |
return {'content': json.dumps({}), 'status_code': 200} |
|
61 | 67 | |
62 | 68 | |
63 | 69 |
@mock.patch('passerelle.utils.Request.post') |
... | ... | |
175 | 181 |
}, status=200) |
176 | 182 |
assert resp.json['err'] == 1 |
177 | 183 |
assert resp.json['data']['status_code'] == 400 |
184 | ||
185 | ||
186 |
def test_code_change(app, connector): |
|
187 |
endpoint = utils.generic_endpoint_url('lille-urban-card', 'code_change', slug=connector.slug) |
|
188 |
with HTTMock(mocked_http): |
|
189 |
resp = app.post_json(endpoint, params={ |
|
190 |
'numero_serie': 'XXX', |
|
191 |
'ancien': '1234', |
|
192 |
'nouveau': '2345', |
|
193 |
'confirmation_nouveau': '2345', |
|
194 |
}) |
|
195 |
assert resp.json['err'] == 0 |
|
196 | ||
197 |
# error handling |
|
198 |
resp = app.post_json(endpoint, params={ |
|
199 |
'simulate_error': 'wrong num serie', |
|
200 |
'numero_serie': 'XXX', |
|
201 |
'ancien': '1234', |
|
202 |
'nouveau': '2345', |
|
203 |
'confirmation_nouveau': '2345', |
|
204 |
}, status=200) |
|
205 |
assert resp.json['err'] == 1 |
|
206 |
assert resp.json['data']['status_code'] == 404 |
|
178 |
- |