Skip to content

Commit 3e893d9

Browse files
committed
add test for checking incompatible patch error raised
1 parent 7893ba1 commit 3e893d9

File tree

5 files changed

+75
-8
lines changed

5 files changed

+75
-8
lines changed

packages/models-library/src/models_library/functions_errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,8 @@ class FunctionJobCollectionsExecuteApiAccessDeniedError(FunctionBaseError):
158158
"User {user_id} does not have the permission to execute function job collections"
159159
)
160160
status_code: int = 403 # Forbidden
161+
162+
163+
class FunctionJobPatchModelIncompatibleError(FunctionBaseError):
164+
msg_template = "Incompatible patch model for Function '{function_id}' in product '{product_name}'."
165+
status_code: int = 422

services/web/server/src/simcore_service_webserver/functions/_controller/_functions_rpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
FunctionJobCollectionsWriteApiAccessDeniedError,
3131
FunctionJobCollectionWriteAccessDeniedError,
3232
FunctionJobIDNotFoundError,
33+
FunctionJobPatchModelIncompatibleError,
3334
FunctionJobReadAccessDeniedError,
3435
FunctionJobsReadApiAccessDeniedError,
3536
FunctionJobsWriteApiAccessDeniedError,
@@ -93,6 +94,7 @@ async def register_function_job(
9394
reraise_if_error_type=(
9495
UnsupportedFunctionJobClassError,
9596
FunctionJobsWriteApiAccessDeniedError,
97+
FunctionJobPatchModelIncompatibleError,
9698
)
9799
)
98100
async def patch_registered_function_job(

services/web/server/src/simcore_service_webserver/functions/_functions_exceptions.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,3 @@ class FunctionGroupAccessRightsNotFoundError(WebServerBaseError, RuntimeError):
77
msg_template = user_message(
88
"Group access rights could not be found for Function '{function_id}' in product '{product_name}'."
99
)
10-
11-
12-
class IncompatiblePatchModelError(WebServerBaseError, ValueError):
13-
msg_template = user_message(
14-
"Incompatible patch model for Function '{function_id}' in product '{product_name}'."
15-
)

services/web/server/src/simcore_service_webserver/functions/_functions_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
RegisteredSolverFunctionJob,
3535
)
3636
from models_library.functions_errors import (
37+
FunctionJobPatchModelIncompatibleError,
3738
UnsupportedFunctionClassError,
3839
UnsupportedFunctionJobClassError,
3940
)
@@ -47,7 +48,6 @@
4748
from . import _functions_repository
4849
from ._functions_exceptions import (
4950
FunctionGroupAccessRightsNotFoundError,
50-
IncompatiblePatchModelError,
5151
)
5252

5353
router = RPCRouter()
@@ -114,7 +114,7 @@ async def patch_registered_function_job(
114114
function_job_id=function_job_uuid,
115115
)
116116
if job.function_class != registered_function_job_patch.function_class:
117-
raise IncompatiblePatchModelError(
117+
raise FunctionJobPatchModelIncompatibleError(
118118
function_id=job.function_uuid,
119119
product_name=product_name,
120120
)

services/web/server/tests/unit/with_dbs/04/functions/test_function_jobs_controller_rpc.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from models_library.functions_errors import (
2727
FunctionJobIDNotFoundError,
28+
FunctionJobPatchModelIncompatibleError,
2829
FunctionJobReadAccessDeniedError,
2930
FunctionJobsReadApiAccessDeniedError,
3031
FunctionJobWriteAccessDeniedError,
@@ -540,6 +541,71 @@ async def test_patch_registered_function_jobs(
540541
assert registered_job.solver_job_id == patch.solver_job_id
541542

542543

544+
@pytest.mark.parametrize(
545+
"user_role",
546+
[UserRole.USER],
547+
)
548+
@pytest.mark.parametrize(
549+
"function_job, patch",
550+
[
551+
(
552+
ProjectFunctionJob(
553+
function_uid=_faker.uuid4(),
554+
title="Test Function Job",
555+
description="A test function job",
556+
project_job_id=None,
557+
inputs=None,
558+
outputs=None,
559+
job_creation_task_id=None,
560+
),
561+
RegisteredSolverFunctionJobPatch(
562+
title=_faker.word(),
563+
description=_faker.sentence(),
564+
job_creation_task_id=TaskID(_faker.uuid4()),
565+
inputs={"input1": _faker.pyint(min_value=0, max_value=1000)},
566+
outputs={"output1": _faker.word()},
567+
solver_job_id=_faker.uuid4(),
568+
),
569+
),
570+
],
571+
)
572+
async def test_incompatible_patch_model_error(
573+
client: TestClient,
574+
rpc_client: RabbitMQRPCClient,
575+
add_user_function_api_access_rights: None,
576+
logged_user: UserInfoDict,
577+
other_logged_user: UserInfoDict,
578+
osparc_product_name: ProductName,
579+
mock_function_factory: Callable[[FunctionClass], Function],
580+
clean_functions: None,
581+
function_job: RegisteredFunctionJob,
582+
patch: RegisteredFunctionJobPatch,
583+
):
584+
function = mock_function_factory(function_job.function_class)
585+
586+
registered_function = await functions_rpc.register_function(
587+
rabbitmq_rpc_client=rpc_client,
588+
function=function,
589+
user_id=logged_user["id"],
590+
product_name=osparc_product_name,
591+
)
592+
function_job.function_uid = registered_function.uid
593+
registered_job = await functions_rpc.register_function_job(
594+
rabbitmq_rpc_client=rpc_client,
595+
function_job=function_job,
596+
user_id=logged_user["id"],
597+
product_name=osparc_product_name,
598+
)
599+
with pytest.raises(FunctionJobPatchModelIncompatibleError):
600+
registered_job = await functions_rpc.patch_registered_function_job(
601+
rabbitmq_rpc_client=rpc_client,
602+
user_id=logged_user["id"],
603+
function_job_uuid=registered_job.uid,
604+
product_name=osparc_product_name,
605+
registered_function_job_patch=patch,
606+
)
607+
608+
543609
@pytest.mark.parametrize(
544610
"user_role",
545611
[UserRole.USER],

0 commit comments

Comments
 (0)