示例#1
0
    def test_direct_validate_fail(self):
        v = Validator()

        v.validate('gibberish', 'url')

        self.assertTrue(v.fails())
        self.assertTrue('gibberish must be a valid url' in v.errors())
示例#2
0
    def test_direct_validate_multiple_fail(self):
        v = Validator()

        v.validate(22, 'min:43')

        self.assertTrue(v.fails())
        self.assertTrue('22 must be higher than 43' in v.errors())
示例#3
0
    def test_direct_validate_pass(self):
        v = Validator()

        v.validate('http://google.com', 'url')

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#4
0
    def test_custom_rule_fail(self):
        v = Validator()
        v.extend({'myrule': self.customRule})

        v.make(fields = {'test': 5}, rules = {'test': 'myrule'}, messages = {'myrule' : '{0} is not equal to 1'})

        self.assertTrue(v.fails())
        self.assertTrue('test is not equal to 1' in v.errors())
示例#5
0
    def test_wellformed_all_validation_pass_message_reset_pass(self):

        fields = {'myField': 'itsa me, mario !'}
        rules = {'myField': 'required'}

        messages = {'required': '{} is required'}

        v = Validator(fields = fields, rules = rules, messages = messages)

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#6
0
    def test_email_locale_jp_fail(self):
        
        i18n.switch_language('ja')

        v = Validator(fields = {'test': 'bademail.com'}, rules = {'test': 'email'})

        self.assertTrue(v.fails())

        self.assertTrue('testに正しい形式をご指定ください。' in v.errors())

        ### Switching back locale to English to avoid that other tests fail ! ###
        i18n.switch_language('en')
示例#7
0
    def test_wellformed_all_validation_fail(self):

        fields = {'myField': ''}
        rules = {'myField': 'required'}

        """ Error message is the opposite of the "rule" on purpose """
        messages = {'required': '{} is never required'}

        v = Validator(fields = fields, rules = rules, messages = messages)

        self.assertTrue(v.fails())
        self.assertTrue('myField is never required' in v.errors())
示例#8
0
    def test_email_locale_fr_fail(self):
        
        i18n.switch_language('fr')

        v = Validator(fields = {'test': 'bademail.com'}, rules = {'test': 'email'})

        self.assertTrue(v.fails())

        self.assertTrue('test doit être un email valide' in v.errors())

        ### Switching back locale to English to avoid that other tests fail ! ###
        i18n.switch_language('en')
示例#9
0
    def test_wellformed_all_validation_pass(self):

        fields = {'myField': 'itsa me, mario !'}
        rules = {'myField': 'required'}

        """ Error message is the opposite of the "rule" on purpose """
        messages = {'required': '{} is never required'}

        v = Validator(fields = fields, rules = rules, messages = messages)

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#10
0
    def test_method_extend_pass_pass(self):
        messages = {'new_rule': '{} is less than 10 !!'}
        new_rule = {'new_rule': self.good_method}
        fields = {'cars': 12}
        rules = {'cars': 'new_rule'}

        v = Validator()
        v.extend(new_rule)

        v.make(fields = fields, rules = rules, messages = messages)

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#11
0
    def test_multile_fields_rule_fail(self):
        v = Validator()

        to_test = {
            'name': 'Ken',
            'email': 'ken.fake-email.com',
        }

        rules = {
            'name': 'required',
            'email': 'required|email',
        }

        v.make(fields = to_test, rules = rules)

        self.assertTrue(v.fails())
        self.assertTrue('email must be a valid email' in v.errors())
示例#12
0
    def test_multile_fields_rule_pass(self):
        v = Validator()

        to_test = {
            'name': 'Ken',
            'email': '*****@*****.**',
        }

        rules = {
            'name': 'required',
            'email': 'required|email',
        }

        v.make(fields = to_test, rules = rules)

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#13
0
    def test_between_string_fail(self):
        v = Validator(fields = {'test': '7charss'}, rules = {'test': 'between:8,10'})

        self.assertTrue(v.fails())
        self.assertTrue('test\'s length must be between 8 and 10 characters' in v.errors())
示例#14
0
    def test_multiple_rule_fail2(self):
        v = Validator(fields = {'test': 'myvalue'}, rules = {'test': 'required|email'})

        self.assertTrue(v.fails())
        self.assertTrue('test is required' not in v.errors())
        self.assertTrue('test must be a valid email' in v.errors())
示例#15
0
    def test_multiple_rule_pass(self):
        v = Validator(fields = {'test': '*****@*****.**'}, rules = {'test': 'required|email'})

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#16
0
    def test_email_malformed(self):
        v = Validator(fields = {'test': 'fake.email.com'}, rules = {'test': 'email'})

        self.assertTrue(v.fails())
        self.assertTrue('test must be a valid email' in v.errors())
示例#17
0
    def test_required_pass(self):
        v = Validator(fields = {'test': 'myvalue'}, rules = {'test': 'required'})

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#18
0
    def test_date_rule_fail(self):
        v = Validator(fields = {'test': '2451-df-1234'}, rules = {'test': 'date:%Y-%m-%d'})

        self.assertTrue(v.fails())
        self.assertTrue('test is not a valid date, the format must be %Y-%m-%d' in v.errors())
示例#19
0
    def test_integer_as_string_fail(self):
        v = Validator(fields = {'test': '-10a'}, rules = {'test': 'integer'})

        self.assertTrue(v.fails())
        self.assertTrue("test must be an integer" in v.errors())
示例#20
0
    def test_max_integer_fail(self):
        v = Validator(fields = {'test': 5}, rules = {'test': 'max:4'})

        self.assertTrue(v.fails())
        self.assertTrue('test must be lower than 4' in v.errors())
示例#21
0
    def test_max_string_fail(self):
        v = Validator(fields = {'test': '7charss'}, rules = {'test': 'max:6'})

        self.assertTrue(v.fails())
        self.assertTrue('test must be less than 6 characters' in v.errors())
示例#22
0
    def test_min_integer_fail(self):
        v = Validator(fields = {'test': 5}, rules = {'test': 'min:6'})

        self.assertTrue(v.fails())
        self.assertTrue('test must be higher than 6' in v.errors())
示例#23
0
    def test_min_string_fail(self):
        v = Validator(fields = {'test': '5char'}, rules = {'test': 'min:6'})

        self.assertTrue(v.fails())
        self.assertTrue('test must be more than 6 characters' in v.errors())
示例#24
0
    def test_email_pass(self):
        v = Validator(fields = {'test': '*****@*****.**'}, rules = {'test': 'email'})

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#25
0
    def test_date_rule_pass(self):
        v = Validator(fields = {'test': '2451-09-12'}, rules = {'test': 'date:%Y-%m-%d'})

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#26
0
    def test_between_integer_fail(self):
        v = Validator(fields = {'test': 5}, rules = {'test': 'between:8,10'})

        self.assertTrue(v.fails())
        self.assertTrue('test\'s value must be higher than 8 and lower than 10' in v.errors())
示例#27
0
    def test_integer_as_integer_pass(self):
        v = Validator(fields = {'test': 25}, rules = {'test': 'integer'})

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#28
0
    def test_between_string_integer_pass(self):
        v = Validator(fields = {'test': '9'}, rules = {'test': 'between:8,10'})

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#29
0
    def test_max_string_integer_pass(self):
        v = Validator(fields = {'test': '7'}, rules = {'test': 'max:8'})

        self.assertFalse(v.fails())
        self.assertFalse(v.errors())
示例#30
0
    def test_required_empty(self):
        v = Validator(fields = {'test': ''}, rules = {'test': 'required'})

        self.assertTrue(v.fails())
        self.assertTrue('test is required' in v.errors())