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'
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'
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
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
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
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
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'
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'
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
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
def test_validator_check_matches(): email_validator = Validator(REQUEST) email_validator.validate({'id': [Required, Pattern(r'\d+')]}) assert email_validator.check() is True