Пример #1
0
    def test_length_validator_zero_maximum(self):
        lv = validators.LengthValidator(min_length=None, max_length=0)
        # no problems here
        lv('')

        with self.assertRaises(ValidationError):
            lv('longer than zero chars')
Пример #2
0
    def test_using_validators_on_other_fields(self):
        dict_validator = validators.DictionaryValidator(words=['nostromo'],
                                                        threshold=0.8)
        length_validator = validators.LengthValidator(min_length=2)

        p = CharField(validators=[dict_validator, length_validator])

        p.clean('aa')
        with self.assertRaises(ValidationError):
            p.clean('a')  # too short
        with self.assertRaises(ValidationError):
            p.clean('nostrilomo')  # too much like nostromo
Пример #3
0
    def test_length_validator_explicit_minimum(self):
        lv = validators.LengthValidator(min_length=8, max_length=None)

        # these should all fail validation
        badstrings = '', '1', '1234567', '$%ǟ^&*('
        for bad in badstrings:
            with self.assertRaises(ValidationError):
                lv(bad)

        # these should all pass validation
        goodstrings = '12345678', '^@$%()ǟ^&$@%ǟ_(^$%@ǟ\'\')'
        for good in goodstrings:
            lv(good)
Пример #4
0
 def test_length_validator_no_maximum(self):
     lv = validators.LengthValidator(min_length=None, max_length=None)
     lv('any length is fine')
Пример #5
0
 def test_length_validator_no_minimum(self):
     lv = validators.LengthValidator(min_length=None, max_length=None)
     lv('')