示例#1
0
def test_custom_error_message():
    email_validator = Validator()
    email_validator.validate({'id': [Required], 'username': [Required]})
    email_validator.messages({'id': 'change your id', 'username': '******'})

    assert email_validator.check({'tomato': 'true'}) is False
    assert email_validator.errors()['id'] == 'change your id'
    assert email_validator.errors()['username'] == 'dont forget your username'
示例#2
0
    def test_custom_error_messages_missing_one(self):
        email_validator = Validator()
        email_validator.validate({'id': [Required]})

        email_validator.messages({'username': '******'})

        assert email_validator.check({'username': '******'}) is False
        assert email_validator.errors()['id'] == 'must be present'
示例#3
0
 def test_validator_can_get_validation_error(self):
     email_validator = Validator()
     email_validator.validate({'id': [Required]})
     assert email_validator.check({'name': '1,2'}) is False
     assert email_validator.error('id') == 'must be present'
     assert email_validator.error('name') == None
示例#4
0
 def test_validator_length(self):
     email_validator = Validator()
     email_validator.validate({'id': [Length(0, maximum=2)]})
     assert email_validator.check({'id': [1, 2, 3, 4, 5]}) is False
示例#5
0
 def test_validator_errors_returns_false(self):
     email_validator = Validator()
     email_validator.validate({'id': [Required, Pattern(r'\d+')]})
     assert email_validator.check({'id': '4'}) is True
     assert email_validator.errors() is None
示例#6
0
 def test_validator_check_matches_without_request(self):
     email_validator = Validator()
     email_validator.validate({'id': [Required, Pattern(r'\d+')]})
     assert email_validator.check({'id': '4'}) is True
示例#7
0
 def test_validator_error_without_request(self):
     email_validator = Validator()
     email_validator.validate({'username': [Required]})
     assert email_validator.check({'id': 5}) is False
     assert email_validator.errors()['username'] == 'must be present'
示例#8
0
 def test_validator_error(self):
     email_validator = Validator(self.request)
     email_validator.validate({'username': [Required]})
     assert email_validator.check() is False
     assert email_validator.errors()['username'] == 'must be present'
示例#9
0
 def test_validator_check_matches(self):
     email_validator = Validator(self.request)
     email_validator.validate({'id': [Required, Pattern(r'\d+')]})
     assert email_validator.check() is True
示例#10
0
 def test_validator_check_does_not_match(self):
     email_validator = Validator(self.request)
     email_validator.validate({'id': [Required, Pattern('[a-zA-Z]')]})
     assert email_validator.check() is False
示例#11
0
 def test_email_validator_sets_dictionary(self):
     email_validator = Validator(self.request)
     email_validator.validate({'id': 1})
     assert email_validator.validation_dictionary == {'id': 1}
示例#12
0
 def test_validator_sets_request(self):
     validator = Validator(self.request)
     assert validator.request is self.request
示例#13
0
def test_validator_check_matches():
    email_validator = Validator(REQUEST)
    email_validator.validate({'id': [Required, Pattern(r'\d+')]})
    assert email_validator.check() is True
示例#14
0
def test_email_validator_sets_dictionary():
    email_validator = Validator(REQUEST)
    email_validator.validate({'id': 1})
    assert email_validator.validation_dictionary == {'id': 1}
示例#15
0
def test_validator_sets_request():
    validator = Validator(REQUEST)

    assert validator.request is REQUEST