Commit 98fffbea authored by George Papathanail's avatar George Papathanail
Browse files

feat: add AppInstanceRepository list_by_app_deployment_id

parent f66aaeb0
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,11 @@ class SqlAppInstanceRepository(AppInstanceRepository):
        rows = await self._session.scalars(stmt)
        return [AppInstanceMapper.to_domain(row) for row in rows]

    async def list_by_app_deployment_id(self, app_deployment_id: UUID) -> list[AppInstance]:
        stmt = select(AppInstanceRow).where(AppInstanceRow.app_deployment_id == app_deployment_id)
        rows = await self._session.scalars(stmt)
        return [AppInstanceMapper.to_domain(row) for row in rows]

    async def exists_for_app_registration(self, app_registration_id: UUID) -> bool:
        stmt = select(AppInstanceRow.app_instance_id).where(
            AppInstanceRow.app_registration_id == app_registration_id,
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@ class AppInstanceRepository(ABC):
    async def list_by_operation_id(self, operation_id: UUID) -> list[AppInstance]:
        pass

    @abstractmethod
    async def list_by_app_deployment_id(self, app_deployment_id: UUID) -> list[AppInstance]:
        pass

    @abstractmethod
    async def exists_for_app_registration(self, app_registration_id: UUID) -> bool:
        pass
+7 −0
Original line number Diff line number Diff line
@@ -469,6 +469,13 @@ class FakeAppInstanceRepository(AppInstanceRepository):
            if row.operation_id == operation_id
        ]

    async def list_by_app_deployment_id(self, app_deployment_id: UUID) -> list[AppInstance]:
        return [
            row.model_copy(deep=True)
            for row in self.rows.values()
            if row.app_deployment_id == app_deployment_id
        ]

    async def exists_for_app_registration(self, app_registration_id: UUID) -> bool:
        terminal_states = (AppInstanceState.FAILED, AppInstanceState.TERMINATED)
        return any(
+22 −0
Original line number Diff line number Diff line
@@ -52,6 +52,28 @@ async def test_get_by_id_returns_none_when_missing() -> None:
    assert await repo.get_by_id(uuid4()) is None


async def test_list_by_app_deployment_id_returns_mapped_app_instances() -> None:
    row = _row()
    row.app_deployment_id = uuid4()
    session = AsyncMock(spec=AsyncSession)
    session.scalars.return_value = [row]
    repo = SqlAppInstanceRepository(session)

    result = await repo.list_by_app_deployment_id(row.app_deployment_id)

    assert len(result) == 1
    assert result[0].app_instance_id == row.app_instance_id
    session.scalars.assert_awaited_once()


async def test_list_by_app_deployment_id_returns_empty_when_none_match() -> None:
    session = AsyncMock(spec=AsyncSession)
    session.scalars.return_value = []
    repo = SqlAppInstanceRepository(session)

    assert await repo.list_by_app_deployment_id(uuid4()) == []


async def test_save_flushes_and_reloads_app_instance() -> None:
    domain = _domain()
    expected = _domain()