Skip to content

Commit

Permalink
test(launcher-api): update orphan JobResults visibility tests, add …
Browse files Browse the repository at this point in the history
…a UT for `jobs` permissions
  • Loading branch information
mabw-rte committed Aug 28, 2024
1 parent 58bf28c commit 9e44b59
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions tests/integration/launcher_blueprint/test_launcher_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
2 changes: 1 addition & 1 deletion tests/launcher/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_service_get_jobs_from_database(self, db_session) -> None:
)
),
)
== returned_faked_execution_results
== []
)

with pytest.raises(UserHasNotPermissionError):
Expand Down

0 comments on commit 9e44b59

Please sign in to comment.