def test_when_validating_delete_then_calls_common_and_delete_validators(self): common = Mock(Validator) delete = Mock(Validator) model = Mock() validator = ValidationGroup(common=[common], delete=[delete]) validator.validate_delete(model) common.validate.assert_called_once_with(model) delete.validate.assert_called_once_with(model)
def test_when_validating_edit_then_calls_common_and_edit_validators(self): common = Mock(Validator) edit = Mock(Validator) model = Mock() validator = ValidationGroup(common=[common], edit=[edit]) validator.validate_edit(model) common.validate.assert_called_once_with(model) edit.validate.assert_called_once_with(model)
def build_validator(): destination_validators = { 'user': [GetResource('user_id', user_dao.get, 'User')], 'group': [ResourceExists('group_id', group_dao.exists, 'Group')], 'queue': [ResourceExists('queue_id', queue_dao.exists, 'Queue')], 'conference': [ResourceExists('conference_id', conference_dao.exists, 'Conference')], 'custom': [CustomValidator()], 'service': [], 'forward': [ForwardValidator()], 'transfer': [], 'agent': [ResourceExists('agent_id', agent_dao.exists, 'Agent')], 'park_position': [ParkPositionValidator(feature_dao)], 'parking': [], 'onlinerec': [], 'paging': [ResourceExists('paging_id', paging_dao.exists, 'Paging')], 'bsfilter': [ ResourceExists('filter_member_id', bsfilter_dao.filter_member_exists, 'FilterMember') ], } funckey_validator = FuncKeyModelValidator(destination_validators) mapping_validator = FuncKeyMappingValidator(funckey_validator) similar_validator = SimilarFuncKeyValidator() required_validator = MissingFields() private_template_validator = PrivateTemplateValidator() return ValidationGroup( common=[required_validator, mapping_validator, similar_validator], delete=[private_template_validator])
def build_validator(device_dao, line_dao): return ValidationGroup( common=[ Optional( 'ip', RegexField.compile('ip', IP_REGEX, "wrong type: IP Address")), Optional( 'mac', RegexField.compile('mac', MAC_REGEX, "wrong type: MAC Address")), Optional('plugin', MemberOfSequence('plugin', device_dao.plugins, 'Plugin')), Optional( 'template_id', MemberOfSequence('template_id', device_dao.device_templates, 'DeviceTemplate')), OptionsValidator(), ], create=[ Optional( 'mac', UniqueField('mac', lambda mac: device_dao.find_by(mac=mac), 'Device')), ], edit=[ Optional('mac', UniqueFieldChanged('mac', device_dao, 'Device')), ], delete=[DeviceNotAssociated(line_dao)], )
def build_validator(): return ValidationGroup( common=[ RequiredFields('interface'), RegexField.compile('interface', INTERFACE_REGEX), ], create=[UniqueField('interface', find_by_interface, 'CustomEndpoint')], edit=[UniqueFieldChanged('interface', dao, 'CustomEndpoint')])
def build_validator_forward(): return ValidationGroup(edit=[ Optional('busy_enabled', NoEmptyFieldWhenEnabled('busy_destination', 'busy_enabled')), Optional( 'noanswer_enabled', NoEmptyFieldWhenEnabled('noanswer_destination', 'noanswer_enabled')), Optional( 'unconditional_enabled', NoEmptyFieldWhenEnabled('unconditional_destination', 'unconditional_enabled')) ])
def build_validator(): return ValidationGroup( common=[ RequiredFields('firstname'), Optional( 'mobile_phone_number', RegexField.compile('mobile_phone_number', MOBILE_PHONE_NUMBER_REGEX)), Optional('caller_id', RegexField.compile('caller_id', CALLER_ID_REGEX)), Optional('username', RegexField.compile('username', USERNAME_PASSWORD_REGEX)), Optional('password', RegexField.compile('password', USERNAME_PASSWORD_REGEX)), Optional( 'call_permission_password', RegexField.compile('call_permission_password', CALL_PERMISSION_PASSWORD_REGEX)), Optional( 'ring_seconds', NumberRange('ring_seconds', minimum=0, maximum=60, step=5)), Optional('simultaneous_calls', NumberRange('simultaneous_calls', minimum=1, maximum=20)), Optional('language', RegexField.compile('language', LANGUAGE_REGEX)), Optional( 'entity_id', ResourceExists('entity_id', entity_db.entity_id_exists, 'Entity')) ], delete=[ NoVoicemailAssociated(user_voicemail_dao), NoLineAssociated(user_line_dao) ], create=[ Optional( 'email', UniqueField('email', lambda email: user_dao.find_by(email=email), 'User')) ], edit=[ RequiredFields('call_transfer_enabled', 'call_record_enabled', 'online_call_record_enabled', 'supervision_enabled', 'ring_seconds', 'simultaneous_calls', 'caller_id', 'enabled'), Optional('email', UniqueFieldChanged('email', user_dao, 'User')), ])
def build_validator(): return ValidationGroup(common=[ RequiredFields('exten', 'context'), GetResource('context', context_dao.get, 'Context'), ExtensionRangeValidator(context_dao), ], create=[ ExtenAvailableOnCreateValidator(extension_dao), ], edit=[ ExtenAvailabelOnUpdateValidator(extension_dao), ], delete=[ ExtensionAssociationValidator( extension_dao, line_extension_dao) ])
def build_validators(): return ValidationGroup(common=[ MissingFields(), FindResource('context', context_dao.get, 'Context'), RegexField.compile('number', NUMBER_REGEX, "numeric string (max length: 40)"), Optional('language', RegexField.compile('language', LANGUAGE_REGEX)), Optional( 'timezone', MemberOfSequence('timezone', voicemail_dao.find_all_timezone, 'Timezone')), Optional( 'password', RegexField.compile('password', PASSWORD_REGEX, "numeric string (max length: 80)")), ], create=[NumberContextExists(voicemail_dao)], edit=[NumberContextChanged(voicemail_dao)], delete=[AssociatedToUser(user_voicemail_dao)])
def build_validator(): return ValidationGroup( common=[ Optional( 'name', RegexField.compile( 'name', NAME_REGEX, "username must only use alphanumeric characters")), Optional('secret', RegexField.compile('secret', SECRET_REGEX)) ], create=[ Optional( 'name', UniqueField('name', lambda v: dao.find_by(name=v), 'SIPEndpoint'), RegexField.compile('name', NAME_REGEX)), Optional('secret', RegexField.compile('secret', SECRET_REGEX)), ], edit=[ RequiredFields('name', 'secret', 'type', 'host'), UsernameChanged('name', lambda v: dao.find_by(name=v), dao.get), ])
def build_validator(device_dao): return ValidationGroup(common=[ RequiredFields('context'), FindResource('context', context_dao.find, 'Context'), ], create=[ Optional('provisioning_code', ProvCodeAvailable(line_dao)), Optional('position', NumberRange('position', minimum=1)), Optional( 'registrar', MemberOfSequence('registrar', device_dao.registrars, 'Registrar')), ], edit=[ ProvCodeChanged(line_dao), RequiredFields('provisioning_code', 'position'), NumberRange('position', minimum=1), MemberOfSequence('registrar', device_dao.registrars, 'Registrar'), ])
def build_validator(): return ValidationGroup( common=[ Optional('name', RegexField.compile('name', NAME_REGEX)), Optional('password', RegexField.compile('password', PASSWORD_REGEX)), Optional('extensions', RegexFieldList.compile('extensions', EXTENSION_REGEX)), ], create=[ RequiredFields('name'), Optional( 'name', UniqueField( 'name', lambda name: call_permission_dao.find_by(name=name), 'CallPermission')) ], edit=[ Optional( 'name', UniqueFieldChanged('name', call_permission_dao, 'CallPermission')) ])
def build_service_callservice(): return UserCallServiceService(user_dao, ValidationGroup(), build_notifier_service())
def build_validator(): return ValidationGroup()