示例#1
0
def build_validator():
    moh_validator = MOHExists('music_on_hold', moh_dao.get_by)
    return ValidationGroup(
        delete=[NoVoicemailAssociated(),
                NoLineAssociated(user_line_dao)],
        create=[
            Optional(
                'email',
                UniqueField('email',
                            lambda email: user_dao.find_by(email=email),
                            'User'),
            ),
            Optional(
                'username',
                UniqueField(
                    'username',
                    lambda username: user_dao.find_by(username=username),
                    'User',
                ),
            ),
            moh_validator,
        ],
        edit=[
            Optional('email',
                     UniqueFieldChanged('email', user_dao.find_by, 'User')),
            Optional('username',
                     UniqueFieldChanged('username', user_dao.find_by, 'User')),
            moh_validator,
        ],
    )
示例#2
0
def build_validator():
    return ValidationGroup(
        delete=[NoVoicemailAssociated(),
                NoLineAssociated(user_line_dao)],
        create=[
            Optional(
                'email',
                UniqueField('email',
                            lambda email: user_dao.find_by(email=email),
                            'User'),
            ),
            Optional(
                'username',
                UniqueField(
                    'username',
                    lambda username: user_dao.find_by(username=username),
                    'User',
                ),
            ),
        ],
        edit=[
            Optional('email', UniqueFieldChanged('email', user_dao, 'User')),
            Optional('username',
                     UniqueFieldChanged('username', user_dao, 'User')),
        ],
    )
示例#3
0
def build_validator():
    return ValidationGroup(
        create=[UniqueField('interface', find_by_interface, 'CustomEndpoint')],
        edit=[
            UniqueFieldChanged('interface', custom_dao.find_by,
                               'CustomEndpoint')
        ],
    )
示例#4
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField('name', lambda name: outcall_dao.find_by(name=name),
                        'Outcall')
        ],
        edit=[UniqueFieldChanged('name', outcall_dao.find_by, 'Outcall')],
    )
示例#5
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField(
                'name', lambda name: call_pickup_dao.find_by(name=name), 'CallPickup'
            )
        ],
        edit=[
            Optional('name', UniqueFieldChanged('name', call_pickup_dao, 'CallPickup'))
        ],
    )
示例#6
0
class TestUniqueField(unittest.TestCase):
    def setUp(self):
        self.dao_find = Mock()
        self.validator = UniqueField('field', self.dao_find)

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

        self.dao_find.return_value = None

        self.validator.validate(model)

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

        self.dao_find.return_value = model

        assert_that(
            calling(self.validator.validate).with_args(model),
            raises(ResourceError))
示例#7
0
def build_validator():
    moh_validator = MohModelValidator()

    return ValidationGroup(
        create=[
            UniqueField('name', lambda name: moh_dao.find_by(name=name),
                        'MOH'),
            moh_validator,
        ],
        edit=[moh_validator],
    )
示例#8
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField('number',
                        lambda number: agent_dao.find_by(number=number),
                        'Agent')
        ],
        edit=[
            Optional('number', UniqueFieldChanged('number', agent_dao,
                                                  'Agent'))
        ],
    )
示例#9
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField(
                'name',
                lambda name, tenant_uuids: skill_dao.find_by(
                    name=name, tenant_uuids=tenant_uuids),
                'Skill',
            )
        ],
        edit=[UniqueFieldChanged('name', skill_dao.find_by, 'Skill')],
    )
示例#10
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField('name', lambda name: group_dao.find_by(name=name),
                        'Group'),
            GroupValidator(),
        ],
        edit=[
            Optional('name', UniqueFieldChanged('name', group_dao, 'Group')),
            GroupValidator(),
        ],
    )
示例#11
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField('name', lambda name: queue_dao.find_by(name=name),
                        'Queue'),
            QueueValidator(),
        ],
        edit=[
            Optional('name', UniqueFieldChanged('name', queue_dao, 'Queue')),
            QueueValidator(),
        ],
    )
示例#12
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField('number',
                        lambda number: paging_dao.find_by(number=number),
                        'Paging')
        ],
        edit=[
            Optional(
                'number',
                UniqueFieldChanged('number', paging_dao.find_by, 'Paging'))
        ],
    )
示例#13
0
def build_validator():
    return ValidationGroup(
        create=[
            Optional(
                'name',
                UniqueField('name', lambda v: sip_dao.find_by(name=v),
                            'SIPEndpoint'),
            )
        ],
        edit=[
            Optional('name', UniqueFieldChanged('name', sip_dao,
                                                'SIPEndpoint'))
        ],
    )
示例#14
0
def build_validator():
    return ValidationGroup(
        create=[
            Optional(
                'name',
                UniqueField('name', lambda value: iax_dao.find_by(name=value),
                            'IAXEndpoint'),
            )
        ],
        edit=[
            Optional('name', UniqueFieldChanged('name', iax_dao,
                                                'IAXEndpoint'))
        ],
    )
示例#15
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField('name', lambda name: context_dao.find_by(name=name),
                        'Context')
        ],
        delete=[
            ContextDeleteValidator(
                agent_login_status_dao_module,
                extension_dao_module,
                trunk_dao_module,
                voicemail_dao_module,
            )
        ],
    )
示例#16
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField(
                'name',
                lambda name, tenant_uuids: call_permission_dao.find_by(
                    name=name, tenant_uuids=tenant_uuids),
                'CallPermission',
            )
        ],
        edit=[
            UniqueFieldChanged('name', call_permission_dao.find_by,
                               'CallPermission'),
        ],
    )
示例#17
0
def build_validator():
    return ValidationGroup(
        create=[
            UniqueField('name',
                        lambda name: call_filter_dao.find_by(name=name),
                        'CallFilter')
        ],
        edit=[
            Optional(
                'name',
                UniqueFieldChanged('name', call_filter_dao.find_by,
                                   'CallFilter'),
            )
        ],
    )
示例#18
0
def build_validator():
    moh_validator = MOHExists('music_on_hold', moh_dao.get_by)
    return ValidationGroup(
        create=[
            UniqueField('name', lambda name: queue_dao.find_by(name=name),
                        'Queue'),
            QueueValidator(),
            WaitDestinationValidator(),
            moh_validator,
        ],
        edit=[
            Optional('name',
                     UniqueFieldChanged('name', queue_dao.find_by, 'Queue')),
            QueueValidator(),
            WaitDestinationValidator(),
            moh_validator,
        ],
    )
示例#19
0
def build_validator(device_dao, line_dao):
    return ValidationGroup(
        common=[
            Optional(
                'plugin', MemberOfSequence('plugin', device_dao.plugins, 'Plugin')
            ),
            Optional(
                'template_id',
                MemberOfSequence(
                    'template_id', device_dao.device_templates, 'DeviceTemplate'
                ),
            ),
        ],
        create=[
            Optional(
                'mac',
                UniqueField('mac', lambda mac: device_dao.find_by(mac=mac), 'Device'),
            )
        ],
        edit=[Optional('mac', UniqueFieldChanged('mac', device_dao.find_by, 'Device'))],
        delete=[DeviceNotAssociated(line_dao)],
    )
示例#20
0
def build_validator(pjsip_doc):
    sip_find_by = partial(sip_dao_module.find_by, template=False)
    template_find_by = partial(sip_dao_module.find_by, template=True)
    return ValidationGroup(
        create=[
            Optional(
                'name',
                UniqueField('name', lambda v: sip_find_by(name=v),
                            'SIPEndpoint'),
                UniqueField('name', lambda v: template_find_by(name=v),
                            'SIPEndpointTemplate'),
                UniqueField('name', lambda v: transport_dao.find_by(name=v),
                            'Transport'),
            ),
            Optional(
                'aor_section_options',
                PJSIPDocValidator('aor_section_options', 'aor', pjsip_doc),
            ),
            Optional(
                'auth_section_options',
                PJSIPDocValidator('auth_section_options', 'auth', pjsip_doc),
            ),
            Optional(
                'endpoint_section_options',
                PJSIPDocValidator('endpoint_section_options', 'endpoint',
                                  pjsip_doc),
            ),
            Optional(
                'identify_section_options',
                PJSIPDocValidator('identify_section_options', 'identify',
                                  pjsip_doc),
            ),
            Optional(
                'registration_section_options',
                PJSIPDocValidator('registration_section_options',
                                  'registration', pjsip_doc),
            ),
            Optional(
                'registration_outbound_auth_section_options',
                PJSIPDocValidator('registration_outbound_auth_section_options',
                                  'auth', pjsip_doc),
            ),
            Optional(
                'outbound_auth_section_options',
                PJSIPDocValidator('outbound_auth_section_options', 'auth',
                                  pjsip_doc),
            ),
        ],
        edit=[
            EndpointSIPTemplatesValidator(),
            Optional(
                'name',
                UniqueFieldChanged('name',
                                   sip_find_by,
                                   'SIPEndpoint',
                                   id_field='uuid'),
                UniqueFieldChanged('name',
                                   template_find_by,
                                   'SIPEndpointTemplate',
                                   id_field='uuid'),
                UniqueFieldChanged('name',
                                   transport_dao.find_by,
                                   'Transport',
                                   id_field='uuid'),
            ),
            Optional(
                'aor_section_options',
                PJSIPDocValidator('aor_section_options', 'aor', pjsip_doc),
            ),
            Optional(
                'auth_section_options',
                PJSIPDocValidator('auth_section_options', 'auth', pjsip_doc),
            ),
            Optional(
                'endpoint_section_options',
                PJSIPDocValidator('endpoint_section_options', 'endpoint',
                                  pjsip_doc),
            ),
            Optional(
                'identify_section_options',
                PJSIPDocValidator('identify_section_options', 'identify',
                                  pjsip_doc),
            ),
            Optional(
                'registration_section_options',
                PJSIPDocValidator('registration_section_options',
                                  'registration', pjsip_doc),
            ),
            Optional(
                'registration_outbound_auth_section_options',
                PJSIPDocValidator('registration_outbound_auth_section_options',
                                  'auth', pjsip_doc),
            ),
            Optional(
                'outbound_auth_section_options',
                PJSIPDocValidator('outbound_auth_section_options', 'auth',
                                  pjsip_doc),
            ),
        ],
    )
示例#21
0
 def setUp(self):
     self.dao_find = Mock()
     self.validator = UniqueField('field', self.dao_find)