def test_crud_function_doc(): from sasctl.core import _build_crud_funcs for func in _build_crud_funcs('/widgets'): t0 = func.__doc__ assert ' widgets ' in func.__doc__ assert '{item}' not in func.__doc__
def test_get_item_by_dict(): from sasctl.core import _build_crud_funcs _, get_item, _, _ = _build_crud_funcs('/widget') # No REST call needed if complete dictionary is passed target = {'name': 'Test Widget', 'id': 12345} with mock.patch('sasctl.core.request') as request: resp = get_item(target) assert target == resp assert request.call_count == 0
def test_list_items(): from sasctl.core import _build_crud_funcs, RestObj list_items, _, _, _ = _build_crud_funcs('/items') with mock.patch('sasctl.core.request') as request: request.return_value = RestObj() resp = list_items() assert request.call_count == 1 assert [RestObj()] == resp
def test_get_item_by_name(): from sasctl.core import _build_crud_funcs _, get_item, _, _ = _build_crud_funcs('/widget') target = {'name': 'Test Widget', 'id': 12345} with mock.patch('sasctl.core.request') as request: with mock.patch('sasctl.core.is_uuid') as is_uuid: is_uuid.return_value = False request.return_value = target resp = get_item(target['name']) assert target == resp
def test_update_item(): from sasctl.core import _build_crud_funcs, RestObj _, _, update_item, _ = _build_crud_funcs('/widget') target = RestObj({'name': 'Test Widget', 'id': 12345}) with mock.patch('sasctl.core.request') as request: request.return_value = target # ETag should be required with pytest.raises(ValueError): resp = update_item(target) target._headers = {'etag': 'abcd'} resp = update_item(target) assert request.call_count == 1 assert ('put', '/widget/12345') == request.call_args[0] assert target == resp
#!/usr/bin/env python # encoding: utf-8 # # Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 from sasctl.core import post, _build_crud_funcs from sasctl.utils.cli import sasctl_command _SERVICE_ROOT = '/folders' list_folders, get_folder, update_folder, delete_folder = _build_crud_funcs( _SERVICE_ROOT + '/folders', 'folder') @sasctl_command('folders', 'create') def create_folder(name, parent=None, description=None): """ Parameters ---------- name : str The name of the new folder parent : str or dict, optional The parent folder for this folder, if any. Can be a folder name, id, or dict response from get_folder description : str, optional A description of the folder Returns -------
associated with the file or the actual content can be updated. A single file can be deleted by using a specific ID. Multiple files can be deleted by specifying a parentUri. A file can be uploaded via raw request or multipart form request. """ import os import six from sasctl.core import get_link, request_link, post, _build_crud_funcs from sasctl.services.folders import get_folder from sasctl.utils.cli import sasctl_command _SERVICE_ROOT = '/files' list_files, get_file, update_file, delete_file = _build_crud_funcs( _SERVICE_ROOT + '/files', 'file') @sasctl_command('files', 'create') def create_file(file, folder=None, filename=None, expiration=None): """Create a new file on the server by uploading a local file. Parameters ---------- file : str or file_like Path to the file to upload or a file-like object. folder : str or dict, optional Name, or, or folder information as returned by :func:`.get_folder`. filename : str, optional Name to assign to the uploaded file. Defaults to the filename if `file` is a path, otherwise required. expiration : datetime, optional
# # Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 from sasctl.core import is_uuid, get, post, get_link, _build_crud_funcs, current_session ROOT_PATH = '/modelRepository' FUNCTIONS = { 'Analytical', 'Classification', 'Clustering', 'Forecasting', 'Prediction', 'Text categorization', 'Text extraction', 'Text sentiment', 'Text topics', 'Sentiment' } # TODO: automatic query string encoding list_repositories, get_repository, update_repository, delete_repository = _build_crud_funcs( ROOT_PATH + '/repositories', 'repository') list_projects, get_project, update_project, delete_project = _build_crud_funcs( ROOT_PATH + '/projects', 'project') list_models, get_model, update_model, delete_model = _build_crud_funcs( ROOT_PATH + '/models', 'model') def get_model_link(model, rel, refresh=False): """Retrieve a link from a model's set of links. Parameters ---------- model : str or dict The name or id of the model, or a dictionary representation of the model. rel, str The name of the link to retrieve
#!/usr/bin/env python # encoding: utf-8 # # Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 from sasctl.core import _build_crud_funcs, post ROOT_PATH = '/projects' list_projects, get_project, update_project, delete_project = _build_crud_funcs(ROOT_PATH + '/projects', 'project') def create_project(name, description=None, image=None): """ Parameters ---------- name : str description : str image : str URI of an image to use as the project avatar Returns ------- RestObj """ body = {'name': name, 'description': description,
#!/usr/bin/env python # encoding: utf-8 # # Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 from sasctl.core import post, _build_crud_funcs from sasctl.services.model_publish import _publish_name SERVICE_ROOT = '/modelManagement' list_performance_definitions, get_performance_definition, \ update_performance_definition, delete_performance_definition = \ _build_crud_funcs(SERVICE_ROOT + '/performanceTasks', 'performance task', 'performance tasks') # TODO: set ds2MultiType def publish_model(model, destination, name=None, force=False): from .model_repository import get_model, get_model_link model_obj = get_model(model) if model_obj is None: model_name = model.name if hasattr(model, 'name') else str(model) raise ValueError("Model '{}' was not found.".format(model_name)) model_uri = get_model_link(model_obj, 'self') # TODO: Verify allowed formats by destination type. # As of 19w04 MAS throws HTTP 500 if name is in invalid format.