caluire-axel: unlink endpoint (#53705)
This commit is contained in:
parent
81ad4a3f79
commit
962fc6edb1
|
@ -19,3 +19,12 @@ def test_link(conn, user):
|
|||
pprint.pprint(res)
|
||||
assert res['err'] == 0
|
||||
print('\n')
|
||||
|
||||
print("Deleting link")
|
||||
url = conn + '/unlink?NameID=%s' % name_id
|
||||
resp = requests.post(url)
|
||||
resp.raise_for_status()
|
||||
res = resp.json()
|
||||
assert res['err'] == 0
|
||||
pprint.pprint(res)
|
||||
print('\n')
|
||||
|
|
|
@ -32,7 +32,7 @@ class CaluireAxel(BaseResource):
|
|||
)
|
||||
|
||||
category = _('Business Process Connectors')
|
||||
_category_ordering = [_('Family')]
|
||||
_category_ordering = [_('Family account')]
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Caluire Axel')
|
||||
|
@ -66,7 +66,7 @@ class CaluireAxel(BaseResource):
|
|||
raise APIError('Person not found', err_code='not-found')
|
||||
|
||||
@endpoint(
|
||||
display_category=_('Family'),
|
||||
display_category=_('Family account'),
|
||||
display_order=1,
|
||||
description=_('Create link between user and Caluire Axel'),
|
||||
perm='can_access',
|
||||
|
@ -108,6 +108,28 @@ class CaluireAxel(BaseResource):
|
|||
},
|
||||
}
|
||||
|
||||
def get_link(self, name_id):
|
||||
try:
|
||||
return self.link_set.get(name_id=name_id)
|
||||
except Link.DoesNotExist:
|
||||
raise APIError('Person not found', err_code='not-found')
|
||||
|
||||
@endpoint(
|
||||
display_category=_('Family account'),
|
||||
display_order=2,
|
||||
description=_('Delete link between user and Caluire Axel'),
|
||||
methods=['post'],
|
||||
perm='can_access',
|
||||
parameters={
|
||||
'NameID': {'description': _('Publik ID')},
|
||||
},
|
||||
)
|
||||
def unlink(self, request, NameID):
|
||||
link = self.get_link(NameID)
|
||||
link_id = link.pk
|
||||
link.delete()
|
||||
return {'link': link_id, 'deleted': True, 'family_id': link.family_id}
|
||||
|
||||
|
||||
class Link(models.Model):
|
||||
resource = models.ForeignKey(CaluireAxel, on_delete=models.CASCADE)
|
||||
|
|
|
@ -349,3 +349,19 @@ def test_link_endpoint(app, resource, link_params, place):
|
|||
assert resp.json['created'] is False # link already exists
|
||||
assert 'xml_request' in resp.json['data']
|
||||
assert 'xml_response' in resp.json['data']
|
||||
|
||||
|
||||
def test_unlink_endpoint_no_result(app, resource):
|
||||
resp = app.post('/caluire-axel/test/unlink?NameID=yyy')
|
||||
assert resp.json['err_desc'] == "Person not found"
|
||||
assert resp.json['err'] == 'not-found'
|
||||
|
||||
|
||||
def test_unlink_endpoint(app, resource):
|
||||
link = Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
resp = app.post('/caluire-axel/test/unlink?NameID=yyy')
|
||||
assert Link.objects.exists() is False
|
||||
assert resp.json['err'] == 0
|
||||
assert resp.json['link'] == link.pk
|
||||
assert resp.json['family_id'] == 'XXX'
|
||||
assert resp.json['deleted'] is True
|
||||
|
|
Loading…
Reference in New Issue