def validate(self, value): verrors = ValidationErrors() for attr in self.attrs.values(): if attr.name in value: try: attr.validate(value[attr.name]) except ValidationErrors as e: verrors.add_child(self.name, e) for v in value: if v not in Cron.FIELDS: verrors.add(self.name, f'Unexpected {v} value') if verrors: raise verrors cron_expression = '' for field in Cron.FIELDS: cron_expression += value.get(field) + ' ' if value.get(field) else '* ' try: croniter(cron_expression) except Exception as e: verrors.add(self.name, 'Please ensure fields match cron syntax - ' + str(e)) if verrors: raise verrors
def validate(self, value): verrors = ValidationErrors() for attr in self.attrs.values(): if attr.name in value: try: attr.validate(value[attr.name]) except ValidationErrors as e: verrors.add_child(self.name, e) for v in value: if v not in Cron.FIELDS: verrors.add(self.name, f'Unexpected {v} value') if verrors: raise verrors cron_expression = '' for field in Cron.FIELDS: cron_expression += value.get(field) + ' ' if value.get( field) else '* ' try: croniter(cron_expression) except Exception as e: verrors.add(self.name, 'Please ensure fields match cron syntax - ' + str(e)) if verrors: raise verrors
def validate(self, value): if value is None: return verrors = ValidationErrors() s = set() for i, v in enumerate(value): if self.unique: if isinstance(v, dict): v = tuple(sorted(list(v.items()))) if v in s: verrors.add(f"{self.name}.{i}", "This value is not unique.") s.add(v) attr_verrors = ValidationErrors() for attr in self.items: try: attr.validate(v) except ValidationErrors as e: attr_verrors.add_child(f"{self.name}.{i}", e) else: break else: verrors.extend(attr_verrors) if verrors: raise verrors super().validate(value)
def construct_schema( item_version_details: dict, new_values: dict, update: bool, old_values: Union[dict, object] = NOT_PROVIDED ) -> dict: schema_name = f'chart_release_{"update" if update else "create"}' attrs = list(itertools.chain.from_iterable( get_schema(q, update, old_values) for q in item_version_details['schema']['questions'] )) dict_obj = update_conditional_defaults( Dict(schema_name, *attrs, update=update, additional_attrs=True), { 'schema': {'attrs': item_version_details['schema']['questions']} } ) verrors = ValidationErrors() verrors.add_child('values', validate_schema( attrs, new_values, True, dict_kwargs={ 'conditional_defaults': dict_obj.conditional_defaults, 'update': update, } )) return { 'verrors': verrors, 'new_values': new_values, 'dict_obj': dict_obj, 'schema_name': schema_name, }
def validate(self, value): if value is None: return verrors = ValidationErrors() for attr in self.attrs.values(): if attr.name in value: try: attr.validate(value[attr.name]) except ValidationErrors as e: verrors.add_child(self.name, e) for v in value: if self.begin_end and v in ['begin', 'end']: continue if v not in Cron.FIELDS: verrors.add(self.name, f'Unexpected {v} value') if verrors: raise verrors cron_expression = '' for field in Cron.FIELDS: cron_expression += value.get(field) + ' ' if value.get( field) else '* ' try: iter = croniter(cron_expression) except Exception as e: iter = None verrors.add(self.name, 'Please ensure fields match cron syntax - ' + str(e)) if value.get('begin') and value.get('end') and not ( value.get('begin') <= value.get('end')): verrors.add(self.name, 'Begin time should be less or equal than end time') if iter is not None and (value.get('begin') or value.get('end')): begin = value.get('begin') or time(0, 0) end = value.get('end') or time(23, 59) for i in range(24 * 60): d = iter.get_next(datetime) if begin <= d.time() <= end: break else: verrors.add( self.name, 'Specified schedule does not match specified time interval' ) if verrors: raise verrors
def validate(self, value): verrors = ValidationErrors() for attr in self.attrs.values(): if attr.name in value: try: attr.validate(value[attr.name]) except ValidationErrors as e: verrors.add_child(self.name, e) if verrors: raise verrors
def validate(self, value): verrors = ValidationErrors() for i, v in enumerate(value): for attr in self.items: try: attr.validate(v) except ValidationErrors as e: verrors.add_child(f"{self.name}.{i}", e) if verrors: raise verrors
def validate(self, value): if value is None: return verrors = ValidationErrors() for attr in self.attrs.values(): if attr.name in value: try: attr.validate(value[attr.name]) except ValidationErrors as e: verrors.add_child(self.name, e) for v in value: if self.begin_end and v in ['begin', 'end']: continue if v not in Cron.FIELDS: verrors.add(self.name, f'Unexpected {v} value') if verrors: raise verrors cron_expression = '' for field in Cron.FIELDS: cron_expression += value.get(field) + ' ' if value.get( field) else '* ' try: croniter(cron_expression) except Exception as e: verrors.add(self.name, 'Please ensure fields match cron syntax - ' + str(e)) if value.get('begin') and value.get('end') and not ( value.get('begin') <= value.get('end')): verrors.add(self.name, 'Begin time should be less or equal than end time') if verrors: raise verrors
def validate(self, value): if value is None: return verrors = ValidationErrors() s = set() for i, v in enumerate(value): if self.unique: if v in s: verrors.add(f"{self.name}.{i}", "This value is not unique.") s.add(v) for attr in self.items: try: attr.validate(v) except ValidationErrors as e: verrors.add_child(f"{self.name}.{i}", e) if verrors: raise verrors super().validate(value)
def validate(self, value): if value is None: return verrors = ValidationErrors() for attr in self.attrs.values(): if attr.name in value: try: attr.validate(value[attr.name]) except ValidationErrors as e: verrors.add_child(self.name, e) for v in value: if self.begin_end and v in ['begin', 'end']: continue if v not in Cron.FIELDS: verrors.add(self.name, f'Unexpected {v} value') if verrors: raise verrors cron_expression = '' for field in Cron.FIELDS: cron_expression += value.get(field) + ' ' if value.get(field) else '* ' try: croniter(cron_expression) except Exception as e: verrors.add(self.name, 'Please ensure fields match cron syntax - ' + str(e)) if value.get('begin') and value.get('end') and not (value.get('begin') <= value.get('end')): verrors.add(self.name, 'Begin time should be less or equal than end time') if verrors: raise verrors
def validate(self, value): if value is None: return verrors = ValidationErrors() s = set() for i, v in enumerate(value): if self.unique: if isinstance(v, dict): v = tuple(sorted(list(v.items()))) if v in s: verrors.add(f"{self.name}.{i}", "This value is not unique.") s.add(v) for attr in self.items: try: attr.validate(v) except ValidationErrors as e: verrors.add_child(f"{self.name}.{i}", e) if verrors: raise verrors super().validate(value)