Esempio n. 1
0
def validate_job_data(job_data):
    schema = Schema(job_schema)
    Validator.validate(schema, job_data)
    lava_commands = get_all_cmds()
    for action in job_data['actions']:
        command_name = action['command']
        command = lava_commands.get(command_name)
        if command is None:
            raise ValueError("action %r not known" % command_name)
        command.validate_parameters(action.get('parameters'))
Esempio n. 2
0
def validate_job_data(job_data):
    schema = Schema(job_schema)
    Validator.validate(schema, job_data)
    lava_commands = get_all_cmds()
    for action in job_data['actions']:
        command_name = action['command']
        command = lava_commands.get(command_name)
        if command is None:
            raise ValueError("action %r not known" % command_name)
        command.validate_parameters(action.get('parameters'))
Esempio n. 3
0
def validate(schema_text, data_text, deserializer=_default_deserializer):
    """
    Validate specified JSON text with specified schema.

    Both arguments are converted to JSON objects with :func:`simplejson.loads`,
    if present, or :func:`json.loads`.

    :param schema_text:
        Text of the JSON schema to check against
    :type schema_text:
        :class:`str`
    :param data_text:
        Text of the JSON object to check
    :type data_text:
        :class:`str`
    :param deserializer:
        Function to convert the schema and data to JSON objects
    :type deserializer:
        :class:`callable`
    :returns:
        Same as :meth:`json_schema_validator.validator.Validator.validate`
    :raises:
        Whatever may be raised by simplejson (in particular
        :class:`simplejson.decoder.JSONDecoderError`, a subclass of
        :class:`ValueError`) or json
    :raises:
        Whatever may be raised by
        :meth:`json_schema_validator.validator.Validator.validate`. In particular
        :class:`json_schema_validator.errors.ValidationError` and
        :class:`json_schema_validator.errors.SchemaError`
    """
    schema = Schema(deserializer(schema_text))
    data = deserializer(data_text)
    return Validator.validate(schema, data)
Esempio n. 4
0
 def validate(self):
     """
     Validate the fragment value against the schema. If the validator is
     not defined, uses the default validator.
     """
     if self._schema is not None:
         if self._validator is None:
             Validator.validate(self.schema, self.value)
         else:
             [mod, func] = self._validator.rsplit('.',1) 
             try:
                 val_func = getattr(import_module(mod), func)
                 val_func(self.schema, self.value)
             except:
                 print "Unable to validate: " , sys.exc_info()[0]
                 raise
def validate(schema_text, data_text):
    """
    Validate specified JSON text (data_text) with specified schema (schema
    text). Both are converted to JSON objects with :func:`simplesjon.loads`.

    :param schema_text:
        Text of the JSON schema to check against
    :type schema_text:
        :class:`str`
    :param data_text:
        Text of the JSON object to check
    :type data_text:
        :class:`str`
    :returns:
        Same as :meth:`json_schema_validator.validator.Validator.validate`
    :raises:
        Whatever may be raised by simplejson (in particular
        :class:`simplejson.decoder.JSONDecoderError`, a subclass of :class:`ValueError`)
    :raises:
        Whatever may be raised by
        :meth:`json_schema_validator.validator.Validator.validate`. In particular
        :class:`json_schema_validator.errors.ValidationError` and
        :class:`json_schema_validator.errors.SchemaError`


    """
    schema = Schema(simplejson.loads(schema_text))
    data = simplejson.loads(data_text)
    return Validator.validate(schema, data)
Esempio n. 6
0
def validate(schema_text, data_text):
    """
    Validate specified JSON text (data_text) with specified schema (schema
    text). Both are converted to JSON objects with :func:`simplesjon.loads`.

    :param schema_text:
        Text of the JSON schema to check against
    :type schema_text:
        :class:`str`
    :param data_text:
        Text of the JSON object to check
    :type data_text:
        :class:`str`
    :returns:
        Same as :meth:`json_schema_validator.validator.Validator.validate`
    :raises:
        Whatever may be raised by simplejson (in particular
        :class:`simplejson.decoder.JSONDecoderError`, a subclass of :class:`ValueError`)
    :raises:
        Whatever may be raised by
        :meth:`json_schema_validator.validator.Validator.validate`. In particular
        :class:`json_schema_validator.errors.ValidationError` and
        :class:`json_schema_validator.errors.SchemaError`


    """
    schema = Schema(simplejson.loads(schema_text))
    data = simplejson.loads(data_text)
    return Validator.validate(schema, data)
Esempio n. 7
0
def run_testcases_python(casemap):
    for schemafile, casefiles in casemap.iteritems():
        print "SCHEMA:", schemafile
        sj = read_json(schemafile)
        print sj
        schema = Schema(sj)
        for casefile in casefiles:
            print "CASE:", casefile
            cj = read_json(casefile)
            print cj
            assert Validator.validate(schema, cj)
    def check(cls, doc):
        """
        Check document format and validate the contents against a schema.

        :Discussion:
            The document is validated against a set of known versions
            and their schemas.

        :Return value:
            String identifying document format

        :Exceptions:
            json_schema_validator.errors.ValidationError
                When the document does not match the appropriate schema.
            linaro_dashboard_bundle.errors.DocumentFormatError
                When the document format is not in the known set of formats.
        """
        fmt = doc.get('format')
        schema = cls.SCHEMAS.get(fmt)
        if schema is None:
            raise DocumentFormatError(fmt)
        Validator.validate(schema, doc)
        return fmt
Esempio n. 9
0
    def check(cls, doc):
        """
        Check document format and validate the contents against a schema.

        :Discussion:
            The document is validated against a set of known versions
            and their schemas.

        :Return value:
            String identifying document format

        :Exceptions:
            json_schema_validator.errors.ValidationError
                When the document does not match the appropriate schema.
            linaro_dashboard_bundle.errors.DocumentFormatError
                When the document format is not in the known set of formats.
        """
        fmt = doc.get('format')
        schema = cls.SCHEMAS.get(fmt)
        if schema is None:
            raise DocumentFormatError(fmt)
        Validator.validate(schema, doc)
        return fmt
Esempio n. 10
0
    def validate_resources(consumer_record):
        """
        This method validates that the passed consumer record  is a valid resources record

        Args:
            consumer_record (str): A valid JSON string representation of the consumer record

        Returns:
            bool: True if validation passes, False otherwise
        """
        try:
            return Validator.validate(
                PanoptesConsumerRecordValidator._resource_schema,
                consumer_record)
        except ValidationError:
            return False
Esempio n. 11
0
def _validate_lmp_module(lmp_module_data):
    schema = Schema(lmp_module_schema)
    Validator.validate(schema, lmp_module_data)
Esempio n. 12
0
 def validate_parameters(cls, params):
     if cls.parameters_schema:
         if params is None:
             params = {}
         schema = Schema(cls.parameters_schema)
         Validator.validate(schema, params)
Esempio n. 13
0
 def validate(self):
     """
     Validate the fragment value against the schema
     """
     if self._schema is not None:
         Validator.validate(self.schema, self.value)
def _validate_lmp_module(lmp_module_data):
    schema = Schema(lmp_module_schema)
    Validator.validate(schema, lmp_module_data)
 def validate_parameters(cls, params):
     if cls.parameters_schema:
         if params is None:
             params = {}
         schema = Schema(cls.parameters_schema)
         Validator.validate(schema, params)
Esempio n. 16
0
    offers = decoders.keys()
    content_type = request.content_type

    if content_type not in offers:
        raise exc.HTTPUnsupportedMediaType(u"%s is not supported" % content_type)

    decoder = decoders[content_type]

    try:
        data = decoder(request.body)
    except Exception, error:
        raise exc.HTTPBadRequest(unicode(error))

    if json_schema:
        try:
            valid = Validator.validate(Schema(json_schema), data)
        except ValidationError, error:
            error_message = u"""%s

Schema:

%s""" % (unicode(error), json.dumps(json_schema).decode("ascii"))

            raise exc.HTTPBadRequest(error_message)

    return data


class FrontController(object):
    def __init__(self, applications):
        self.applications = applications
Esempio n. 17
0
 def validate(self):
     """
     Validate the fragment value against the schema
     """
     if self._schema is not None:
         Validator.validate(self.schema, self.value)