Skip to content

Commit 1d4df87

Browse files
committed
further improvements to test
1 parent 5a6d47e commit 1d4df87

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

services/api-server/tests/unit/celery/test_functions.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@
66
from celery.contrib.testing.worker import TestWorkController
77
from celery_library.task import register_task
88
from faker import Faker
9+
from fastapi import FastAPI
10+
from httpx import AsyncClient, BasicAuth
911
from models_library.functions import (
1012
FunctionClass,
1113
FunctionID,
1214
FunctionInputs,
1315
FunctionJobID,
1416
RegisteredFunction,
17+
RegisteredProjectFunction,
1518
RegisteredProjectFunctionJob,
1619
)
1720
from models_library.projects import ProjectID
1821
from servicelib.celery.models import TaskID
22+
from servicelib.common_headers import (
23+
X_SIMCORE_PARENT_NODE_ID,
24+
X_SIMCORE_PARENT_PROJECT_UUID,
25+
)
26+
from simcore_service_api_server._meta import API_VTAG
1927
from simcore_service_api_server.api.dependencies.authentication import Identity
28+
from simcore_service_api_server.api.routes.functions_routes import get_function
2029
from simcore_service_api_server.celery._worker_tasks._functions_tasks import (
2130
run_function as run_function_task,
2231
)
@@ -72,5 +81,28 @@ def _(celery_app: Celery) -> None:
7281

7382
@pytest.mark.parametrize("register_celery_tasks", [_register_fake_run_function_task()])
7483
@pytest.mark.parametrize("add_worker_tasks", [False])
75-
async def test_with_fake_run_function(with_storage_celery_worker: TestWorkController):
76-
pass
84+
async def test_with_fake_run_function(
85+
app: FastAPI,
86+
client: AsyncClient,
87+
auth: BasicAuth,
88+
with_storage_celery_worker: TestWorkController,
89+
):
90+
91+
extra = RegisteredProjectFunction.model_config.get("json_schema_extra")
92+
assert extra
93+
app.dependency_overrides[get_function] = (
94+
lambda: RegisteredProjectFunction.model_validate(extra["examples"][0])
95+
)
96+
97+
headers = {}
98+
headers[X_SIMCORE_PARENT_PROJECT_UUID] = "null"
99+
headers[X_SIMCORE_PARENT_NODE_ID] = "null"
100+
101+
response = await client.post(
102+
f"/{API_VTAG}/functions/{_faker.uuid4()}:run",
103+
auth=auth,
104+
json={},
105+
headers=headers,
106+
)
107+
108+
assert response.status_code == 200

0 commit comments

Comments
 (0)