Commit 3461ce4f authored by George Papathanail's avatar George Papathanail
Browse files

fix: align session request/response schemas with CAMARA spec

parent a1f88b03
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -124,6 +124,15 @@ class SRMClient:
        )
        return [SRMZone.model_validate(z) for z in data]

    async def create_qod_session(
        self,
        payload: dict[str, Any],
        x_correlator: str | None = None,
    ) -> SessionInfo:
        headers = {"x-correlator": x_correlator} if x_correlator else None
        data = await self._request("POST", "/sessions", json=payload, headers=headers)
        return SessionInfo.model_validate(data)

    async def get_qod_session(
        self,
        session_id: str,
@@ -133,6 +142,14 @@ class SRMClient:
        data = await self._request("GET", f"/sessions/{session_id}", headers=headers)
        return SessionInfo.model_validate(data)

    async def delete_qod_session(
        self,
        session_id: str,
        x_correlator: str | None = None,
    ) -> None:
        headers = {"x-correlator": x_correlator} if x_correlator else None
        await self._request("DELETE", f"/sessions/{session_id}", headers=headers)

    async def get_apps(self, x_correlator: str | None = None) -> list[SRMCatalogPayload]:
        headers = {"x-correlator": x_correlator} if x_correlator else None
        data = await self._request(
+6 −0
Original line number Diff line number Diff line
@@ -38,4 +38,10 @@ class SRMClientPort(Protocol):
        x_correlator: str | None,
    ) -> list[SRMServiceInstance]: ...

    async def create_qod_session(
        self, payload: dict[str, Any], x_correlator: str | None
    ) -> SessionInfo: ...

    async def get_qod_session(self, session_id: str, x_correlator: str | None) -> SessionInfo: ...

    async def delete_qod_session(self, session_id: str, x_correlator: str | None) -> None: ...
+26 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ from open_exposure_gateway.adapters.errors import (
    DuplicateOperationError,
)
from open_exposure_gateway.api.camara.quality_on_demand.v0_10_1.schemas import (
    QosStatus,
    SessionInfo,
)
from open_exposure_gateway.application.services.edge_application_management_service import (
@@ -152,6 +153,26 @@ class FakeSRMClient:
            result = [i for i in result if i.service_instance_id == str(app_instance_id)]
        return result

    async def create_qod_session(
        self, payload: dict[str, Any], x_correlator: str | None = None
    ) -> SessionInfo:
        duration = payload.get("duration", 86400)
        session = SessionInfo(
            sessionId=uuid4(),
            device=payload["device"],
            applicationServer=payload["applicationServer"],
            qosProfile=payload["qosProfile"],
            duration=duration,
            startedAt=1_750_000_000,
            expiresAt=1_750_000_000 + duration,
            qosStatus=QosStatus.REQUESTED,
            devicePorts=payload.get("devicePorts"),
            applicationServerPorts=payload.get("applicationServerPorts"),
            webhook=payload.get("webhook"),
        )
        self.qod_sessions[str(session.sessionId)] = session
        return session

    async def get_qod_session(
        self, session_id: str, x_correlator: str | None = None
    ) -> SessionInfo:
@@ -160,6 +181,11 @@ class FakeSRMClient:
            raise NotFoundException(message=f"Session {session_id} not found")
        return session

    async def delete_qod_session(self, session_id: str, x_correlator: str | None = None) -> None:
        if session_id not in self.qod_sessions:
            raise NotFoundException(message=f"Session {session_id} not found")
        del self.qod_sessions[session_id]


def completion_payload(operation_id: str, **overrides: Any) -> dict[str, Any]:
    payload: dict[str, Any] = {