Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajout d'un score de qualité minimum aux requetes data⋅inclusion #5597

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@

API_DATA_INCLUSION_BASE_URL = os.getenv("API_DATA_INCLUSION_BASE_URL")
API_DATA_INCLUSION_TOKEN = os.getenv("API_DATA_INCLUSION_TOKEN")
API_DATA_INCLUSION_SOURCES = os.getenv("API_DATA_INCLUSION_SOURCES", "").split(",")
API_DATA_INCLUSION_SOURCES = os.getenv("API_DATA_INCLUSION_SOURCES")
API_DATA_INCLUSION_SCORE_QUALITE_MINIMUM = os.getenv("API_DATA_INCLUSION_SCORE_QUALITE_MINIMUM", 0.6)

API_GEIQ_LABEL_BASE_URL = os.getenv("API_GEIQ_LABEL_BASE_URL")
API_GEIQ_LABEL_TOKEN = os.getenv("API_GEIQ_LABEL_TOKEN")
Expand Down
13 changes: 8 additions & 5 deletions itou/utils/apis/data_inclusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ def __init__(self, base_url: str, token: str):
)

def search_services(self, code_insee: str) -> list[dict]:
params = {
"code_insee": code_insee,
"thematiques": API_THEMATIQUES,
"score_qualite_minimum": settings.API_DATA_INCLUSION_SCORE_QUALITE_MINIMUM,
}
if settings.API_DATA_INCLUSION_SOURCES:
params["sources"] = settings.API_DATA_INCLUSION_SOURCES.split(",")
try:
response = self.client.get(
"/search/services",
params={
"code_insee": code_insee,
"sources": settings.API_DATA_INCLUSION_SOURCES,
"thematiques": API_THEMATIQUES,
},
params=params,
).raise_for_status()
except httpx.HTTPError as exc:
logger.info("data.inclusion request error code_insee=%s error=%s", code_insee, exc)
Expand Down
11 changes: 8 additions & 3 deletions tests/utils/apis/test_data_inclusion_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import parse_qs

import httpx
import pytest

Expand All @@ -6,7 +8,6 @@

def test_data_inclusion_client(settings, respx_mock):
client = DataInclusionApiClient("https://fake.api.gouv.fr/", "fake-token")
settings.API_DATA_INCLUSION_SOURCES = "dora,toto"
api_mock = respx_mock.get("https://fake.api.gouv.fr/search/services")
api_mock.respond(
200,
Expand All @@ -26,11 +27,10 @@ def test_data_inclusion_client(settings, respx_mock):
{"id": "svc3"},
{"id": "svc4"},
]
from urllib.parse import parse_qs

assert parse_qs(str(api_mock.calls[0].request.url.params)) == {
"code_insee": ["fake-insee-code"],
"sources": ["dora,toto"],
"score_qualite_minimum": ["0.6"],
"thematiques": [
"acces-aux-droits-et-citoyennete",
"accompagnement-social-et-professionnel-personnalise",
Expand All @@ -42,6 +42,11 @@ def test_data_inclusion_client(settings, respx_mock):
}
assert api_mock.calls[0].request.headers["authorization"] == "Bearer fake-token"

# check setting sources
settings.API_DATA_INCLUSION_SOURCES = "dora,toto"
client.search_services("fake-insee-code")
assert parse_qs(str(api_mock.calls[1].request.url.params))["sources"] == ["dora", "toto"]

# check exceptions
api_mock.respond(200, json={"something": "else"})
with pytest.raises(DataInclusionApiException):
Expand Down