Beispiel #1
0
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)],
    )
Beispiel #2
0
class TestMemberOfSequence(unittest.TestCase):

    def setUp(self):
        self.dao_list = Mock()
        self.validator = MemberOfSequence('field', self.dao_list)

    def test_given_field_not_in_list_of_items_then_raises_error(self):
        model = Mock(field='value')
        self.dao_list.return_value = []

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

    def test_given_field_in_list_then_validation_passes(self):
        model = Mock(field='value')
        self.dao_list.return_value = ['value']

        self.validator.validate(model)
Beispiel #3
0
class TestMemberOfSequence(unittest.TestCase):

    def setUp(self):
        self.dao_list = Mock()
        self.validator = MemberOfSequence('field', self.dao_list)

    def test_given_field_not_in_list_of_items_then_raises_error(self):
        model = Mock(field='value')
        self.dao_list.return_value = []

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

    def test_given_field_in_list_then_validation_passes(self):
        model = Mock(field='value')
        self.dao_list.return_value = ['value']

        self.validator.validate(model)
Beispiel #4
0
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'),
                           ])
Beispiel #5
0
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)])
Beispiel #6
0
 def setUp(self):
     self.dao_list = Mock()
     self.validator = MemberOfSequence('field', self.dao_list)
Beispiel #7
0
 def setUp(self):
     self.dao_list = Mock()
     self.validator = MemberOfSequence('field', self.dao_list)