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={ |
... | ... | |
733 | 733 |
assert 'anciennes_cles_de_federation' not in get_content(first_id) |
734 | 734 |
assert 'anciennes_cles_de_federation' not in get_content(enfant_id) |
735 | 735 | |
736 | ||
736 | 737 |
with httmock.HTTMock(technocarte_ok): |
737 | 738 |
job = Job.objects.get() |
738 | 739 |
job.state = Job.STATE_TODO |
... | ... | |
789 | 790 |
for i, r in enumerate(responses): |
790 | 791 |
assert r.json['err'] == 0 |
791 | 792 | |
793 |
# test obtention de clés de fédération |
|
794 |
def get_federation(uuid, **kwargs): |
|
795 |
return app.get('/rsu/individu/%s/federation/technocarte/' % uuid, **kwargs).json |
|
796 |
first = Entity.objects.get(id=first_id) |
|
797 |
first.content['cles_de_federation']['authentic'] = 'abcd' |
|
798 |
first.save() |
|
799 |
enfant = Entity.objects.get(id=enfant_id) |
|
800 |
enfant.content['cles_de_federation']['authentic'] = 'efgh' |
|
801 |
enfant.save() |
|
802 |
settings.ZOO_NANTERRE_APPLICATIONS['technocarte']['apikey'] = 'xyz' |
|
803 |
assert get_federation('abcd', status=401)['err'] == 1 |
|
804 |
assert get_federation('efgh', status=401)['err'] == 1 |
|
805 |
assert get_federation('abcd', params={'apikey': 'xyz'})['cle_de_federation'] == '1234' |
|
806 |
assert get_federation('efgh', params={'apikey': 'xyz'})['cle_de_federation'] == '5678' |
|
807 | ||
792 | 808 | |
793 | 809 |
@pytest.mark.django_db(True) |
794 | 810 |
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 apikey and request.GET.get('apikey') != apikey: |
|
1473 |
return Response({'err': 1, 'errors': ['apikey invalide']}, status=401) |
|
1474 |
individu = self.get_individu(identifier) |
|
1475 |
return Response({'err': 0, 'cle_de_federation': individu.content['cles_de_federation'].get(application)}) |
|
1476 | ||
1477 |
federation = Federation.as_view() |
|
1478 | ||
1479 | ||
1466 | 1480 |
class SagaTiers(APIView): |
1467 | 1481 |
def get(self, request, application, identifier, format=None): |
1468 | 1482 |
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 |
- |