Projet

Général

Profil

0001-caluire-axel-unlink-endpoint-53705.patch

Lauréline Guérin, 06 mai 2021 11:52

Télécharger (3,77 ko)

Voir les différences:

Subject: [PATCH] caluire-axel: unlink endpoint (#53705)

 functests/caluire_axel/test_caluire_axel.py |  9 +++++++
 passerelle/contrib/caluire_axel/models.py   | 26 +++++++++++++++++++--
 tests/test_caluire_axel.py                  | 16 +++++++++++++
 3 files changed, 49 insertions(+), 2 deletions(-)
functests/caluire_axel/test_caluire_axel.py
19 19
    pprint.pprint(res)
20 20
    assert res['err'] == 0
21 21
    print('\n')
22

  
23
    print("Deleting link")
24
    url = conn + '/unlink?NameID=%s' % name_id
25
    resp = requests.post(url)
26
    resp.raise_for_status()
27
    res = resp.json()
28
    assert res['err'] == 0
29
    pprint.pprint(res)
30
    print('\n')
passerelle/contrib/caluire_axel/models.py
32 32
    )
33 33

  
34 34
    category = _('Business Process Connectors')
35
    _category_ordering = [_('Family')]
35
    _category_ordering = [_('Family account')]
36 36

  
37 37
    class Meta:
38 38
        verbose_name = _('Caluire Axel')
......
66 66
        raise APIError('Person not found', err_code='not-found')
67 67

  
68 68
    @endpoint(
69
        display_category=_('Family'),
69
        display_category=_('Family account'),
70 70
        display_order=1,
71 71
        description=_('Create link between user and Caluire Axel'),
72 72
        perm='can_access',
......
108 108
            },
109 109
        }
110 110

  
111
    def get_link(self, name_id):
112
        try:
113
            return self.link_set.get(name_id=name_id)
114
        except Link.DoesNotExist:
115
            raise APIError('Person not found', err_code='not-found')
116

  
117
    @endpoint(
118
        display_category=_('Family account'),
119
        display_order=2,
120
        description=_('Delete link between user and Caluire Axel'),
121
        methods=['post'],
122
        perm='can_access',
123
        parameters={
124
            'NameID': {'description': _('Publik ID')},
125
        },
126
    )
127
    def unlink(self, request, NameID):
128
        link = self.get_link(NameID)
129
        link_id = link.pk
130
        link.delete()
131
        return {'link': link_id, 'deleted': True, 'family_id': link.family_id}
132

  
111 133

  
112 134
class Link(models.Model):
113 135
    resource = models.ForeignKey(CaluireAxel, on_delete=models.CASCADE)
tests/test_caluire_axel.py
349 349
    assert resp.json['created'] is False  # link already exists
350 350
    assert 'xml_request' in resp.json['data']
351 351
    assert 'xml_response' in resp.json['data']
352

  
353

  
354
def test_unlink_endpoint_no_result(app, resource):
355
    resp = app.post('/caluire-axel/test/unlink?NameID=yyy')
356
    assert resp.json['err_desc'] == "Person not found"
357
    assert resp.json['err'] == 'not-found'
358

  
359

  
360
def test_unlink_endpoint(app, resource):
361
    link = Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
362
    resp = app.post('/caluire-axel/test/unlink?NameID=yyy')
363
    assert Link.objects.exists() is False
364
    assert resp.json['err'] == 0
365
    assert resp.json['link'] == link.pk
366
    assert resp.json['family_id'] == 'XXX'
367
    assert resp.json['deleted'] is True
352
-