Exemplo n.º 1
0
class TestFindResource(unittest.TestCase):

    def setUp(self):
        self.dao_find = Mock()
        self.validator = FindResource('field', self.dao_find)

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

        self.dao_find.return_value = None

        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_find.assert_called_once_with(model.field)
Exemplo n.º 2
0
class TestFindResource(unittest.TestCase):

    def setUp(self):
        self.dao_find = Mock()
        self.validator = FindResource('field', self.dao_find)

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

        self.dao_find.return_value = None

        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_find.assert_called_once_with(model.field)
Exemplo n.º 3
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)])
Exemplo n.º 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'),
                           ])
Exemplo n.º 5
0
 def setUp(self):
     self.dao_find = Mock()
     self.validator = FindResource('field', self.dao_find)
Exemplo n.º 6
0
 def setUp(self):
     self.dao_find = Mock()
     self.validator = FindResource('field', self.dao_find)