diff --git a/api/src/data_inclusion/api/inclusion_data/routes.py b/api/src/data_inclusion/api/inclusion_data/routes.py index c5554807..1a702178 100644 --- a/api/src/data_inclusion/api/inclusion_data/routes.py +++ b/api/src/data_inclusion/api/inclusion_data/routes.py @@ -1,10 +1,8 @@ from typing import Annotated, TypeVar -from furl import furl from pydantic.json_schema import SkipJsonSchema import fastapi -from fastapi.responses import RedirectResponse from data_inclusion import schema as di_schema from data_inclusion.api import auth @@ -130,44 +128,6 @@ def retrieve_service_endpoint( return services.retrieve_service(db_session=db_session, source=source, id_=id) -@router.get( - "/services/{source}/{id}/redirige", - include_in_schema=False, -) -def redirect_service_endpoint( - request: fastapi.Request, - source: Annotated[str, fastapi.Path()], - id: Annotated[str, fastapi.Path()], - depuis: Annotated[str, fastapi.Query()], - db_session=fastapi.Depends(db.get_session), -): - """Redirige vers le lien source du service donné""" - - # This endpoint is not token restricted. - # This is to record redirections stemming from 3rd party website - # like les emplois, while keeping things simple for the 3rd party. - - # The required `depuis` query param only purpose is to associate - # the query to a consumer, since there is not token authentication. - - # The redirection should forward any other query parameters, such - # as utm query parameters - - service_instance = services.retrieve_service( - db_session=db_session, source=source, id_=id - ) - - if service_instance.lien_source is None: - return fastapi.Response(status_code=fastapi.status.HTTP_404_NOT_FOUND) - - params = dict(request.query_params) - del params["depuis"] - - target_url = furl(str(service_instance.lien_source)).add(params) - - return RedirectResponse(str(target_url)) - - @router.get( "/search/services", response_model=pagination.BigPage[schemas.ServiceSearchResult], diff --git a/api/tests/e2e/api/test_inclusion_data.py b/api/tests/e2e/api/test_inclusion_data.py index 90f4570a..ee1366fe 100644 --- a/api/tests/e2e/api/test_inclusion_data.py +++ b/api/tests/e2e/api/test_inclusion_data.py @@ -3,10 +3,8 @@ from unittest.mock import ANY import pytest -import sqlalchemy as sqla from data_inclusion import schema -from data_inclusion.api.request import models from data_inclusion.api.utils import soliguide from ... import factories @@ -1340,37 +1338,3 @@ def test_retrieve_service_and_notify_soliguide( assert response.status_code == status_code assert fake_soliguide_client.retrieved_ids == retrieved_ids - - -@pytest.mark.parametrize( - ("lien_source", "depuis", "status_code"), - [ - ("https://dora.incubateur.net/", "les-emplois", 307), - ("https://dora.incubateur.net/", None, 422), - (None, "les-emplois", 404), - ], -) -def test_redirect_service(api_client, lien_source, depuis, status_code, db_session): - service = factories.ServiceFactory(lien_source=lien_source) - - url = "/api/v0/services/" - params = {"mtm_campaign": "LesEmplois"} - if depuis is not None: - params["depuis"] = depuis - response = api_client.get( - url + f"{service.source}/{service.id}/redirige", - follow_redirects=False, - params=params, - ) - - assert response.status_code == status_code - - if status_code == 307: - assert response.headers["location"] == f"{lien_source}?mtm_campaign=LesEmplois" - - assert ( - db_session.scalar( - sqla.select(sqla.func.count()).select_from(models.Request) - ) - == 1 - )