diff --git a/tests/integration/launcher_blueprint/test_launcher_local.py b/tests/integration/launcher_blueprint/test_launcher_local.py index 08d1175889..aeff69e315 100644 --- a/tests/integration/launcher_blueprint/test_launcher_local.py +++ b/tests/integration/launcher_blueprint/test_launcher_local.py @@ -122,3 +122,44 @@ def test_get_launcher_time_limit( "description": "Unknown solver configuration: 'unknown'", "exception": "UnknownSolverConfig", } + + def test_jobs_permissions( + self, + client: TestClient, + user_access_token: str, + admin_access_token: str, + ) -> None: + # create an admin study with no permissions + res = client.post( + "/v1/studies", + headers={"Authorization": f"Bearer {admin_access_token}"}, + params={"name": "study_admin"}, + ) + res.raise_for_status() + # get the study_id + study_id = res.json() + + # launch a job with the admin user + res = client.post( + f"/v1/launcher/run/{study_id}", + headers={"Authorization": f"Bearer {admin_access_token}"}, + json={"launcher": "local"}, + ) + res.raise_for_status() + job_id = res.json()["job_id"] + + # check that the user cannot see the job + res = client.get( + "/v1/launcher/jobs", + headers={"Authorization": f"Bearer {user_access_token}"}, + ) + res.raise_for_status() + assert job_id not in [job.get("id") for job in res.json()] + + # check that the admin can see the job + res = client.get( + "/v1/launcher/jobs", + headers={"Authorization": f"Bearer {admin_access_token}"}, + ) + res.raise_for_status() + assert job_id in [job.get("id") for job in res.json()] diff --git a/tests/launcher/test_service.py b/tests/launcher/test_service.py index 9095673070..a9b5eb0b38 100644 --- a/tests/launcher/test_service.py +++ b/tests/launcher/test_service.py @@ -308,7 +308,7 @@ def test_service_get_jobs_from_database(self, db_session) -> None: ) ), ) - == returned_faked_execution_results + == [] ) with pytest.raises(UserHasNotPermissionError):