def test_between_malformed_non_integer(self): v = Validator() try: v.make(fields = {'test': '5char'}, rules = {'test': 'between:omagad,omagaaaad'}) except ValueError as e: self.assertRaisesRegexp(e, 'constraint is not a valid integer')
def test_between_malformed(self): v = Validator() try: v.make(fields = {'test': '5char'}, rules = {'test': 'between'}) except ValueError as e: self.assertRaisesRegexp(e, 'constraints are missing from the validation rule')
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())
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())
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())
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())