|
| 1 | +from collections.abc import Callable |
| 2 | + |
| 3 | +import pytest |
| 4 | +from celery import Celery, Task |
1 | 5 | from celery.contrib.testing.worker import TestWorkController |
| 6 | +from celery_library.task import register_task |
| 7 | +from faker import Faker |
| 8 | +from models_library.functions import ( |
| 9 | + FunctionClass, |
| 10 | + FunctionID, |
| 11 | + FunctionInputs, |
| 12 | + FunctionJobID, |
| 13 | + RegisteredFunction, |
| 14 | + RegisteredProjectFunctionJob, |
| 15 | +) |
| 16 | +from models_library.projects import ProjectID |
| 17 | +from servicelib.celery.models import TaskID |
| 18 | +from simcore_service_api_server.api.dependencies.authentication import Identity |
| 19 | +from simcore_service_api_server.celery._worker_tasks._functions_tasks import ( |
| 20 | + run_function as run_function_task, |
| 21 | +) |
| 22 | +from simcore_service_api_server.models.api_resources import JobLinks |
| 23 | +from simcore_service_api_server.models.schemas.jobs import ( |
| 24 | + JobPricingSpecification, |
| 25 | + NodeID, |
| 26 | +) |
| 27 | + |
| 28 | +_faker = Faker() |
| 29 | + |
| 30 | + |
| 31 | +def _register_fake_run_function_task() -> Callable[[Celery], None]: |
| 32 | + |
| 33 | + async def run_function( |
| 34 | + task: Task, |
| 35 | + task_id: TaskID, |
| 36 | + *, |
| 37 | + user_identity: Identity, |
| 38 | + function: RegisteredFunction, |
| 39 | + function_inputs: FunctionInputs, |
| 40 | + pricing_spec: JobPricingSpecification | None, |
| 41 | + job_links: JobLinks, |
| 42 | + x_simcore_parent_project_uuid: NodeID | None, |
| 43 | + x_simcore_parent_node_id: NodeID | None, |
| 44 | + ): |
| 45 | + return RegisteredProjectFunctionJob( |
| 46 | + title=_faker.sentence(), |
| 47 | + description=_faker.paragraph(), |
| 48 | + function_uid=FunctionID(_faker.uuid4()), |
| 49 | + inputs=function_inputs, |
| 50 | + outputs=None, |
| 51 | + function_class=FunctionClass.PROJECT, |
| 52 | + uid=FunctionJobID(_faker.uuid4()), |
| 53 | + created_at=_faker.date_time(), |
| 54 | + project_job_id=ProjectID(_faker.uuid4()), |
| 55 | + ) |
| 56 | + |
| 57 | + assert run_function_task.__name__ == run_function.__name__ |
| 58 | + |
| 59 | + def _(celery_app: Celery) -> None: |
| 60 | + register_task(celery_app, run_function) |
| 61 | + |
| 62 | + return _ |
2 | 63 |
|
3 | 64 |
|
| 65 | +@pytest.mark.parametrize("register_celery_tasks", [_register_fake_run_function_task]) |
| 66 | +@pytest.mark.parametrize("add_worker_tasks", [False]) |
4 | 67 | async def test_with_fake_run_function(with_storage_celery_worker: TestWorkController): |
5 | 68 | pass |
0 commit comments