Beispiel #1
0
def build_validator(registrar_dao):
    return ValidationGroup(
        create=[
            Optional('provisioning_code', ProvCodeAvailable(line_dao)),
            Optional('registrar',
                     GetResource('registrar', registrar_dao.get, 'Registrar')),
            GetResource('context', context_dao.get_by_name, 'Context'),
        ],
        edit=[
            ProvCodeChanged(line_dao),
            GetResource('registrar', registrar_dao.get, 'Registrar'),
            GetResource('context', context_dao.get_by_name, 'Context'),
        ],
    )
Beispiel #2
0
def build_validator():
    destination_validators = {
        'agent': [GetResource('agent_id', agent_dao.get, 'Agent')],
        'bsfilter': [
            ResourceExists('filter_member_id', call_filter_dao.member_exists,
                           'FilterMember')
        ],
        'conference':
        [GetResource('conference_id', conference_dao.get, 'Conference')],
        'custom': [CustomValidator()],
        'forward': [ForwardValidator()],
        'group': [GetResource('group_id', group_dao.get, 'Group')],
        'groupmember': [GetResource('group_id', group_dao.get, 'Group')],
        'onlinerec': [],
        'paging': [GetResource('paging_id', paging_dao.get, 'Paging')],
        'park_position': [ParkPositionValidator(feature_dao)],
        'parking': [],
        'queue': [GetResource('queue_id', queue_dao.get, 'Queue')],
        'service': [],
        'transfer': [],
        'user': [GetResource('user_id', user_dao.get, 'User')],
    }

    funckey_validator = FuncKeyModelValidator(destination_validators)
    mapping_validator = FuncKeyMappingValidator(funckey_validator)
    similar_validator = SimilarFuncKeyValidator()

    private_template_validator = PrivateTemplateValidator()

    return ValidationGroup(
        common=[mapping_validator, similar_validator],
        delete=[private_template_validator],
    )
Beispiel #3
0
def build_validator():
    return ValidationGroup(
        create=[
            Optional(
                'context',
                GetResource('context', context_dao_module.get_by_name,
                            'Context'),
            ),
            ContextTenantValidator(context_dao_module),
        ],
        edit=[
            Optional(
                'context',
                GetResource('context', context_dao_module.get_by_name,
                            'Context'),
            ),
            ContextTenantValidator(context_dao_module),
        ],
    )
Beispiel #4
0
class TestGetResource(unittest.TestCase):
    def setUp(self):
        self.dao_get = Mock()
        self.validator = GetResource('field', self.dao_get)

    def test_given_resource_does_not_exist_then_raises_error(self):
        model = Mock(field=sentinel.field)

        self.dao_get.side_effect = NotFoundError

        assert_that(
            calling(self.validator.validate).with_args(model),
            raises(InputError))

    def test_given_resource_exists_then_validation_passes(self):
        model = Mock(field=sentinel.field)

        self.validator.validate(model)

        self.dao_get.assert_called_once_with(model.field)
Beispiel #5
0
class ClosedDestinationValidator:

    _VALIDATORS = {
        'user': [
            GetResource('fallback_actionid', user_dao.get, 'User'),
            GetMohFromClosedSchedule(moh_dao.get),
        ],
    }

    def validate(self, schedule):
        for validator in self._VALIDATORS.get(schedule.fallback_action, []):
            validator.validate(schedule)
Beispiel #6
0
def build_validator():
    return ValidationGroup(
        common=[
            GetResource('context', context_dao.get_by_name, 'Context'),
            Optional(
                'timezone',
                MemberOfSequence('timezone',
                                 static_voicemail.find_all_timezone,
                                 'Timezone'),
            ),
        ],
        create=[NumberContextExists(voicemail_dao)],
        edit=[NumberContextChanged(voicemail_dao)],
        delete=[AssociatedToUser()],
    )
Beispiel #7
0
class DestinationValidator:

    _VALIDATORS = {
        'application:callbackdisa': [],
        'application:custom':
        [GetResource('actionarg1', application_dao.get, 'Application')],
        'application:directory': [],
        'application:disa': [],
        'application:faxtomail': [],
        'application:voicemailmain': [],
        'conference':
        [GetResource('actionarg1', conference_dao.get, 'Conference')],
        'custom': [],
        'extension': [],
        'group': [GetResource('actionarg1', group_dao.get, 'Group')],
        'endcall:busy': [],
        'endcall:congestion': [],
        'endcall:hangup': [],
        'ivr': [GetResource('actionarg1', ivr_dao.get, 'IVR')],
        'none': [],
        'outcall': [GetResource('actionarg1', outcall_dao.get, 'Outcall')],
        'queue': [
            GetResource('actionarg1', queue_dao.get, 'Queue'),
            OptionalGetSkillRuleFromActionArg2Resource(skill_rule_dao.get),
        ],
        'sound': [],
        'switchboard':
        [GetResource('actionarg1', switchboard_dao.get, 'Switchboard')],
        'user': [
            GetResource('actionarg1', user_dao.get, 'User'),
            GetMohFromActionArg2Resource(moh_dao.get),
        ],
        'voicemail':
        [GetResource('actionarg1', voicemail_dao.get, 'Voicemail')],
    }

    def validate(self, destination):
        for validator in self._VALIDATORS[destination.action]:
            validator.validate(destination)
Beispiel #8
0
def build_validator():
    return ValidationGroup(
        common=[GetResource('context', context_dao_module.get_by_name, 'Context')],
        create=[
            ExtenAvailableOnCreateValidator(
                extension_dao_module, parking_lot_dao_module
            ),
            ExtenRegexValidator(context_dao_module),
        ],
        edit=[
            ExtenAvailableOnUpdateValidator(
                extension_dao_module, parking_lot_dao_module
            ),
            ContextOnUpdateValidator(context_dao_module),
            ExtensionRangeValidator(context_dao_module),
            ExtenRegexValidator(context_dao_module),
            SameTenantValidator(context_dao_module),
        ],
        delete=[
            ExtensionAssociationValidator(
                extension_dao_module, line_extension_dao_module
            )
        ],
    )
Beispiel #9
0
 def setUp(self):
     self.dao_get = Mock()
     self.validator = GetResource('field', self.dao_get)