class Command(MonitorMixin, Resource): #: The address to call (without protocol or domain). Eg: #: ``/api/<username>/groups/0/action`` address = fields.String(v.Required()) #: The body of the request body = fields.Dictionary() #: The HTTP request method method = fields.String(v.In(['GET', 'PUT', 'POST', 'DELETE']))
class Schedule(MonitorMixin, Resource): #: The name of the schedule. name = fields.String(v.Required()) #: Description of the schedule description = fields.String() #: Command to execute when the scheduled event occurs command = fields.Embedded(Command) #: Local time when the scheduled event will occur local_time = fields.TimePattern(name='localtime') #: Status, either 'enabled' or 'disabled' status = fields.String(v.In(['enabled', 'disabled'])) #: If set to true, the schedule will be removed automatically if expired, #: if set to false it will be disabled. Default is true. auto_delete = fields.Boolean(name='autodelete') #: UTC time that the timer was started. Only provided for timers. start_time = fields.IsoDate(name='starttime', read_only=True)
def __init__(self, *validators, **kwargs): self.options = kwargs self.default = kwargs.get('default') # Setup field validators self.validators = [] if kwargs.get('required'): self.validators.append(builtin_validators.Required()) choices = kwargs.get('choices') if choices: self.validators.append(builtin_validators.In(choices)) self.validators.extend(validators)
def __init__(self, *validators, **kwargs): self.options = kwargs self.default = kwargs.get('default') self.description = kwargs.get('description', '') self.required = kwargs.get('required', False) self.choices = kwargs.get('choices', []) assert isinstance(self.choices, list) # Setup field validators self.validators = [] if self.required: self.validators.append(builtin_validators.Required()) if self.choices: self.validators.append(builtin_validators.In(self.choices)) self.validators.extend(validators)
def setup(self): self.validator = validators.Required()
def test_should_raise_validation_error_if_field_validator_raise(self): self.field = fields.List(validators.Required()) expect(lambda: self.validate(None)).to( raise_error(errors.ValidationError, end_with('required')))
def test_should_pass_if_pass_field_validators(self): self.field = fields.List(validators.Required()) self.validate(['foo', 'bar'])