From 7c30a795a880f8ecfb76e44308181a893a0db5a7 Mon Sep 17 00:00:00 2001
From: Emmanuel Cazenave <ecazenave@entrouvert.com>
Date: Mon, 24 Oct 2022 17:33:29 +0200
Subject: [PATCH 1/8] api_entreprise: use responses in unit tests (#70610)

---
 tests/test_api_entreprise.py | 399 +++++++++++++++++------------------
 1 file changed, 197 insertions(+), 202 deletions(-)

diff --git a/tests/test_api_entreprise.py b/tests/test_api_entreprise.py
index afc76cd0..161333e0 100644
--- a/tests/test_api_entreprise.py
+++ b/tests/test_api_entreprise.py
@@ -18,8 +18,8 @@ from unittest import mock
 
 import pytest
 import requests
+import responses
 from django.utils import timezone
-from httmock import HTTMock, response, urlmatch
 
 from passerelle.apps.api_entreprise.models import APIEntreprise
 from tests.utils import FakedResponse, make_resource
@@ -247,94 +247,6 @@ DOCUMENT_ASSOCIATION_RESPONSE = "binary content"
 REQUEST_PARAMS = {'context': 'MSP', 'object': 'demand', 'recipient': 'siret'}
 
 
-@urlmatch(netloc='^entreprise.api.gouv.fr$', path='^/v2/etablissements/')
-def api_entreprise_etablissements(url, request):
-    return response(200, ETABLISSEMENTS_RESPONSE, request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$', path='^/v2/entreprises/')
-def api_entreprise_entreprises(url, request):
-    return response(200, ENTREPRISES_RESPONSE, request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$', path='^/v2/associations/')
-def api_entreprise_associations(url, request):
-    return response(200, ASSOCIATIONS_RESPONSE, request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$', path='^/v2/extraits_rcs_infogreffe/')
-def api_entreprise_extraits_rcs(url, request):
-    return response(200, EXTRAITS_RCS_RESPONSE, request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$', path='^/v2/documents_associations/')
-def api_entreprise_documents_associations(url, request):
-    return response(200, DOCUMENTS_ASSOCIATION_RESPONSE, request=request)
-
-
-@urlmatch(netloc='^apientreprise.fr$', path='^/attestations/')
-def api_entreprise_document_association(url, request):
-    return response(200, DOCUMENT_ASSOCIATION_RESPONSE, request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$', path='^/v2/effectifs_annuels_acoss_covid/')
-def effectifs_annuels_acoss_covid(url, request):
-    return response(200, EFFECTIFS_ANNUELS_ACOSS_COVID, request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$', path='^/v2/effectifs_mensuels_acoss_covid/.*/entreprise')
-def entreprise_effectifs_mensuels_acoss_covid(url, request):
-    return response(200, ENTREPRISE_EFFECTIFS_MENSUELS_ACOSS_COVID, request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$', path='^/v2/effectifs_mensuels_acoss_covid/.*/etablissement')
-def etablisssment_effectifs_mensuels_acoss_covid(url, request):
-    return response(200, ETABLISSEMENT_EFFECTIFS_MENSUELS_ACOSS_COVID, request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$', path='^/v2/exercices')
-def api_entreprise_exercices(url, request):
-    return response(200, EXERCICES_RESPONSE, request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$')
-def api_entreprise_error_500(url, request):
-    return response(500, 'bad error happened', request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$')
-def api_entreprise_connection_error(url, request):
-    raise requests.RequestException('connection timed-out')
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$')
-def api_entreprise_error_not_json(url, request):
-    return response(200, 'simple text', request=request)
-
-
-@urlmatch(netloc='^entreprise.api.gouv.fr$')
-def api_entreprise_error_not_found(url, request):
-    return response(404, {'error': 'not_found', 'message': 'Page not found'}, request=request)
-
-
-@pytest.yield_fixture
-def mock_api_entreprise():
-    with HTTMock(
-        api_entreprise_etablissements,
-        api_entreprise_entreprises,
-        api_entreprise_associations,
-        api_entreprise_extraits_rcs,
-        api_entreprise_associations,
-        api_entreprise_documents_associations,
-        api_entreprise_document_association,
-        effectifs_annuels_acoss_covid,
-        entreprise_effectifs_mensuels_acoss_covid,
-        etablisssment_effectifs_mensuels_acoss_covid,
-        api_entreprise_exercices,
-    ):
-        yield None
-
-
 @pytest.fixture
 def resource(db):
     return make_resource(
@@ -363,8 +275,10 @@ def test_endpoint_with_no_params(mocked_get, app, resource):
     assert mocked_get.call_args[1]['data']['recipient'] == 'Custom recipient'
 
 
-def test_entreprises_endpoint(app, resource, mock_api_entreprise):
-    response = app.get('/api-entreprise/test/entreprises/443170139/', params=REQUEST_PARAMS)
+def test_entreprises_endpoint(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get('https://entreprise.api.gouv.fr/v2/entreprises/443170139/', json=ENTREPRISES_RESPONSE)
+        response = app.get('/api-entreprise/test/entreprises/443170139/', params=REQUEST_PARAMS)
     data = response.json['data']
     assert data['entreprise']['categorie_entreprise'] == 'PME'
     assert data['entreprise']['numero_tva_intracommunautaire'] == 'FR16418166096'
@@ -385,7 +299,7 @@ def test_entreprises_endpoint(app, resource, mock_api_entreprise):
     assert data['etablissement_siege']['date_mise_a_jour'] == '2015-12-03'
 
 
-def test_simple_match_mandataire_social(app, resource, mock_api_entreprise):
+def test_simple_match_mandataire_social(app, resource):
     params = {
         'first_name': 'françois',
         'last_name': 'hIsQuIn',
@@ -394,40 +308,42 @@ def test_simple_match_mandataire_social(app, resource, mock_api_entreprise):
     }
     params.update(REQUEST_PARAMS)
 
-    url = '/api-entreprise/test/match_mandataire_social/443170139/'
-    response = app.get(url, params=params)
+    with responses.RequestsMock() as rsps:
+        rsps.get('https://entreprise.api.gouv.fr/v2/entreprises/443170139/', json=ENTREPRISES_RESPONSE)
+        url = '/api-entreprise/test/match_mandataire_social/443170139/'
+        response = app.get(url, params=params)
 
-    # successful matching
-    data = response.json['data']
-    assert data['nom'] == 'HISQUIN'
-    assert data['prenom'] == 'FRANCOIS'
-    assert data['date_naissance'] == '1965-01-27'
-    assert data['type'] == 'PP'
+        # successful matching
+        data = response.json['data']
+        assert data['nom'] == 'HISQUIN'
+        assert data['prenom'] == 'FRANCOIS'
+        assert data['date_naissance'] == '1965-01-27'
+        assert data['type'] == 'PP'
 
-    params['method'] = 'unkwown'
-    response = app.get(url, params=params)
+        params['method'] = 'unkwown'
+        response = app.get(url, params=params)
 
-    # unsupported method
-    assert response.json['err']
-    assert 'data' not in response.json
+        # unsupported method
+        assert response.json['err']
+        assert 'data' not in response.json
 
-    params['method'] = 'simple'
-    params.pop('first_name')
-    response = app.get(url, params=params, status=400)
+        params['method'] = 'simple'
+        params.pop('first_name')
+        response = app.get(url, params=params, status=400)
 
-    # missing parameter
-    assert not response.json['data']
-    assert 'missing parameter' in response.json['err_desc']
+        # missing parameter
+        assert not response.json['data']
+        assert 'missing parameter' in response.json['err_desc']
 
-    params['first_name'] = 'JOHN'
-    response = app.get(url, params=params)
+        params['first_name'] = 'JOHN'
+        response = app.get(url, params=params)
 
-    # matching failed
-    assert not response.json['err']
-    assert not response.json['data']
+        # matching failed
+        assert not response.json['err']
+        assert not response.json['data']
 
 
-def test_levenshtein_match_mandataire_social(app, resource, mock_api_entreprise):
+def test_levenshtein_match_mandataire_social(app, resource):
     params = {
         'first_name': 'françois',
         'last_name': 'hIsQuIn',
@@ -436,50 +352,58 @@ def test_levenshtein_match_mandataire_social(app, resource, mock_api_entreprise)
     }
     params.update(REQUEST_PARAMS)
 
-    url = '/api-entreprise/test/match_mandataire_social/443170139/'
-    response = app.get(url, params=params)
+    with responses.RequestsMock() as rsps:
+        rsps.get('https://entreprise.api.gouv.fr/v2/entreprises/443170139/', json=ENTREPRISES_RESPONSE)
 
-    # successful matching
-    data = response.json['data']
-    assert data['nom'] == 'HISQUIN'
-    assert data['prenom'] == 'FRANCOIS'
-    assert data['date_naissance'] == '1965-01-27'
-    assert data['type'] == 'PP'
+        url = '/api-entreprise/test/match_mandataire_social/443170139/'
+        response = app.get(url, params=params)
 
-    params['first_name'] = 'JOHN'
-    response = app.get(url, params=params)
+        # successful matching
+        data = response.json['data']
+        assert data['nom'] == 'HISQUIN'
+        assert data['prenom'] == 'FRANCOIS'
+        assert data['date_naissance'] == '1965-01-27'
+        assert data['type'] == 'PP'
 
-    # matching failed
-    assert not response.json['err']
-    assert not response.json['data']
+        params['first_name'] = 'JOHN'
+        response = app.get(url, params=params)
 
-    params['first_name'] = 'francoi'
-    params['last_name'] = 'hisquinn'
-    response = app.get(url, params=params)
+        # matching failed
+        assert not response.json['err']
+        assert not response.json['data']
 
-    # successful matching within distance bracket
-    data = response.json['data']
-    assert data['nom'] == 'HISQUIN'
-    assert data['prenom'] == 'FRANCOIS'
-    assert data['date_naissance'] == '1965-01-27'
-    assert data['type'] == 'PP'
+        params['first_name'] = 'francoi'
+        params['last_name'] = 'hisquinn'
+        response = app.get(url, params=params)
 
+        # successful matching within distance bracket
+        data = response.json['data']
+        assert data['nom'] == 'HISQUIN'
+        assert data['prenom'] == 'FRANCOIS'
+        assert data['date_naissance'] == '1965-01-27'
+        assert data['type'] == 'PP'
 
-@mock.patch('passerelle.utils.Request.get')
-def test_entreprises_endpoint_include_private(mocked_get, app, resource, mock_api_entreprise):
-    mocked_get.return_value = FakedResponse(content='{}', status_code=200)
-    request_params = REQUEST_PARAMS.copy()
 
-    app.get('/api-entreprise/test/entreprises/443170139/', params=request_params)
-    assert 'non_diffusables' not in mocked_get.mock_calls[0].kwargs['data']
+def test_entreprises_endpoint_include_private(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get('https://entreprise.api.gouv.fr/v2/entreprises/443170139/', json=ENTREPRISES_RESPONSE)
 
-    request_params['include_private'] = True
-    app.get('/api-entreprise/test/entreprises/443170139/', params=request_params)
-    assert mocked_get.mock_calls[1].kwargs['data']['non_diffusables'] == 'true'
+        request_params = REQUEST_PARAMS.copy()
 
+        app.get('/api-entreprise/test/entreprises/443170139/', params=request_params)
+        assert 'non_diffusables' not in rsps.calls[-1].request.body
 
-def test_etablissements_endpoint(app, resource, mock_api_entreprise):
-    response = app.get('/api-entreprise/test/etablissements/44317013900036/', params=REQUEST_PARAMS)
+        request_params['include_private'] = True
+        app.get('/api-entreprise/test/entreprises/443170139/', params=request_params)
+        assert 'non_diffusables=true' in rsps.calls[-1].request.body
+
+
+def test_etablissements_endpoint(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/etablissements/44317013900036/', json=ETABLISSEMENTS_RESPONSE
+        )
+        response = app.get('/api-entreprise/test/etablissements/44317013900036/', params=REQUEST_PARAMS)
     assert 'data' in response.json
     data = response.json['data']
 
@@ -495,8 +419,10 @@ def test_etablissements_endpoint(app, resource, mock_api_entreprise):
     assert data['etablissement']['adresse']['code_insee_localite'] == '75108'
 
 
-def test_associations_endpoint(app, resource, mock_api_entreprise):
-    response = app.get('/api-entreprise/test/associations/443170139/', params=REQUEST_PARAMS)
+def test_associations_endpoint(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get('https://entreprise.api.gouv.fr/v2/associations/443170139/', json=ASSOCIATIONS_RESPONSE)
+        response = app.get('/api-entreprise/test/associations/443170139/', params=REQUEST_PARAMS)
     assert 'data' in response.json
     data = response.json['data']
 
@@ -512,8 +438,14 @@ def test_associations_endpoint(app, resource, mock_api_entreprise):
     assert data['association']['adresse_siege']['code_insee'] == '75120'
 
 
-def test_documents_associations_endpoint(app, resource, mock_api_entreprise):
-    response = app.get('/api-entreprise/test/documents_associations/443170139/', params=REQUEST_PARAMS)
+def test_documents_associations_endpoint(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/documents_associations/443170139/',
+            json=DOCUMENTS_ASSOCIATION_RESPONSE,
+        )
+
+        response = app.get('/api-entreprise/test/documents_associations/443170139/', params=REQUEST_PARAMS)
     assert 'data' in response.json
     data = response.json['data']
     assert len(data) == 3
@@ -525,21 +457,31 @@ def test_documents_associations_endpoint(app, resource, mock_api_entreprise):
         assert 'datetime' in document
 
 
-def test_associations_last_document_of_type_endpoint(app, resource, mock_api_entreprise):
-    params = REQUEST_PARAMS
-    params['document_type'] = 'Statuts'
-    response = app.get('/api-entreprise/test/document_association/443170139/get-last/', params=params)
-    assert 'data' in response.json
-    data = response.json['data']
-    assert data['timestamp'] == '1500660325'
+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/',
+            json=DOCUMENTS_ASSOCIATION_RESPONSE,
+        )
+
+        params = REQUEST_PARAMS
+        params['document_type'] = 'Statuts'
+        response = app.get('/api-entreprise/test/document_association/443170139/get-last/', params=params)
+        assert 'data' in response.json
+        data = response.json['data']
+        assert data['timestamp'] == '1500660325'
 
-    params['document_type'] = 'Liste des dirigeants'
-    response = app.get('/api-entreprise/test/document_association/443170139/get-last/', params=params)
-    assert not response.json['data']
+        params['document_type'] = 'Liste des dirigeants'
+        response = app.get('/api-entreprise/test/document_association/443170139/get-last/', params=params)
+        assert not response.json['data']
 
 
-def test_extraits_rcs(app, resource, mock_api_entreprise, freezer):
-    response = app.get('/api-entreprise/test/extraits_rcs/443170139/', params=REQUEST_PARAMS)
+def test_extraits_rcs(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/extraits_rcs_infogreffe/443170139/', json=EXTRAITS_RCS_RESPONSE
+        )
+        response = app.get('/api-entreprise/test/extraits_rcs/443170139/', params=REQUEST_PARAMS)
     assert 'data' in response.json
     data = response.json['data']
 
@@ -550,36 +492,65 @@ def test_extraits_rcs(app, resource, mock_api_entreprise, freezer):
     assert data['date_immatriculation_datetime'] == '1998-03-26T23:00:00Z'
 
 
-def test_document_association(app, resource, mock_api_entreprise, freezer):
-    response = app.get('/api-entreprise/test/documents_associations/443170139/', params=REQUEST_PARAMS)
-    assert 'data' in response.json
-    data = response.json['data']
-    assert len(data) == 3
-    document = data[0]
-    assert 'url' in document
-    app.get(document['url'], params={'context': 'MSP', 'object': 'demand', 'recipient': 'siret'}, status=200)
-    # try to get document with wrong signature
-    wrong_url = document['url'] + "wrong/"
-    app.get(wrong_url, status=404)
+def test_document_association(app, resource, freezer):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/documents_associations/443170139/',
+            json=DOCUMENTS_ASSOCIATION_RESPONSE,
+        )
+
+        response = app.get('/api-entreprise/test/documents_associations/443170139/', params=REQUEST_PARAMS)
+        assert 'data' in response.json
+        data = response.json['data']
+        assert len(data) == 3
+        document = data[0]
+        assert 'url' in document
+
+        rsps.get(
+            'https://apientreprise.fr/attestations/40ab0b07d434d0417e8997ce7c5afbef/attestation_document_association.pdf',
+            body='binary content',
+        )
 
-    # try expired url
-    freezer.move_to(timezone.now() + timezone.timedelta(days=8))
-    app.get(document['url'], status=404)
+        app.get(
+            document['url'], params={'context': 'MSP', 'object': 'demand', 'recipient': 'siret'}, status=200
+        )
+        # try to get document with wrong signature
+        wrong_url = document['url'] + "wrong/"
+        app.get(wrong_url, status=404)
+
+        # try expired url
+        freezer.move_to(timezone.now() + timezone.timedelta(days=8))
+        app.get(document['url'], status=404)
 
 
-def test_effectifs_annuels_acoss_covid(app, resource, mock_api_entreprise, freezer):
-    response = app.get('/api-entreprise/test/effectifs_annuels_acoss_covid/418166096/', params=REQUEST_PARAMS)
+def test_effectifs_annuels_acoss_covid(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/effectifs_annuels_acoss_covid/418166096/',
+            json=EFFECTIFS_ANNUELS_ACOSS_COVID,
+        )
+
+        response = app.get(
+            '/api-entreprise/test/effectifs_annuels_acoss_covid/418166096/', params=REQUEST_PARAMS
+        )
     data = response.json['data']
     assert data['siren'] == '418166096'
     assert data['annee'] == '2019'
     assert data['effectifs_annuels'] == 100.5
 
 
-def test_entreprise_effectifs_mensuels_acoss_covid(app, resource, mock_api_entreprise, freezer):
-    response = app.get(
-        '/api-entreprise/test/entreprise_effectifs_mensuels_acoss_covid/2019/02/418166096/',
-        params=REQUEST_PARAMS,
-    )
+def test_entreprise_effectifs_mensuels_acoss_covid(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/effectifs_mensuels_acoss_covid/2019/02/entreprise/418166096/',
+            json=ENTREPRISE_EFFECTIFS_MENSUELS_ACOSS_COVID,
+        )
+
+        response = app.get(
+            '/api-entreprise/test/entreprise_effectifs_mensuels_acoss_covid/2019/02/418166096/',
+            params=REQUEST_PARAMS,
+        )
+
     data = response.json['data']
     assert data['siren'] == '418166096'
     assert data['annee'] == '2019'
@@ -587,11 +558,17 @@ def test_entreprise_effectifs_mensuels_acoss_covid(app, resource, mock_api_entre
     assert data['effectifs_mensuels'] == 100.5
 
 
-def test_etablissment_effectifs_mensuels_acoss_covid(app, resource, mock_api_entreprise, freezer):
-    response = app.get(
-        '/api-entreprise/test/etablissement_effectifs_mensuels_acoss_covid/2019/02/418166096/',
-        params=REQUEST_PARAMS,
-    )
+def test_etablissment_effectifs_mensuels_acoss_covid(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/effectifs_mensuels_acoss_covid/2019/02/etablissement/418166096/',
+            json=ETABLISSEMENT_EFFECTIFS_MENSUELS_ACOSS_COVID,
+        )
+
+        response = app.get(
+            '/api-entreprise/test/etablissement_effectifs_mensuels_acoss_covid/2019/02/418166096/',
+            params=REQUEST_PARAMS,
+        )
     data = response.json['data']
     assert data['siret'] == '41816609600051'
     assert data['annee'] == '2019'
@@ -599,8 +576,10 @@ def test_etablissment_effectifs_mensuels_acoss_covid(app, resource, mock_api_ent
     assert data['effectifs_mensuels'] == 100.5
 
 
-def test_exercices(app, resource, mock_api_entreprise, freezer):
-    response = app.get('/api-entreprise/test/exercices/418166096/', params=REQUEST_PARAMS)
+def test_exercices(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get('https://entreprise.api.gouv.fr/v2/exercices/418166096/', json=EXERCICES_RESPONSE)
+        response = app.get('/api-entreprise/test/exercices/418166096/', params=REQUEST_PARAMS)
     data = response.json['data']
     assert len(data['exercices']) == 3
     exercice = data['exercices'][0]
@@ -610,8 +589,11 @@ def test_exercices(app, resource, mock_api_entreprise, freezer):
     assert exercice['date_fin_exercice_datetime'] == '2016-12-30T23:00:00Z'
 
 
-def test_error_500(app, resource, mock_api_entreprise):
-    with HTTMock(api_entreprise_error_500):
+def test_error_500(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/entreprises/443170139/', body='bad error happened', status=500
+        )
         response = app.get('/api-entreprise/test/entreprises/443170139/', params=REQUEST_PARAMS)
         assert response.status_code == 200
         assert response.json['err'] == 1
@@ -619,8 +601,12 @@ def test_error_500(app, resource, mock_api_entreprise):
         assert 'error happened' in response.json['err_desc']
 
 
-def test_no_json_error(app, resource, mock_api_entreprise):
-    with HTTMock(api_entreprise_error_not_json):
+def test_no_json_error(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/entreprises/443170139/',
+            body='simple text',
+        )
         response = app.get('/api-entreprise/test/entreprises/443170139/', params=REQUEST_PARAMS)
         assert response.status_code == 200
         assert response.json['err'] == 1
@@ -630,16 +616,25 @@ def test_no_json_error(app, resource, mock_api_entreprise):
         )
 
 
-def test_error_404(app, resource, mock_api_entreprise):
-    with HTTMock(api_entreprise_error_not_found):
+def test_error_404(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/entreprises/443170139/',
+            json={'error': 'not_found', 'message': 'Page not found'},
+            status=404,
+        )
         response = app.get('/api-entreprise/test/entreprises/443170139/', params=REQUEST_PARAMS)
         assert response.status_code == 200
         assert response.json['err'] == 1
         assert response.json['err_desc'] == 'Page not found'
 
 
-def test_connection_error(app, resource, mock_api_entreprise):
-    with HTTMock(api_entreprise_connection_error):
+def test_connection_error(app, resource):
+    with responses.RequestsMock() as rsps:
+        rsps.get(
+            'https://entreprise.api.gouv.fr/v2/entreprises/443170139/',
+            body=requests.RequestException('connection timed-out'),
+        )
         response = app.get('/api-entreprise/test/entreprises/443170139/', params=REQUEST_PARAMS)
         assert response.status_code == 200
         assert response.json['err'] == 1
-- 
2.30.2

