-
Notifications
You must be signed in to change notification settings - Fork 45
Add methods to CAS Management #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add methods to CAS Management #129
Conversation
Hey @SilvestriStefano, We do not use f-strings since we still support users back to Python 3.5 and f-strings were introduced in Python 3.6. I'm opening up the merge request to the git actions now, so those should begin to run momentarily. If this is a WIP, would it be better to merge your updates into a new branch? |
Hello, |
Hi, Originally, in the post request was written I have not added a test method for the |
Hey @SilvestriStefano, This looks great! I am in the process of reformatting the sasctl code base to fully follow PEP8 guidelines, so I made a number of comments in my review focused on those reformatting instances. The only logic change I suggested was with regards to adding a new function to handle the many key checks. Thank you for creating the integration tests and their associated cassettes. I also noticed that cas_management is not subject to any unit tests, so I will add that to my to do list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial review
@@ -8,6 +8,10 @@ | |||
|
|||
from .service import Service | |||
|
|||
|
|||
from typing import Union, TextIO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we shift this back up just below "import os" to minimize extra whitespace in the imports? And to clearly separate python built-in, external library, and sasctl-specific imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
""" | ||
Returns a collection of sessions available on the CAS server. | ||
|
||
Params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Format Matching] Please use "Parameters" to match sasctl docstring format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad. It should be fixed now.
@@ -22,7 +26,125 @@ class CASManagement(Service): | |||
list_servers, get_server, _, _ = Service._crud_funcs("/servers", "server") | |||
|
|||
@classmethod | |||
def list_caslibs(cls, server, filter_=None): | |||
def list_sessions(cls, qparams: dict = None, server: str = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to query_params: more verbose variable names help with cognitive complexity and underscore instead of camelcase follows PEP8 S117 rule for variable naming convention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
|
||
Params | ||
------ | ||
queryParams : dict, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query_params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
""" | ||
server = server or DEFAULT_SERVER | ||
|
||
if qparams is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query_params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if ("sourceTableName" not in qParam.keys() | ||
and "quiet" not in qParam.keys() | ||
and "removeAcs" not in qParam.keys()): | ||
raise Exception( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use ValueError here instead of a general exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in the second helper function check_required_key
"Missing required query parameters `sourceTableName`, `quiet`, `removeAcs`" | ||
) | ||
else: | ||
query = qParam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query_params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
else: | ||
raise ValueError( | ||
"The only acceptable query parameters are %s and must be passed in a dictionary" | ||
% (allowedQ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allowed_queries & unnecessary parentheses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
server : str, optional | ||
Server where the `caslib` is registered. | ||
Defaults to `cas-shared-default`. | ||
qparams: dict, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query_params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
from typing import Union, TextIO | ||
|
||
|
||
DEFAULT_SERVER = "cas-shared-default" | ||
DEFAULT_CASLIB = "casuser" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a classless function up here to handle the many key checks? Something like:
check_valid_keys(valid_keys, input_keys, parameter_name):
if not all(key in valid_keys for key in input_keys):
raise ValueError("The only acceptable values for %s are %s" % (parameter_name, valid_keys))
i.e. change
elif (
format_ == 'csv' and
not all(key in allowed_body_csv for key in input_keys)
):
raise ValueError(
"The parameters specific to a csv file are %s." % allowed_body_csv
)
to
elif format_ == "csv":
check_valid_keys(allowed_body_csv, input_keys, "csv parameters")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As requested, I have added two functions that handles the many checks: one for checking that the keys entered are valid, and one that checks that required keys are being passed as inputs.
Hello @smlindauer, Thank you for reviewing. |
I want to mention that I changed the |
Should we go with Samples or would Public make more sense? I believe Public and Samples are always created, but Public is more likely to contain CAS data that users would be using. |
@smlindauer you are right. The "Public" caslib makes more sense as the default one. I made the change. |
Hello,
I noticed that some methods are missing from the CAS Management service. I am thinking of adding the following for starters
with related tests as well:
Any suggestion/feedback is highly appreciated.
Question/curiosity: is there a reason why f-strings are not used?
Signed-off-by: Stefano Silvestri ssilvestri@olab-studio.com