def test_bool_with_key_not_found(self, def_val, expected, strict): fake_dict = {'fake_key1': 'value1'} invalid_default = utils.get_bool_from_api_params('fake_key2', fake_dict, def_val, strict) self.assertEqual(expected, invalid_default)
def check_add_security_service(self, req, id, body): """Check the feasibility of associate a new security service.""" context = req.environ['manila.context'] share_network = db_api.share_network_get(context, id) policy.check_policy(context, RESOURCE_NAME, 'add_security_service_check', target_obj=share_network) data = body['add_security_service_check'] try: security_service = db_api.security_service_get( context, data['security_service_id']) except KeyError: msg = "Malformed request body." raise exc.HTTPBadRequest(explanation=msg) except exception.NotFound: msg = ("Security service %s doesn't exist." ) % data['security_service_id'] raise exc.HTTPBadRequest(explanation=msg) reset_check = utils.get_bool_from_api_params('reset_operation', data) try: result = ( self.share_api.check_share_network_security_service_update( context, share_network, security_service, reset_operation=reset_check)) except exception.ServiceIsDown as e: raise exc.HTTPConflict(explanation=e.msg) except exception.InvalidShareNetwork as e: raise exc.HTTPBadRequest(explanation=e.msg) except exception.InvalidSecurityService as e: raise exc.HTTPConflict(explanation=e.msg) return self._view_builder.build_security_service_update_check( req, data, result)
def test_bool_with_key_not_found(self, def_val, expected, strict): fake_dict = {'fake_key1': 'value1'} invalid_default = utils.get_bool_from_api_params('fake_key2', fake_dict, def_val, strict) self.assertEqual(expected, invalid_default)
def _get_shares(self, req, is_detail): """Returns a list of shares, transformed through view builder.""" context = req.environ['manila.context'] common._validate_pagination_query(req) search_opts = {} search_opts.update(req.GET) # Remove keys that are not related to share attrs sort_key = search_opts.pop('sort_key', 'created_at') sort_dir = search_opts.pop('sort_dir', 'desc') show_count = False if 'with_count' in search_opts: show_count = utils.get_bool_from_api_params( 'with_count', search_opts) search_opts.pop('with_count') # Deserialize dicts if 'metadata' in search_opts: search_opts['metadata'] = ast.literal_eval(search_opts['metadata']) if 'extra_specs' in search_opts: search_opts['extra_specs'] = ast.literal_eval( search_opts['extra_specs']) # NOTE(vponomaryov): Manila stores in DB key 'display_name', but # allows to use both keys 'name' and 'display_name'. It is leftover # from Cinder v1 and v2 APIs. if 'name' in search_opts: search_opts['display_name'] = search_opts.pop('name') if 'description' in search_opts: search_opts['display_description'] = search_opts.pop( 'description') # like filter for key, db_key in (('name~', 'display_name~'), ('description~', 'display_description~')): if key in search_opts: search_opts[db_key] = search_opts.pop(key) if sort_key == 'name': sort_key = 'display_name' common.remove_invalid_options( context, search_opts, self._get_share_search_options()) shares = self.share_api.get_all( context, search_opts=search_opts, sort_key=sort_key, sort_dir=sort_dir) total_count = None if show_count: total_count = len(shares) if is_detail: shares = self._view_builder.detail_list(req, shares, total_count) else: shares = self._view_builder.summary_list(req, shares, total_count) return shares
def test_bool_with_valid_string(self, string, value): fake_dict = {'fake_key': string} result = utils.get_bool_from_api_params('fake_key', fake_dict) self.assertEqual(value, result)
def _get_shares(self, req, is_detail): """Returns a list of shares, transformed through view builder.""" context = req.environ['manila.context'] search_opts = {} search_opts.update(req.GET) # Remove keys that are not related to share attrs search_opts.pop('limit', None) search_opts.pop('offset', None) sort_key = search_opts.pop('sort_key', 'created_at') sort_dir = search_opts.pop('sort_dir', 'desc') show_count = False if 'with_count' in search_opts: show_count = utils.get_bool_from_api_params( 'with_count', search_opts) search_opts.pop('with_count') # Deserialize dicts if 'metadata' in search_opts: search_opts['metadata'] = ast.literal_eval(search_opts['metadata']) if 'extra_specs' in search_opts: search_opts['extra_specs'] = ast.literal_eval( search_opts['extra_specs']) # NOTE(vponomaryov): Manila stores in DB key 'display_name', but # allows to use both keys 'name' and 'display_name'. It is leftover # from Cinder v1 and v2 APIs. if 'name' in search_opts: search_opts['display_name'] = search_opts.pop('name') if 'description' in search_opts: search_opts['display_description'] = search_opts.pop( 'description') # like filter for key, db_key in (('name~', 'display_name~'), ('description~', 'display_description~')): if key in search_opts: search_opts[db_key] = search_opts.pop(key) if sort_key == 'name': sort_key = 'display_name' common.remove_invalid_options( context, search_opts, self._get_share_search_options()) shares = self.share_api.get_all( context, search_opts=search_opts, sort_key=sort_key, sort_dir=sort_dir) total_count = None if show_count: total_count = len(shares) limited_list = common.limited(shares, req) if is_detail: shares = self._view_builder.detail_list(req, limited_list, total_count) else: shares = self._view_builder.summary_list(req, limited_list, total_count) return shares
def test_bool_with_valid_string(self, string, value): fake_dict = {'fake_key': string} result = utils.get_bool_from_api_params('fake_key', fake_dict) self.assertEqual(value, result)