22 |
22 |
|
23 |
23 |
from django.core.urlresolvers import reverse
|
24 |
24 |
|
|
25 |
import requests
|
|
26 |
|
25 |
27 |
from passerelle.apps.api_particulier.models import APIParticulier
|
26 |
28 |
from passerelle.base.models import ResourceLog
|
27 |
29 |
|
... | ... | |
107 |
109 |
return response(500, {'error': 500}, request=request)
|
108 |
110 |
|
109 |
111 |
|
|
112 |
@urlmatch(netloc=r'^particulier.*\.api\.gouv\.fr$')
|
|
113 |
def api_particulier_connection_error(url, request):
|
|
114 |
raise requests.RequestException('connection timed-out')
|
|
115 |
|
|
116 |
|
110 |
117 |
@urlmatch(netloc=r'^particulier.*\.api\.gouv\.fr$')
|
111 |
118 |
def api_particulier_error_not_json(url, request):
|
112 |
119 |
return response(200, 'something bad happened', request=request)
|
... | ... | |
138 |
145 |
|
139 |
146 |
|
140 |
147 |
def test_error(app, resource, mock_api_particulier):
|
|
148 |
vector = [
|
|
149 |
(['impots_svair', 'avis-imposition'], {
|
|
150 |
'numero_fiscal': 12,
|
|
151 |
'reference_avis': 15,
|
|
152 |
}),
|
|
153 |
(['caf_famille', 'situation-familiale'], {
|
|
154 |
'code_postal': 12,
|
|
155 |
'numero_allocataire': 15
|
|
156 |
}),
|
|
157 |
]
|
141 |
158 |
with HTTMock(api_particulier_error_500):
|
142 |
159 |
def do(endpoint, params):
|
143 |
160 |
resp = endpoint_get(
|
... | ... | |
150 |
167 |
assert resp.json['err'] == 1
|
151 |
168 |
assert resp.json['data']['status_code'] == 500
|
152 |
169 |
assert resp.json['data']['code'] == 'non-200'
|
153 |
|
vector = [
|
154 |
|
(['impots_svair', 'avis-imposition'], {
|
155 |
|
'numero_fiscal': 12,
|
156 |
|
'reference_avis': 15,
|
157 |
|
}),
|
158 |
|
(['caf_famille', 'situation-familiale'], {
|
159 |
|
'code_postal': 12,
|
160 |
|
'numero_allocataire': 15
|
161 |
|
}),
|
162 |
|
]
|
163 |
170 |
for endpoints, params in vector:
|
164 |
171 |
for endpoint in endpoints:
|
165 |
172 |
do(endpoint, params)
|
... | ... | |
175 |
182 |
assert resp.json['err'] == 1
|
176 |
183 |
assert 'returned non-JSON content' in resp.json['err_desc']
|
177 |
184 |
assert resp.json['data']['code'] == 'non-json'
|
178 |
|
vector = [
|
179 |
|
(['impots_svair', 'avis-imposition'], {
|
180 |
|
'numero_fiscal': 12,
|
181 |
|
'reference_avis': 15,
|
182 |
|
}),
|
183 |
|
(['caf_famille', 'situation-familiale'], {
|
184 |
|
'code_postal': 12,
|
185 |
|
'numero_allocataire': 15
|
186 |
|
}),
|
187 |
|
]
|
188 |
185 |
for endpoints, params in vector:
|
189 |
186 |
for endpoint in endpoints:
|
190 |
187 |
do(endpoint, params)
|
... | ... | |
200 |
197 |
assert resp.json['err'] == 1
|
201 |
198 |
assert resp.json['err_desc'] == 'No matching tax notice was found.'
|
202 |
199 |
assert resp.json['data']['code'] == 'not-found'
|
203 |
|
vector = [
|
204 |
|
(['impots_svair', 'avis-imposition'], {
|
205 |
|
'numero_fiscal': 12,
|
206 |
|
'reference_avis': 15,
|
207 |
|
}),
|
208 |
|
(['caf_famille', 'situation-familiale'], {
|
209 |
|
'code_postal': 12,
|
210 |
|
'numero_allocataire': 15
|
211 |
|
}),
|
212 |
|
]
|
|
200 |
for endpoints, params in vector:
|
|
201 |
for endpoint in endpoints:
|
|
202 |
do(endpoint, params)
|
|
203 |
with HTTMock(api_particulier_connection_error):
|
|
204 |
def do(endpoint, params):
|
|
205 |
resp = endpoint_get(
|
|
206 |
'/api-particulier/test/%s' % endpoint,
|
|
207 |
app,
|
|
208 |
resource,
|
|
209 |
endpoint,
|
|
210 |
params=params)
|
|
211 |
assert resp.status_code == 200
|
|
212 |
assert resp.json['err'] == 1
|
|
213 |
assert resp.json['err_desc'] == 'API-particulier platform "test" connection error: connection timed-out'
|
213 |
214 |
for endpoints, params in vector:
|
214 |
215 |
for endpoint in endpoints:
|
215 |
216 |
do(endpoint, params)
|
216 |
|
-
|