| 
8 | 8 | 
 
  | 
9 | 9 | import httpx  | 
10 | 10 | import pytest  | 
 | 11 | +import simcore_service_api_server.api.routes.function_jobs_routes as function_jobs_routes  | 
 | 12 | +from celery_library.task_manager import CeleryTaskManager  | 
 | 13 | +from faker import Faker  | 
 | 14 | +from fastapi import FastAPI  | 
11 | 15 | from httpx import AsyncClient  | 
12 | 16 | from models_library.api_schemas_webserver.functions import (  | 
13 | 17 |     ProjectFunctionJob,  | 
14 | 18 |     RegisteredProjectFunctionJob,  | 
15 | 19 | )  | 
16 |  | -from models_library.functions import FunctionJobStatus, RegisteredProjectFunction  | 
 | 20 | +from models_library.functions import (  | 
 | 21 | +    FunctionJobStatus,  | 
 | 22 | +    RegisteredProjectFunction,  | 
 | 23 | +)  | 
17 | 24 | from models_library.products import ProductName  | 
 | 25 | +from models_library.progress_bar import ProgressReport, ProgressStructuredMessage  | 
 | 26 | +from models_library.projects import ProjectID  | 
18 | 27 | from models_library.projects_state import RunningState  | 
19 | 28 | from models_library.rest_pagination import PageMetaInfoLimitOffset  | 
20 | 29 | from models_library.users import UserID  | 
21 | 30 | from pytest_mock import MockerFixture, MockType  | 
22 | 31 | from servicelib.aiohttp import status  | 
 | 32 | +from servicelib.celery.models import TaskFilter, TaskState, TaskStatus, TaskUUID  | 
23 | 33 | from simcore_service_api_server._meta import API_VTAG  | 
24 | 34 | from simcore_service_api_server.models.schemas.jobs import JobStatus  | 
25 | 35 | 
 
  | 
 | 36 | +_faker = Faker()  | 
 | 37 | + | 
26 | 38 | 
 
  | 
27 | 39 | async def test_delete_function_job(  | 
28 | 40 |     client: AsyncClient,  | 
@@ -179,19 +191,59 @@ def mocked_list_function_jobs(offset: int, limit: int):  | 
179 | 191 | 
 
  | 
180 | 192 | 
 
  | 
181 | 193 | @pytest.mark.parametrize("job_status", ["SUCCESS", "FAILED", "STARTED"])  | 
 | 194 | +@pytest.mark.parametrize("project_job_id", [None, ProjectID(_faker.uuid4())])  | 
 | 195 | +@pytest.mark.parametrize("job_creation_task_id", [None, TaskUUID(_faker.uuid4())])  | 
182 | 196 | async def test_get_function_job_status(  | 
 | 197 | +    app: FastAPI,  | 
183 | 198 |     mocked_app_dependencies: None,  | 
184 | 199 |     client: AsyncClient,  | 
 | 200 | +    mocker: MockerFixture,  | 
185 | 201 |     mock_handler_in_functions_rpc_interface: Callable[[str, Any], None],  | 
186 | 202 |     mock_registered_project_function_job: RegisteredProjectFunctionJob,  | 
187 | 203 |     mock_registered_project_function: RegisteredProjectFunction,  | 
188 | 204 |     mock_method_in_jobs_service: Callable[[str, Any], None],  | 
189 | 205 |     auth: httpx.BasicAuth,  | 
190 | 206 |     job_status: str,  | 
 | 207 | +    project_job_id: ProjectID,  | 
 | 208 | +    job_creation_task_id: TaskUUID | None,  | 
191 | 209 | ) -> None:  | 
192 | 210 | 
 
  | 
 | 211 | +    def _mock_task_manager(*args, **kwargs) -> CeleryTaskManager:  | 
 | 212 | +        async def _get_task_status(  | 
 | 213 | +            task_uuid: TaskUUID, task_filter: TaskFilter  | 
 | 214 | +        ) -> TaskStatus:  | 
 | 215 | +            assert task_uuid == job_creation_task_id  | 
 | 216 | +            return TaskStatus(  | 
 | 217 | +                task_uuid=task_uuid,  | 
 | 218 | +                task_state=TaskState.STARTED,  | 
 | 219 | +                progress_report=ProgressReport(  | 
 | 220 | +                    actual_value=0.5,  | 
 | 221 | +                    total=1.0,  | 
 | 222 | +                    attempt=1,  | 
 | 223 | +                    unit=None,  | 
 | 224 | +                    message=ProgressStructuredMessage.model_validate(  | 
 | 225 | +                        ProgressStructuredMessage.model_config["json_schema_extra"][  | 
 | 226 | +                            "examples"  | 
 | 227 | +                        ][0]  | 
 | 228 | +                    ),  | 
 | 229 | +                ),  | 
 | 230 | +            )  | 
 | 231 | + | 
 | 232 | +        obj = mocker.Mock(spec=CeleryTaskManager)  | 
 | 233 | +        obj.get_task_status = _get_task_status  | 
 | 234 | +        return obj  | 
 | 235 | + | 
 | 236 | +    mocker.patch.object(function_jobs_routes, "get_task_manager", _mock_task_manager)  | 
 | 237 | + | 
193 | 238 |     mock_handler_in_functions_rpc_interface(  | 
194 |  | -        "get_function_job", mock_registered_project_function_job  | 
 | 239 | +        "get_function_job",  | 
 | 240 | +        mock_registered_project_function_job.model_copy(  | 
 | 241 | +            update={  | 
 | 242 | +                "user_id": ANY,  | 
 | 243 | +                "project_job_id": project_job_id,  | 
 | 244 | +                "job_creation_task_id": job_creation_task_id,  | 
 | 245 | +            }  | 
 | 246 | +        ),  | 
195 | 247 |     )  | 
196 | 248 |     mock_handler_in_functions_rpc_interface(  | 
197 | 249 |         "get_function", mock_registered_project_function  | 
 | 
0 commit comments