@@ -515,6 +515,37 @@ def test_invalid_profile(self, fixture_fastapi_client: TestClient):
515515
516516 assert response .status_code != 200
517517
518+ def test_disabled_endpoint (self , fixture_fastapi_client : TestClient ):
519+ with patch (
520+ "autosubmit_api.routers.v4.runners.read_config_file"
521+ ) as mock_read_config :
522+ mock_read_config .return_value = {
523+ "RUNNER_CONFIGURATION" : {
524+ "PROFILES" : {
525+ "MY_PROFILE" : {
526+ "RUNNER_TYPE" : "LOCAL" ,
527+ "MODULE_LOADER_TYPE" : "NO_MODULE" ,
528+ }
529+ },
530+ "ENDPOINTS" : {"SET_JOB_STATUS" : {"ENABLED" : False }},
531+ },
532+ }
533+
534+ response = fixture_fastapi_client .post (
535+ self .endpoint ,
536+ json = {
537+ "expid" : "test_expid" ,
538+ "profile_name" : "MY_PROFILE" ,
539+ "command_params" : {
540+ "final_status" : "COMPLETED" ,
541+ "job_names_list" : ["JOB1" , "JOB2" ],
542+ },
543+ },
544+ )
545+
546+ assert response .status_code == 403
547+ assert "disabled" in response .json ()["error_message" ]
548+
518549 def test_valid_ssh_request (self , fixture_fastapi_client : TestClient ):
519550 # Mock read_config_file to include SSH_AUTOSUBMIT_DEV profile
520551 # and get_runner to return a mock runner
@@ -567,6 +598,27 @@ def test_valid_ssh_request(self, fixture_fastapi_client: TestClient):
567598class TestRunnerRunExperiment :
568599 endpoint = "/v4/runners/command/run-experiment"
569600
601+ def test_disabled_endpoint (self , fixture_fastapi_client : TestClient ):
602+ with patch (
603+ "autosubmit_api.routers.v4.runners.read_config_file"
604+ ) as mock_read_config :
605+ mock_read_config .return_value = {
606+ "RUNNER_CONFIGURATION" : {
607+ "ENDPOINTS" : {"RUNNER_RUN" : {"ENABLED" : False }},
608+ },
609+ }
610+
611+ response = fixture_fastapi_client .post (
612+ self .endpoint ,
613+ json = {
614+ "expid" : "test_expid" ,
615+ "profile_name" : "ANY_PROFILE" ,
616+ },
617+ )
618+
619+ assert response .status_code == 403
620+ assert "disabled" in response .json ()["error_message" ]
621+
570622 def test_valid_ssh_request (self , fixture_fastapi_client : TestClient ):
571623 with (
572624 patch (
@@ -612,6 +664,24 @@ def test_valid_ssh_request(self, fixture_fastapi_client: TestClient):
612664class TestRunnerGetRunnerRunStatus :
613665 endpoint = "/v4/runners/command/get-runner-run-status"
614666
667+ def test_disabled_endpoint (self , fixture_fastapi_client : TestClient ):
668+ with patch (
669+ "autosubmit_api.routers.v4.runners.read_config_file"
670+ ) as mock_read_config :
671+ mock_read_config .return_value = {
672+ "RUNNER_CONFIGURATION" : {
673+ "ENDPOINTS" : {"RUNNER_RUN" : {"ENABLED" : False }},
674+ },
675+ }
676+
677+ response = fixture_fastapi_client .post (
678+ self .endpoint ,
679+ json = {"expid" : "test_expid" },
680+ )
681+
682+ assert response .status_code == 403
683+ assert "disabled" in response .json ()["error_message" ]
684+
615685 def test_valid_request (self , fixture_fastapi_client : TestClient ):
616686 with patch (
617687 "autosubmit_api.routers.v4.runners.create_runner_processes_repository"
@@ -669,6 +739,24 @@ def test_no_process_found(self, fixture_fastapi_client: TestClient):
669739class TestRunnerStopExperiment :
670740 endpoint = "/v4/runners/command/stop-experiment"
671741
742+ def test_disabled_endpoint (self , fixture_fastapi_client : TestClient ):
743+ with patch (
744+ "autosubmit_api.routers.v4.runners.read_config_file"
745+ ) as mock_read_config :
746+ mock_read_config .return_value = {
747+ "RUNNER_CONFIGURATION" : {
748+ "ENDPOINTS" : {"RUNNER_RUN" : {"ENABLED" : False }},
749+ },
750+ }
751+
752+ response = fixture_fastapi_client .post (
753+ self .endpoint ,
754+ json = {"expid" : "test_expid" },
755+ )
756+
757+ assert response .status_code == 403
758+ assert "disabled" in response .json ()["error_message" ]
759+
672760 def test_valid_ssh_request (self , fixture_fastapi_client : TestClient ):
673761 with patch (
674762 "autosubmit_api.routers.v4.runners.get_runner_from_expid"
@@ -703,6 +791,29 @@ def test_stop_failure(self, fixture_fastapi_client: TestClient):
703791class TestRunnerCreateExperiment :
704792 endpoint = "/v4/runners/command/create-experiment"
705793
794+ def test_disabled_endpoint (self , fixture_fastapi_client : TestClient ):
795+ with patch (
796+ "autosubmit_api.routers.v4.runners.read_config_file"
797+ ) as mock_read_config :
798+ mock_read_config .return_value = {
799+ "RUNNER_CONFIGURATION" : {
800+ "ENDPOINTS" : {"CREATE_EXPERIMENT" : {"ENABLED" : False }},
801+ },
802+ }
803+
804+ response = fixture_fastapi_client .post (
805+ self .endpoint ,
806+ json = {
807+ "profile_name" : "ANY_PROFILE" ,
808+ "command_params" : {
809+ "description" : "Test experiment" ,
810+ },
811+ },
812+ )
813+
814+ assert response .status_code == 403
815+ assert "disabled" in response .json ()["error_message" ]
816+
706817 def test_valid_local_request (self , fixture_fastapi_client : TestClient ):
707818 with (
708819 patch (
@@ -750,3 +861,94 @@ def test_no_description(self, fixture_fastapi_client: TestClient):
750861 )
751862
752863 assert response .status_code != 200
864+
865+
866+ class TestRunnerConfigurations :
867+ @pytest .mark .parametrize (
868+ "file_content, expected" ,
869+ [
870+ (
871+ {},
872+ {
873+ "SET_JOB_STATUS" : {"ENABLED" : True },
874+ "RUNNER_RUN" : {"ENABLED" : True },
875+ "CREATE_EXPERIMENT" : {"ENABLED" : True },
876+ },
877+ ),
878+ (
879+ {
880+ "RUNNER_CONFIGURATION" : {
881+ "ENDPOINTS" : {
882+ "SET_JOB_STATUS" : {"ENABLED" : False },
883+ "RUNNER_RUN" : {"ENABLED" : False },
884+ "CREATE_EXPERIMENT" : {"ENABLED" : False },
885+ }
886+ }
887+ },
888+ {
889+ "SET_JOB_STATUS" : {"ENABLED" : False },
890+ "RUNNER_RUN" : {"ENABLED" : False },
891+ "CREATE_EXPERIMENT" : {"ENABLED" : False },
892+ },
893+ ),
894+ (
895+ {
896+ "RUNNER_CONFIGURATION" : {
897+ "ENDPOINTS" : {
898+ "SET_JOB_STATUS" : {
899+ "ENABLED" : False ,
900+ "EXTRA_KEY" : "foo" ,
901+ },
902+ "CREATE_EXPERIMENT" : {"ENABLED" : True },
903+ }
904+ }
905+ },
906+ {
907+ "SET_JOB_STATUS" : {"ENABLED" : False , "EXTRA_KEY" : "foo" },
908+ "RUNNER_RUN" : {"ENABLED" : True },
909+ "CREATE_EXPERIMENT" : {"ENABLED" : True },
910+ },
911+ ),
912+ (
913+ {
914+ "RUNNER_CONFIGURATION" : {
915+ "ENDPOINTS" : {
916+ "SET_JOB_STATUS" : {
917+ "EXTRA_KEY" : "foo" ,
918+ },
919+ }
920+ }
921+ },
922+ {
923+ "SET_JOB_STATUS" : {"ENABLED" : True , "EXTRA_KEY" : "foo" },
924+ "RUNNER_RUN" : {"ENABLED" : True },
925+ "CREATE_EXPERIMENT" : {"ENABLED" : True },
926+ },
927+ ),
928+ ],
929+ )
930+ def test_endpoints_configuration (
931+ self , fixture_fastapi_client : TestClient , file_content : dict , expected : dict
932+ ):
933+ endpoint = "/v4/runners/configuration/endpoints"
934+
935+ with patch (
936+ "autosubmit_api.routers.v4.runners.read_config_file"
937+ ) as mock_read_config :
938+ mock_read_config .return_value = file_content
939+
940+ response = fixture_fastapi_client .get (
941+ endpoint ,
942+ )
943+
944+ resp_obj : dict = response .json ()
945+
946+ assert resp_obj == expected
947+
948+ # for endpoint_name in ["SET_JOB_STATUS", "RUNNER_RUN", "CREATE_EXPERIMENT"]:
949+ # assert endpoint_name in resp_obj
950+ # assert "ENABLED" in resp_obj[endpoint_name]
951+ # assert (
952+ # isinstance(resp_obj[endpoint_name]["ENABLED"], bool)
953+ # and resp_obj[endpoint_name]["ENABLED"] is True
954+ # )
0 commit comments