0001-toulouse_axel-unlink-endpoint-37863.patch
functests/toulouse_axel/test_toulouse_axel.py | ||
---|---|---|
39 | 39 |
assert res['err'] == 0 |
40 | 40 |
pprint.pprint(res) |
41 | 41 |
print('\n') |
42 | ||
43 |
print("Deleting link") |
|
44 |
url = conn + '/unlink?NameID=%s' % name_id |
|
45 |
resp = requests.post(url) |
|
46 |
resp.raise_for_status() |
|
47 |
res = resp.json() |
|
48 |
assert res['err'] == 0 |
|
49 |
pprint.pprint(res) |
|
50 |
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=_('Delete link between user and Toulouse Axel'), |
|
174 |
methods=['post'], |
|
175 |
perm='can_access', |
|
176 |
parameters={ |
|
177 |
'NameID': {'description': _('Publik ID')}, |
|
178 |
}) |
|
179 |
def unlink(self, request, NameID): |
|
180 |
try: |
|
181 |
link = self.link_set.get(name_id=NameID) |
|
182 |
except Link.DoesNotExist: |
|
183 |
raise APIError('Person not found', err='not-found') |
|
184 | ||
185 |
link_id = link.pk |
|
186 |
link.delete() |
|
187 |
return {'link': link_id, 'deleted': True, 'dui': link.dui} |
|
188 | ||
172 | 189 |
def get_family_data(self, name_id): |
173 | 190 |
try: |
174 | 191 |
link = self.link_set.get(name_id=name_id) |
tests/test_toulouse_axel.py | ||
---|---|---|
209 | 209 |
assert resp.json['created'] is False # link already exists |
210 | 210 | |
211 | 211 | |
212 |
def test_unlink_endpoint_no_result(app, resource): |
|
213 |
resp = app.post('/toulouse-axel/test/unlink?NameID=yyy') |
|
214 |
assert resp.json['err_desc'] == "Person not found" |
|
215 | ||
216 | ||
217 |
def test_unlink_endpoint(app, resource): |
|
218 |
link = Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
|
219 |
resp = app.post('/toulouse-axel/test/unlink?NameID=yyy') |
|
220 |
assert Link.objects.exists() is False |
|
221 |
assert resp.json['err'] == 0 |
|
222 |
assert resp.json['link'] == link.pk |
|
223 |
assert resp.json['dui'] == 'XXX' |
|
224 |
assert resp.json['deleted'] is True |
|
225 | ||
226 | ||
212 | 227 |
def test_family_info_endpoint_axel_error(app, resource): |
213 | 228 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
214 | 229 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_famille_dui') as operation: |
215 |
- |