0002-toulouse_axel-child_info-endpoint-38155.patch
functests/toulouse_axel/conftest.py | ||
---|---|---|
4 | 4 |
def pytest_addoption(parser): |
5 | 5 |
parser.addoption( |
6 | 6 |
"--url", help="Url of a passerelle Toulouse Axel connector instance") |
7 |
parser.addoption("--nameid", help="Publik Name ID") |
|
7 | 8 |
parser.addoption("--firstname", help="first name of a user") |
8 | 9 |
parser.addoption("--lastname", help="Last name of a user") |
9 | 10 |
parser.addoption("--dob", help="Date of birth of a user") |
... | ... | |
18 | 19 |
@pytest.fixture(scope='session') |
19 | 20 |
def user(request): |
20 | 21 |
return { |
22 |
'name_id': request.config.getoption("--nameid"), |
|
21 | 23 |
'first_name': request.config.getoption("--firstname"), |
22 | 24 |
'last_name': request.config.getoption("--lastname"), |
23 | 25 |
'dob': request.config.getoption("--dob"), |
functests/toulouse_axel/test_toulouse_axel.py | ||
---|---|---|
3 | 3 | |
4 | 4 | |
5 | 5 |
def test_link(conn, user): |
6 |
url = conn + '/link?NameID=123' |
|
6 |
name_id = user['name_id'] |
|
7 |
url = conn + '/link?NameID=%s' % name_id |
|
7 | 8 |
payload = { |
8 | 9 |
'IDDUI': user['dui'], |
9 | 10 |
'NOM': user['last_name'], |
10 | 11 |
'PRENOM': user['first_name'], |
11 | 12 |
'NAISSANCE': user['dob'], |
12 | 13 |
} |
13 |
print("Creating link with the following payload:\n%s" % payload) |
|
14 |
print("Creating link with the following payload:") |
|
15 |
pprint.pprint(payload) |
|
14 | 16 |
resp = requests.post(url, json=payload) |
15 | 17 |
resp.raise_for_status() |
16 | 18 |
res = resp.json() |
... | ... | |
18 | 20 |
pprint.pprint(res) |
19 | 21 |
print('\n') |
20 | 22 | |
21 |
url = conn + '/family_info?NameID=123' |
|
23 |
print("GET family info") |
|
24 |
url = conn + '/family_info?NameID=%s' % name_id |
|
22 | 25 |
resp = requests.get(url) |
23 | 26 |
resp.raise_for_status() |
24 | 27 |
res = resp.json() |
25 | 28 |
assert res['err'] == 0 |
26 | 29 |
pprint.pprint(res) |
27 | 30 |
print('\n') |
31 | ||
32 |
data = res |
|
33 |
for child in data['data']['ENFANT']: |
|
34 |
print("GET child info") |
|
35 |
url = conn + '/child_info?NameID=%s&idpersonne=%s' % (name_id, child['IDPERSONNE']) |
|
36 |
resp = requests.get(url) |
|
37 |
resp.raise_for_status() |
|
38 |
res = resp.json() |
|
39 |
assert res['err'] == 0 |
|
40 |
pprint.pprint(res) |
|
41 |
print('\n') |
passerelle/contrib/toulouse_axel/models.py | ||
---|---|---|
169 | 169 |
raise APIError('Data conflict', err='conflict') |
170 | 170 |
return {'link': link.pk, 'created': created, 'dui': link.dui} |
171 | 171 | |
172 |
@endpoint( |
|
173 |
description=_("Get information about user's family"), |
|
174 |
perm='can_access', |
|
175 |
parameters={ |
|
176 |
'NameID': {'description': _('Publik ID')}, |
|
177 |
}) |
|
178 |
def family_info(self, request, NameID): |
|
172 |
def get_family_data(self, name_id): |
|
179 | 173 |
try: |
180 |
link = self.link_set.get(name_id=NameID)
|
|
174 |
link = self.link_set.get(name_id=name_id)
|
|
181 | 175 |
except Link.DoesNotExist: |
182 | 176 |
raise APIError('Person not found', err='not-found') |
183 | 177 | |
... | ... | |
185 | 179 |
result = ref_famille_dui(self, {'PORTAIL': {'DUI': {'IDDUI': link.dui}}}) |
186 | 180 |
except AxelError as e: |
187 | 181 |
raise APIError('Axel error: %s' % e, err='error') |
188 |
return {'data': result['DATA']['PORTAIL']['DUI']} |
|
182 |
return result['DATA']['PORTAIL']['DUI'] |
|
183 | ||
184 |
@endpoint( |
|
185 |
description=_("Get information about user's family"), |
|
186 |
perm='can_access', |
|
187 |
parameters={ |
|
188 |
'NameID': {'description': _('Publik ID')}, |
|
189 |
}) |
|
190 |
def family_info(self, request, NameID): |
|
191 |
family_data = self.get_family_data(NameID) |
|
192 |
return {'data': family_data} |
|
193 | ||
194 |
@endpoint( |
|
195 |
description=_("Get information about a child"), |
|
196 |
perm='can_access', |
|
197 |
parameters={ |
|
198 |
'NameID': {'description': _('Publik ID')}, |
|
199 |
'idpersonne': {'description': _('Child ID')}, |
|
200 |
}) |
|
201 |
def child_info(self, request, idpersonne, NameID): |
|
202 |
family_data = self.get_family_data(NameID) |
|
203 | ||
204 |
for child in family_data['ENFANT']: |
|
205 |
if child['IDPERSONNE'] == idpersonne: |
|
206 |
return {'data': child} |
|
207 | ||
208 |
raise APIError('Child not found', err='not-found') |
|
189 | 209 | |
190 | 210 | |
191 | 211 |
class Link(models.Model): |
tests/data/toulouse_axel/family_info.xml | ||
---|---|---|
157 | 157 |
</CONTACT> |
158 | 158 |
</ENFANT> |
159 | 159 |
<ENFANT> |
160 |
<IDPERSONNE>4242</IDPERSONNE>
|
|
160 |
<IDPERSONNE>3535</IDPERSONNE>
|
|
161 | 161 |
<RATTACHEAUTREDUI>NON</RATTACHEAUTREDUI> |
162 | 162 |
<NOM>foo</NOM> |
163 | 163 |
<PRENOM>foo</PRENOM> |
tests/test_toulouse_axel.py | ||
---|---|---|
245 | 245 |
'SITUATIONFAMILIALE', |
246 | 246 |
'TELFIXE', |
247 | 247 |
]) |
248 | ||
249 | ||
250 |
def test_child_info_endpoint_axel_error(app, resource): |
|
251 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
|
252 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_famille_dui') as operation: |
|
253 |
operation.side_effect = AxelError('FooBar') |
|
254 |
resp = app.get('/toulouse-axel/test/child_info?NameID=yyy&idpersonne=zzz') |
|
255 |
assert resp.json['err_desc'] == "Axel error: FooBar" |
|
256 | ||
257 | ||
258 |
def test_child_info_endpoint_no_result(app, resource): |
|
259 |
resp = app.get('/toulouse-axel/test/child_info?NameID=yyy&idpersonne=zzz') |
|
260 |
assert resp.json['err_desc'] == "Person not found" |
|
261 | ||
262 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
|
263 |
filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/family_info.xml') |
|
264 |
with open(filepath) as xml: |
|
265 |
content = xml.read() |
|
266 |
with mock_getdata(content, 'RefFamilleDui'): |
|
267 |
resp = app.get('/toulouse-axel/test/child_info?NameID=yyy&idpersonne=zzz') |
|
268 |
assert resp.json['err_desc'] == "Child not found" |
|
269 | ||
270 | ||
271 |
def test_child_info_endpoint(app, resource): |
|
272 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
|
273 |
filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/family_info.xml') |
|
274 |
with open(filepath) as xml: |
|
275 |
content = xml.read() |
|
276 |
with mock_getdata(content, 'RefFamilleDui'): |
|
277 |
resp = app.get('/toulouse-axel/test/child_info?NameID=yyy&idpersonne=4242') |
|
278 |
assert resp.json['err'] == 0 |
|
279 |
assert set(resp.json['data'].keys()) == set([ |
|
280 |
'ASSURANCE', |
|
281 |
'CONTACT', |
|
282 |
'DATENAISSANCE', |
|
283 |
'IDPERSONNE', |
|
284 |
'PRENOM', |
|
285 |
'PRENOMMERE', |
|
286 |
'PRENOMPERE', |
|
287 |
'NOM', |
|
288 |
'NOMMERE', |
|
289 |
'NOMPERE', |
|
290 |
'RATTACHEAUTREDUI', |
|
291 |
'SANITAIRE', |
|
292 |
'SEXE', |
|
293 |
]) |
|
248 |
- |