Python voluptuous.Invalid() Examples
The following are 30
code examples of voluptuous.Invalid().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
voluptuous
, or try the search function
.
Example #1
Source File: api.py From gnocchi with Apache License 2.0 | 6 votes |
def post(self): schema = pecan.request.indexer.get_resource_type_schema() body = deserialize_and_validate(schema) body["state"] = "creating" try: rt = schema.resource_type_from_dict(**body) except resource_type.InvalidResourceAttribute as e: abort(400, "Invalid input: %s" % e) enforce("create resource type", body) try: rt = pecan.request.indexer.create_resource_type(rt) except indexer.ResourceTypeAlreadyExists as e: abort(409, six.text_type(e)) set_resp_location_hdr("/resource_type/" + rt.name) pecan.response.status = 201 return rt
Example #2
Source File: validation.py From monasca-analytics with Apache License 2.0 | 6 votes |
def validate_links(links): """Validate links to make sure, nothing is missing :type links: dict :param links: connection links to validate :raises: SchemaError -- if any link is missing """ missing = set([]) all_keys = set(links.keys()) for connections in links.values(): for component in connections: if component not in all_keys: missing.add(component.id()) if len(missing) > 0: raise voluptuous.Invalid([ "In connections section, the following components are not " "connected\n\t{}\n" "please modify the configuration so that their list of " "connections is at least '[]'".format(", ".join(missing))], [])
Example #3
Source File: filters.py From udata with GNU Affero General Public License v3.0 | 6 votes |
def boolean(value): ''' Convert the content of a string (or a number) to a boolean. Do nothing when input value is already a boolean. This filter accepts usual values for ``True`` and ``False``: "0", "f", "false", "n", etc. ''' if value is None or isinstance(value, bool): return value try: return bool(int(value)) except ValueError: lower_value = value.strip().lower() if not lower_value: return None if lower_value in ('f', 'false', 'n', 'no', 'off'): return False if lower_value in ('on', 't', 'true', 'y', 'yes'): return True raise Invalid('Unable to parse boolean {0}'.format(value))
Example #4
Source File: validations.py From drf-url-filters with MIT License | 6 votes |
def Alphanumeric(msg=None): ''' Checks whether a value is: - int, or - long, or - float without a fractional part, or - str or unicode composed only of alphanumeric characters ''' def fn(value): if not any([ isinstance(value, numbers.Integral), (isinstance(value, float) and value.is_integer()), (isinstance(value, basestring) and value.isalnum()) ]): raise Invalid(msg or ( 'Invalid input <{0}>; expected an integer'.format(value)) ) else: return value return fn
Example #5
Source File: test_filters.py From udata with GNU Affero General Public License v3.0 | 6 votes |
def test_boolean(self): true_values = ('1', 'on', 't', 'TRUE', 'true', 'y', 'yes', ' 1 ', ' tRuE ', True, 1, 2, -1) false_values = ('0', 'f', 'FALSE', 'false', 'n', 'no', 'off', ' 0 ', ' f ', False, 0) none_values = ('', ' ', None) for value in true_values: assert filters.boolean(value) for value in false_values: assert filters.boolean(value) is False for value in none_values: assert filters.boolean(value) is None with pytest.raises(Invalid): filters.boolean('vrai')
Example #6
Source File: validation.py From monasca-analytics with Apache License 2.0 | 6 votes |
def _validate_existing_id(config, component_id): """Check that the id passed as parameter is defined in the configuration :type config: dict :param config: configuration model for the whole system :type component_id: str :param component_id: component ID to be found in configuration """ found_id = False for comp_type in valid_connection_types.keys(): if component_id in config[comp_type].keys(): found_id = True if not found_id: raise voluptuous.Invalid([ 'In "connections", component `{}` hasn\'t been defined' .format(component_id) ], [])
Example #7
Source File: validations.py From drf-url-filters with MIT License | 6 votes |
def StrictlyAlphanumeric(msg=None): ''' Checks whether a value is: - str or unicode, and - composed of both alphabets and digits ''' def fn(value): if not ( isinstance(value, basestring) and value.isalnum() and not value.isdigit() and not value.isalpha() ): raise Invalid(msg or ( 'Invalid input <{0}>; expected an integer'.format(value)) ) else: return value return fn
Example #8
Source File: request_handler.py From monasca-analytics with Apache License 2.0 | 6 votes |
def post(self): try: body = json.loads(self.request.body) web_service_model.banana_model(body) type_table = self._monanas.compute_type_table(body["content"]) self.write(type_table) except (AttributeError, voluptuous.Invalid, ValueError) as e: logger.warn("Wrong request: {}.". format(e)) self.set_status(400, "The request body was malformed.") except Exception as e: tb = traceback.format_exc() print(tb) logger.error("Unexpected error: {}. {}". format(sys.exc_info()[0], e)) self.set_status(500, "Internal server error.") self.flush() self.finish()
Example #9
Source File: validations.py From drf-url-filters with MIT License | 6 votes |
def __call__(self, value): ''' Checks whether a value is list of given validation_function. Returns list of validated values or just one valid value in list if there is only one element in given CSV string. ''' try: if isinstance(value, basestring): if self.separator in value: seperated_string_values =[item.strip() for item in value.split(self.separator)] values = [self.validation_function(item) for item in seperated_string_values] else: values = [self.validation_function(value)] return values else: raise ValueError except (Invalid, ValueError) as e: raise Invalid(self.msg or ('<{0}> is not valid set of <{1}>, {2}'.format( value, self.value_type, e)))
Example #10
Source File: types.py From mergify-engine with Apache License 2.0 | 6 votes |
def _check_GitHubTeam_format(value): if not value: raise voluptuous.Invalid("A GitHub team cannot be an empty string") # Remove leading @ if any: # This format is accepted in conditions so we're happy to accept it here too. if value[0] == "@": value = value[1:] org, sep, team = value.partition("/") if sep == "" and team == "": # Just a slug return _check_GitHubLogin_format(org, "team") _check_GitHubLogin_format(org, "organization") return _check_GitHubLogin_format(team, "team")
Example #11
Source File: test_config_model.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_server_extra_parameters(self): self.config["server"]["infiltrated"] = "I should not exist" self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config)
Example #12
Source File: test_config_model.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_missing_spark_key(self): for key in list(self.config["spark_config"].keys()): del self.config["spark_config"][key] self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config) self.config = self.get_config() del self.config["spark_config"]["streaming"]["batch_interval"] self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config)
Example #13
Source File: test_config_model.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_wrong_format_components(self): for key in self.comp_types: self.config[key] = ["I", "should", "be", "a", "dictionary"] self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config) self.config = self.get_config() for comp_id in self.config[key].keys(): self.config[key][comp_id] = ["I", "should", "be", "a", "dict"] self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config) self.config = self.get_config()
Example #14
Source File: __init__.py From mergify-engine with Apache License 2.0 | 5 votes |
def PullRequestRuleCondition(value): try: return filter.Filter.parse(value) except filter.parser.pyparsing.ParseException as e: raise voluptuous.Invalid( message="Invalid condition '%s'. %s" % (value, str(e)), error_message=str(e) ) except filter.InvalidQuery as e: raise voluptuous.Invalid( message="Invalid condition '%s'. %s" % (value, str(e)), error_message=str(e) )
Example #15
Source File: __init__.py From mergify-engine with Apache License 2.0 | 5 votes |
def get_mergify_config(ctxt, ref=None): filename, content = get_mergify_config_content(ctxt, ref) try: return filename, UserConfigurationSchema(content) except voluptuous.Invalid as e: raise InvalidRules(e, filename)
Example #16
Source File: test_config_model.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_spark_extra_parameters(self): self.config["spark_config"]["infiltrated"] = "I should not exist" self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config) self.config = self.get_config() self.config["spark_config"]["streaming"][ "infiltrated"] = "I should not exist" self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config)
Example #17
Source File: __init__.py From mergify-engine with Apache License 2.0 | 5 votes |
def YAML(v): try: return yaml.safe_load(v) except yaml.YAMLError as e: error_message = str(e) path = ( [types.LineColumnPath(e.problem_mark.line + 1, e.problem_mark.column + 1)] if hasattr(e, "problem_mark") else None ) raise YAMLInvalid( message="Invalid YAML", error_message=error_message, path=path ) return v
Example #18
Source File: types.py From mergify-engine with Apache License 2.0 | 5 votes |
def _check_GitHubLogin_format(value, type="login"): # GitHub says login cannot: # - start with an hyphen # - ends with an hyphen # - contains something else than hyphen and alpha numericals characters if not value: raise voluptuous.Invalid(f"A GitHub {type} cannot be an empty string") if ( value[0] == "-" or value[-1] == "-" or not value.isascii() or not value.replace("-", "").isalnum() ): raise voluptuous.Invalid(f"GitHub {type} contains invalid characters") return value
Example #19
Source File: test_config_model.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_server_wrong_format(self): self.config["server"]["port"] = "I should be an int" self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config) self.config = self.get_config() self.config["server"]["debug"] = 52 self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config)
Example #20
Source File: test_config_model.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_connections_inexisteng_source(self): self.config["connections"]["inex"] = ["sin2"] self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config) self.config = self.get_config()
Example #21
Source File: test_config_model.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_extra_key(self): self.config = self.get_config() self.config["infiltrated"] = "I should not exist" self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config) self.config = self.get_config()
Example #22
Source File: test_config_model.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_missing_key(self): for key in self.comp_types: del self.config[key] self.assertRaises(voluptuous.Invalid, validation.validate_config, self.config) self.config = self.get_config()
Example #23
Source File: test_markov_chain.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_wrong_type(self): self.assertRaises( voluptuous.Invalid, self.mcs.validate_config, self.config_wrong_type)
Example #24
Source File: test_markov_chain.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_extra_param(self): self.assertRaises( voluptuous.Invalid, self.mcs.validate_config, self.config_extra_param)
Example #25
Source File: test_iptables_markov_chain.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_missing_param(self): self.assertRaises( voluptuous.Invalid, self.ips.validate_config, self.config_missing_param)
Example #26
Source File: test_iptables_markov_chain.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_extra_param(self): self.assertRaises( voluptuous.Invalid, self.ips.validate_config, self.config_extra_param)
Example #27
Source File: test_kafka.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_missing_params(self): self.assertRaises( voluptuous.Invalid, self.ks.validate_config, self.config_missing_params)
Example #28
Source File: test_kafka.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_wrong_type(self): self.assertRaises( voluptuous.Invalid, self.ks.validate_config, self.config_wrong_type)
Example #29
Source File: test_kafka.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_config_extra_param(self): self.assertRaises( voluptuous.Invalid, self.ks.validate_config, self.config_extra_param)
Example #30
Source File: test_sink_config_validator.py From monasca-analytics with Apache License 2.0 | 5 votes |
def test_validate_kafka_sink_invalid_port(self): invalid_config = self._valid_config invalid_config["port"] = "invalid_port" self.assertRaises(voluptuous.Invalid, kafka, invalid_config)