Projet

Général

Profil

0006-api_entreprise-use-v3-in-association-s-document-rela.patch

Emmanuel Cazenave, 14 décembre 2022 14:41

Télécharger (5,22 ko)

Voir les différences:

Subject: [PATCH 6/8] api_entreprise: use v3 in association's document related
 endpoints (#70610)

 passerelle/apps/api_entreprise/models.py | 17 +++++++++---
 tests/test_api_entreprise.py             | 34 ++++++++++++++----------
 2 files changed, 33 insertions(+), 18 deletions(-)
passerelle/apps/api_entreprise/models.py
196 196
    )
197 197
    def documents_associations(self, request, association_id, **kwargs):
198 198
        data = []
199
        resp = self.get('v2/documents_associations/%s/' % association_id, raw=True, **kwargs)
200
        for item in resp.get('documents', []):
199
        resp = self.get(
200
            'v3/ministere_interieur/rna/associations/%s/documents' % association_id, raw=True, **kwargs
201
        )
202
        for _item in resp.get('data', []):
201 203
            # ignore documents with no type
204
            item = _item.get('data', {})
202 205
            if not item.get('type'):
203 206
                continue
204 207
            signature_elements = {
......
270 273
    )
271 274
    def get_last_document_of_type(self, request, association_id, document_type, **kwargs):
272 275
        document = None
273
        resp = self.get('v2/documents_associations/%s/' % association_id, raw=True, **kwargs)
274
        documents = [item for item in resp.get('documents', []) if item.get('type') == document_type]
276
        resp = self.get(
277
            'v3/ministere_interieur/rna/associations/%s/documents' % association_id, raw=True, **kwargs
278
        )
279
        documents = [
280
            item.get('data')
281
            for item in resp.get('data', [])
282
            if item.get('data', {}).get('type') == document_type
283
        ]
275 284
        if documents:
276 285
            documents.sort(key=lambda doc: doc['timestamp'])
277 286
            document = documents[-1]
tests/test_api_entreprise.py
183 183
}
184 184

  
185 185
DOCUMENTS_ASSOCIATION_RESPONSE = {
186
    "nombre_documents": 2,
187
    "documents": [
186
    "meta": {"nombre_documents": 2, "nombre_documents_deficients": 0},
187
    "data": [
188 188
        {
189
            "type": "Statuts",
190
            "url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/attestation_document_association.pdf",
191
            "timestamp": "1500660325",
189
            "data": {
190
                "type": "Statuts",
191
                "url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/attestation_document_association.pdf",
192
                "timestamp": "1500660325",
193
            },
192 194
        },
193 195
        {
194
            "type": "Récépissé",
195
            "url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/recepisse_association.pdf",
196
            "timestamp": "1500667325",
196
            "data": {
197
                "type": "Récépissé",
198
                "url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/recepisse_association.pdf",
199
                "timestamp": "1500667325",
200
            },
197 201
        },
198 202
        {
199
            "timestamp": "1337158058",
200
            "url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/attestation_document_association.pdf",
201
            "type": "Statuts",
203
            "data": {
204
                "timestamp": "1337158058",
205
                "url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/attestation_document_association.pdf",
206
                "type": "Statuts",
207
            },
202 208
        },
203 209
    ],
204 210
}
......
446 452
def test_documents_associations_endpoint(app, resource):
447 453
    with responses.RequestsMock() as rsps:
448 454
        rsps.get(
449
            'https://entreprise.api.gouv.fr/v2/documents_associations/443170139/',
455
            'https://entreprise.api.gouv.fr/v3/ministere_interieur/rna/associations/443170139/documents',
450 456
            json=DOCUMENTS_ASSOCIATION_RESPONSE,
451 457
        )
452 458

  
......
465 471
def test_associations_last_document_of_type_endpoint(app, resource):
466 472
    with responses.RequestsMock() as rsps:
467 473
        rsps.get(
468
            'https://entreprise.api.gouv.fr/v2/documents_associations/443170139/',
474
            'https://entreprise.api.gouv.fr/v3/ministere_interieur/rna/associations/443170139/documents',
469 475
            json=DOCUMENTS_ASSOCIATION_RESPONSE,
470 476
        )
471 477

  
......
501 507
def test_document_association(app, resource, freezer):
502 508
    with responses.RequestsMock() as rsps:
503 509
        rsps.get(
504
            'https://entreprise.api.gouv.fr/v2/documents_associations/443170139/',
510
            'https://entreprise.api.gouv.fr/v3/ministere_interieur/rna/associations/443170139/documents',
505 511
            json=DOCUMENTS_ASSOCIATION_RESPONSE,
506 512
        )
507 513

  
508
-