How to use the schematics.exceptions.ValidationError function in schematics

To help you get started, we’ve selected a few schematics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github schematics / schematics / tests / test_validation.py View on Github external
def is_not_future(dt, context=None):
        if dt > now:
            raise ValidationError(future_error_msg)
github schematics / schematics / tests / test_validation.py View on Github external
def validate_publish(self, data, dt, context):
            if data['should_raise'] is True:
                raise ValidationError(u'')
            return dt
github schematics / schematics / tests / test_validation.py View on Github external
def validate_bar(cls, data, value):
            errors = {}

            if 'a' not in value:
                errors['a'] = ValidationError('Key a must be set.')
            if 'b' not in value:
                errors['b'] = ValidationError('Key b must be set.')

            if errors:
                raise DataError(errors)
github schematics / schematics / tests / test_validation.py View on Github external
def test_clean_validation_messages_list():
    error = ValidationError(["A", "B", "C"])
    assert error.messages, ["A", "B", "C"]
github openprocurement / openprocurement.api / src / openprocurement / api / models / schema.py View on Github external
if not relatedItem and data.get('featureOf') in ['item', 'lot']:
            raise ValidationError(u'This field is required.')
        if (
            data.get('featureOf') == 'item'
            and isinstance(data['__parent__'], Model)
            and relatedItem
            not in [i.id for i in data['__parent__'].items]
        ):
            raise ValidationError(u"relatedItem should be one of items")
        if (
            data.get('featureOf') == 'lot'
            and isinstance(data['__parent__'], Model)
            and relatedItem
            not in [i.id for i in data['__parent__'].lots]
        ):
            raise ValidationError(u"relatedItem should be one of lots")
github openprocurement / openprocurement.api / src / openprocurement / api / models.py View on Github external
def validate_parameters(self, data, parameters):
        if isinstance(data['__parent__'], Model):
            tender = data['__parent__']
            if not parameters and tender.features:
                raise ValidationError(u'This field is required.')
            if tender.lots:
                lots = [i.relatedLot for i in data['lotValues']]
                items = [i.id for i in tender.items if i.relatedLot in lots]
                codes = dict([
                    (i.code, [x.value for x in i.enum])
                    for i in (tender.features or [])
                    if i.featureOf == 'tenderer' or i.featureOf == 'lot' and i.relatedItem in lots or i.featureOf == 'item' and i.relatedItem in items
                ])
                if set([i['code'] for i in parameters]) != set(codes):
                    raise ValidationError(u"All features parameters is required.")
            elif set([i['code'] for i in parameters]) != set([i.code for i in (tender.features or [])]):
                raise ValidationError(u"All features parameters is required.")
github openprocurement / openprocurement.api / src / openprocurement / api / models / schema.py View on Github external
def validate_relatedItem(self, data, relatedItem):
        if not relatedItem and data.get('featureOf') in ['item', 'lot']:
            raise ValidationError(u'This field is required.')
        if (
            data.get('featureOf') == 'item'
            and isinstance(data['__parent__'], Model)
            and relatedItem
            not in [i.id for i in data['__parent__'].items]
        ):
            raise ValidationError(u"relatedItem should be one of items")
        if (
            data.get('featureOf') == 'lot'
            and isinstance(data['__parent__'], Model)
            and relatedItem
            not in [i.id for i in data['__parent__'].lots]
        ):
            raise ValidationError(u"relatedItem should be one of lots")
github onicagroup / runway / runway / embedded / stacker / config / __init__.py View on Github external
def validate_template_path(self, data, value):
        if value and data["class_path"]:
            raise ValidationError(
                "class_path cannot be present when "
                "template_path is provided.")
        self.validate_stack_source(data)
github cloudtools / stacker / stacker / config / __init__.py View on Github external
def validate_stack_source(self, data):
        # Locked stacks don't actually need a template, since they're
        # read-only.
        if data["locked"]:
            return

        if not (data["class_path"] or data["template_path"]):
            raise ValidationError(
                "class_path or template_path is required.")
github openprocurement / openprocurement.api / src / openprocurement / api / models / common.py View on Github external
def validate_registrationID(self, data, value):
        if value and data['status'] != 'complete':
            raise ValidationError(u"You can fill registrationID only when status is complete")