Ejemplo n.º 1
0
def test_validate_should_raise_when_invalid():
    schema_dict = {
        'properties': {
            'name': {
                'type': 'string',
            }
        },
        'required': ['name'],
    }
    data = {}
    schema = Profile(schema_dict)
    with pytest.raises(exceptions.ValidationError):
        schema.validate(data)
Ejemplo n.º 2
0
def test_validate_should_raise_when_invalid():
    schema_dict = {
        'properties': {
            'name': {
                'type': 'string',
            }
        },
        'required': ['name'],
    }
    data = {}
    schema = Profile(schema_dict)
    with pytest.raises(exceptions.ValidationError):
        schema.validate(data)
Ejemplo n.º 3
0
def test_validate():
    schema_dict = {
        'properties': {
            'name': {
                'type': 'string',
            }
        },
        'required': ['name'],
    }
    data = {
        'name': 'Sample Package',
    }
    schema = Profile(schema_dict)
    schema.validate(data)
Ejemplo n.º 4
0
def test_validate():
    schema_dict = {
        'properties': {
            'name': {
                'type': 'string',
            }
        },
        'required': ['name'],
    }
    data = {
        'name': 'Sample Package',
    }
    schema = Profile(schema_dict)
    schema.validate(data)
Ejemplo n.º 5
0
    def validate(self, raise_on_error=True, schema_only=True):
        """Validate a datapackage schema.

        By default, only the data-package schema is validated. To validate the
        data files too, set the `data` flag to `True`. The method fails if an
        error is found, unless the `raise_error` flag is explicitely set to
        `False`.

        :param raise_on_error: raise error on failure or not (default: True)
        :param schema_only: only validate the schema (default: True)
        :raise: :class:`ValidationError` if the schema is invalid

        :return A list of error messages or an empty list.
        """
        messages = []
        profile = Profile('fiscal-data-package')

        if raise_on_error:
            profile.validate(self.descriptor)
        else:
            try:
                profile.validate(self.descriptor)
                message = '%s (%s) is a valid fiscal data-package schema'
                log.info(message, self.path, self)
            except ValidationError as e:
                for error in e.errors:
                    message = 'SCHEMA ERROR in %s: %s'
                    args = self.path, error
                    messages.append(message % args)
                    log.warn(message, *args)

        if messages:
            messages.append('Aborting data validation due to invalid schema')
            return messages

        if not schema_only:
            return self._validate_data(raise_on_error)
        else:
            return messages