api_entreprise: use v3 in association's document related endpoints (#70610)
This commit is contained in:
parent
35df56d019
commit
25048709dc
|
@ -196,9 +196,12 @@ class APIEntreprise(BaseResource):
|
|||
)
|
||||
def documents_associations(self, request, association_id, **kwargs):
|
||||
data = []
|
||||
resp = self.get('v2/documents_associations/%s/' % association_id, raw=True, **kwargs)
|
||||
for item in resp.get('documents', []):
|
||||
resp = self.get(
|
||||
'v3/ministere_interieur/rna/associations/%s/documents' % association_id, raw=True, **kwargs
|
||||
)
|
||||
for _item in resp.get('data', []):
|
||||
# ignore documents with no type
|
||||
item = _item.get('data', {})
|
||||
if not item.get('type'):
|
||||
continue
|
||||
signature_elements = {
|
||||
|
@ -270,8 +273,14 @@ class APIEntreprise(BaseResource):
|
|||
)
|
||||
def get_last_document_of_type(self, request, association_id, document_type, **kwargs):
|
||||
document = None
|
||||
resp = self.get('v2/documents_associations/%s/' % association_id, raw=True, **kwargs)
|
||||
documents = [item for item in resp.get('documents', []) if item.get('type') == document_type]
|
||||
resp = self.get(
|
||||
'v3/ministere_interieur/rna/associations/%s/documents' % association_id, raw=True, **kwargs
|
||||
)
|
||||
documents = [
|
||||
item.get('data')
|
||||
for item in resp.get('data', [])
|
||||
if item.get('data', {}).get('type') == document_type
|
||||
]
|
||||
if documents:
|
||||
documents.sort(key=lambda doc: doc['timestamp'])
|
||||
document = documents[-1]
|
||||
|
|
|
@ -183,22 +183,28 @@ ASSOCIATIONS_RESPONSE = {
|
|||
}
|
||||
|
||||
DOCUMENTS_ASSOCIATION_RESPONSE = {
|
||||
"nombre_documents": 2,
|
||||
"documents": [
|
||||
"meta": {"nombre_documents": 2, "nombre_documents_deficients": 0},
|
||||
"data": [
|
||||
{
|
||||
"type": "Statuts",
|
||||
"url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/attestation_document_association.pdf",
|
||||
"timestamp": "1500660325",
|
||||
"data": {
|
||||
"type": "Statuts",
|
||||
"url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/attestation_document_association.pdf",
|
||||
"timestamp": "1500660325",
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "Récépissé",
|
||||
"url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/recepisse_association.pdf",
|
||||
"timestamp": "1500667325",
|
||||
"data": {
|
||||
"type": "Récépissé",
|
||||
"url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/recepisse_association.pdf",
|
||||
"timestamp": "1500667325",
|
||||
},
|
||||
},
|
||||
{
|
||||
"timestamp": "1337158058",
|
||||
"url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/attestation_document_association.pdf",
|
||||
"type": "Statuts",
|
||||
"data": {
|
||||
"timestamp": "1337158058",
|
||||
"url": "https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/attestation_document_association.pdf",
|
||||
"type": "Statuts",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -446,7 +452,7 @@ def test_associations_endpoint(app, resource):
|
|||
def test_documents_associations_endpoint(app, resource):
|
||||
with responses.RequestsMock() as rsps:
|
||||
rsps.get(
|
||||
'https://entreprise.api.gouv.fr/v2/documents_associations/443170139/',
|
||||
'https://entreprise.api.gouv.fr/v3/ministere_interieur/rna/associations/443170139/documents',
|
||||
json=DOCUMENTS_ASSOCIATION_RESPONSE,
|
||||
)
|
||||
|
||||
|
@ -465,7 +471,7 @@ def test_documents_associations_endpoint(app, resource):
|
|||
def test_associations_last_document_of_type_endpoint(app, resource):
|
||||
with responses.RequestsMock() as rsps:
|
||||
rsps.get(
|
||||
'https://entreprise.api.gouv.fr/v2/documents_associations/443170139/',
|
||||
'https://entreprise.api.gouv.fr/v3/ministere_interieur/rna/associations/443170139/documents',
|
||||
json=DOCUMENTS_ASSOCIATION_RESPONSE,
|
||||
)
|
||||
|
||||
|
@ -501,7 +507,7 @@ def test_extraits_rcs(app, resource):
|
|||
def test_document_association(app, resource, freezer):
|
||||
with responses.RequestsMock() as rsps:
|
||||
rsps.get(
|
||||
'https://entreprise.api.gouv.fr/v2/documents_associations/443170139/',
|
||||
'https://entreprise.api.gouv.fr/v3/ministere_interieur/rna/associations/443170139/documents',
|
||||
json=DOCUMENTS_ASSOCIATION_RESPONSE,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue