Skip to content

Commit

Permalink
Make mila_email_username mandatory in Python functions get/set/dele…
Browse files Browse the repository at this point in the history
…te_user_props

Remove core tests for these functions, as they must be called in a context with a valid logged user
  • Loading branch information
notoraptor committed Apr 9, 2024
1 parent cf4e345 commit 71fca56
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 370 deletions.
32 changes: 12 additions & 20 deletions clockwork_web/core/job_user_props_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask_login import current_user
"""Internal functions to manage job-user props."""
from ..db import get_db
import json

Expand All @@ -8,17 +8,14 @@
MAX_PROPS_LENGTH = 2 * 1024 * 1024


def get_user_props(
job_id: str, cluster_name: str, mila_email_username: str = None
) -> dict:
def get_user_props(job_id: str, cluster_name: str, mila_email_username: str) -> dict:
"""
Get job-user props.
Parameters:
job_id ID of job for which we want to get user props.
cluster_name Name of cluster to which the job belongs.
mila_email_username Optional email of user who sets the props we want to get.
Default is current logged user.
mila_email_username Email of user who sets the props we want to get.
Returns:
Dictionary of user-props, empty if no props were found.
Expand All @@ -31,7 +28,7 @@ def get_user_props(


def set_user_props(
job_id: str, cluster_name: str, updates: dict, mila_email_username: str = None
job_id: str, cluster_name: str, updates: dict, mila_email_username: str
) -> dict:
"""
Update job-user-props.
Expand All @@ -41,8 +38,7 @@ def set_user_props(
cluster_name Name of cluster to which the job belongs.
updates Dictionary of props to add.
Each key-value represents a prop.
mila_email_username Optional email of user who wants to update his props.
Default is current logged user.
mila_email_username Email of user who wants to update his props.
Returns:
Dictionary of Updated job-user props.
Expand Down Expand Up @@ -70,15 +66,15 @@ def set_user_props(
{
"job_id": job_id,
"cluster_name": str(cluster_name),
"mila_email_username": current_user.mila_email_username,
"mila_email_username": mila_email_username,
"props": new_props,
}
)

return new_props


def delete_user_props(job_id, cluster_name, key_or_keys, mila_email_username=None):
def delete_user_props(job_id, cluster_name, key_or_keys, mila_email_username: str):
"""
Delete some job-user props.
Expand All @@ -87,10 +83,9 @@ def delete_user_props(job_id, cluster_name, key_or_keys, mila_email_username=Non
cluster_name Name of cluster to which the job belongs.
key_or_keys Either a key or a sequence of keys,
representing prop names to delete.
mila_email_username Optional email of user who wants to delete props.
Default is current logged user.
mila_email_username Email of user who wants to delete props.
"""
# Parsekey_or_keys to get keys to delete.
# Parse key_or_keys to get keys to delete.
if isinstance(key_or_keys, str):
keys = [key_or_keys]
else:
Expand All @@ -112,16 +107,15 @@ def delete_user_props(job_id, cluster_name, key_or_keys, mila_email_username=Non


def _get_user_props_document(
job_id: str, cluster_name: str, mila_email_username: str = None
job_id: str, cluster_name: str, mila_email_username: str
) -> dict:
"""
Get MongoDB document representing job-user props corresponding to given parameters.
Parameters:
job_id ID of job for which we want to get user props.
cluster_name Name of cluster to which the job belongs.
mila_email_username Optional email of user who sets the props we want to get.
Default is current logged user.
mila_email_username Email of user who sets the props we want to get.
Returns:
MongoDB document representing job-user props.
Expand All @@ -139,9 +133,7 @@ def _get_user_props_document(
{
"job_id": job_id,
"cluster_name": str(cluster_name),
"mila_email_username": (
mila_email_username or current_user.mila_email_username
),
"mila_email_username": mila_email_username,
}
)
)
Expand Down
Loading

0 comments on commit 71fca56

Please sign in to comment.