0001-nanterre-ajoute-un-ws-de-r-cup-ration-de-cl-de-f-d-r.patch
tests/test_nanterre.py | ||
---|---|---|
67 | 67 |
assert any(data['id'] == rsu[0].id for data in response.json['data']) |
68 | 68 | |
69 | 69 | |
70 |
def test_create_individu(transactional_db, app, rsu_schema): |
|
70 |
def test_create_individu(settings, transactional_db, app, rsu_schema):
|
|
71 | 71 | |
72 | 72 |
def get_reseau(identifier): |
73 | 73 |
reseau_url = reverse('rsu-api-reseau', kwargs={ |
... | ... | |
789 | 789 |
for i, r in enumerate(responses): |
790 | 790 |
assert r.json['err'] == 0 |
791 | 791 | |
792 |
# test obtention de clés de fédération |
|
793 |
def get_federation(uuid, **kwargs): |
|
794 |
return app.get('/rsu/individu/%s/federation/technocarte/' % uuid, **kwargs).json |
|
795 |
first = Entity.objects.get(id=first_id) |
|
796 |
first.content['cles_de_federation']['authentic'] = 'abcd' |
|
797 |
first.save() |
|
798 |
enfant = Entity.objects.get(id=enfant_id) |
|
799 |
enfant.content['cles_de_federation']['authentic'] = 'efgh' |
|
800 |
enfant.save() |
|
801 | ||
802 |
assert get_federation('abcd', status=403)['err'] == 1 |
|
803 |
assert get_federation('efgh', status=403)['err'] == 1 |
|
804 | ||
805 |
settings.ZOO_NANTERRE_APPLICATIONS['technocarte']['apikey'] = 'xyz' |
|
806 |
assert get_federation('abcd', status=401)['err'] == 1 |
|
807 |
assert get_federation('efgh', status=401)['err'] == 1 |
|
808 |
assert get_federation('abcd', params={'apikey': 'xyz'})['cle_de_federation'] == '1234' |
|
809 |
assert get_federation('efgh', params={'apikey': 'xyz'})['cle_de_federation'] == '5678' |
|
810 | ||
811 |
settings.ZOO_NANTERRE_APPLICATIONS['technocarte']['apikey'] = '' |
|
812 |
assert get_federation('abcd', params={'apikey': 'xyz'}, status=403)['err'] == 1 |
|
813 | ||
814 |
del settings.ZOO_NANTERRE_APPLICATIONS['technocarte']['apikey'] |
|
815 |
assert get_federation('abcd', params={'apikey': 'xyz'}, status=403)['err'] == 1 |
|
792 | 816 | |
793 | 817 |
@pytest.mark.django_db(True) |
794 | 818 |
def test_cles_de_federations(app, rsu_schema): |
zoo/zoo_nanterre/api_views.py | ||
---|---|---|
1463 | 1463 |
suppression_individu = SuppressionIndividu.as_view() |
1464 | 1464 | |
1465 | 1465 | |
1466 |
class Federation(IndividuViewMixin, APIView): |
|
1467 |
def get(self, request, identifier, application, format=None): |
|
1468 |
app_dfn = utils.get_application(application) |
|
1469 |
if not app_dfn: |
|
1470 |
raise Http404 |
|
1471 |
apikey = app_dfn.get('apikey') |
|
1472 |
if not apikey: |
|
1473 |
return Response({'err': 1, 'errors': ['accès interdit']}, status=403) |
|
1474 |
if request.GET.get('apikey') != apikey: |
|
1475 |
return Response({'err': 1, 'errors': ['apikey invalide']}, status=401) |
|
1476 |
individu = self.get_individu(identifier) |
|
1477 |
return Response({'err': 0, 'cle_de_federation': individu.content['cles_de_federation'].get(application)}) |
|
1478 | ||
1479 |
federation = Federation.as_view() |
|
1480 | ||
1481 | ||
1466 | 1482 |
class SagaTiers(APIView): |
1467 | 1483 |
def get(self, request, application, identifier, format=None): |
1468 | 1484 |
app_dfn = utils.get_application(application) |
zoo/zoo_nanterre/urls.py | ||
---|---|---|
48 | 48 |
api_views.suppression_lien_de_responsabilite, |
49 | 49 |
name='rsu-api-suppression-lien-de-responsabilite'), |
50 | 50 |
url(r'^individu/$', api_views.create_individu, name='rsu-api-create-individu'), |
51 |
url(r'^individu/(?P<identifier>[-\w]+)/federation/(?P<application>\w+)/$', api_views.federation, |
|
52 |
name='rsu-api-federation'), |
|
51 | 53 |
url(r'^declaration-union/$', api_views.declaration_union, |
52 | 54 |
name='rsu-api-declaration-union'), |
53 | 55 |
url(r'^synchronisation/$', api_views.synchronization, |
54 |
- |