|
3 | 3 |
|
4 | 4 | import datetime |
5 | 5 | from collections.abc import Callable |
| 6 | +from pathlib import Path |
6 | 7 | from typing import Any |
7 | 8 | from uuid import uuid4 |
8 | 9 |
|
|
17 | 18 | RegisteredProjectFunction, |
18 | 19 | RegisteredProjectFunctionJob, |
19 | 20 | ) |
20 | | -from models_library.functions import FunctionUserAccessRights |
| 21 | +from models_library.functions import FunctionUserAccessRights, RegisteredFunctionJob |
21 | 22 | from models_library.functions_errors import ( |
22 | 23 | FunctionIDNotFoundError, |
23 | 24 | FunctionReadAccessDeniedError, |
@@ -615,3 +616,47 @@ async def test_run_function_not_allowed( |
615 | 616 | assert response.json()["errors"][0] == ( |
616 | 617 | f"Function {mock_registered_function.uid} execute access denied for user {user_id}" |
617 | 618 | ) |
| 619 | + |
| 620 | + |
| 621 | +async def test_run_function_parent_info( |
| 622 | + client: AsyncClient, |
| 623 | + mock_handler_in_functions_rpc_interface: Callable[[str, Any], None], |
| 624 | + mock_registered_function: RegisteredProjectFunction, |
| 625 | + mock_registered_function_job: RegisteredFunctionJob, |
| 626 | + auth: httpx.BasicAuth, |
| 627 | + user_id: UserID, |
| 628 | + mocked_webserver_rest_api_base: respx.MockRouter, |
| 629 | + mocked_directorv2_rest_api_base: respx.MockRouter, |
| 630 | + mocked_webserver_rpc_api: dict[str, MockType], |
| 631 | + create_respx_mock_from_capture, |
| 632 | + project_tests_dir: Path, |
| 633 | +) -> None: |
| 634 | + |
| 635 | + capture = "run_function_parent_info.json" |
| 636 | + create_respx_mock_from_capture( |
| 637 | + respx_mocks=[mocked_webserver_rest_api_base, mocked_directorv2_rest_api_base], |
| 638 | + capture_path=project_tests_dir / "mocks" / capture, |
| 639 | + side_effects_callbacks=[], |
| 640 | + ) |
| 641 | + |
| 642 | + mock_handler_in_functions_rpc_interface( |
| 643 | + "get_function_user_permissions", |
| 644 | + FunctionUserAccessRights( |
| 645 | + user_id=user_id, |
| 646 | + execute=True, |
| 647 | + read=True, |
| 648 | + write=True, |
| 649 | + ), |
| 650 | + ) |
| 651 | + mock_handler_in_functions_rpc_interface("get_function", mock_registered_function) |
| 652 | + mock_handler_in_functions_rpc_interface("find_cached_function_jobs", []) |
| 653 | + mock_handler_in_functions_rpc_interface( |
| 654 | + "register_function_job", mock_registered_function_job |
| 655 | + ) |
| 656 | + |
| 657 | + response = await client.post( |
| 658 | + f"{API_VTAG}/functions/{mock_registered_function.uid}:run", |
| 659 | + json={}, |
| 660 | + auth=auth, |
| 661 | + ) |
| 662 | + assert response.status_code == status.HTTP_200_OK |
0 commit comments