Beispiel #1
0
def build_validator():
    return AssociationValidator(
        common=[
            MissingFields(),
            GetResource('user_id', user_dao.get, 'User'),
            GetResource('voicemail_id', voicemail_dao.get, 'Voicemail')
        ],
        association=[
            UserHasNoVoicemail(user_voicemail_dao)
        ]
    )
Beispiel #2
0
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])
Beispiel #3
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 #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
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)
                           ])
Beispiel #6
0
 def setUp(self):
     self.dao_get = Mock()
     self.validator = GetResource('field', self.dao_get)
Beispiel #7
0
 def setUp(self):
     self.dao_get = Mock()
     self.validator = GetResource('field', self.dao_get)