def test_matching_range(self): with not_raises(ValidationError): Range(min=1, max=5)(1) with not_raises(ValidationError): Range(min=1, max=5)(3) with not_raises(ValidationError): Range(min=1, max=5)(5)
def test_customizing_all_error_messages_at_once(self): message = 'Value is invalid' with raises(ValidationError) as exc_info: Range(min=1, error=message)(0) assert exc_info.value.messages == message with raises(ValidationError) as exc_info: Range(max=1, error=message)(2) == message assert exc_info.value.messages == message with raises(ValidationError) as exc_info: Range(min=1, max=5, error=message)(0) == message assert exc_info.value.messages == message
def test_customzing_max_error_message(self): message = 'Value {data} should be at most {max}' with raises(ValidationError) as exc_info: Range(max=1, error_messages={'max': message})(2) assert exc_info.value.messages == message.format(data=2, max=1)
def test_raising_ValidationError_when_matching_max_value_and_given_value_is_greater( self): with raises(ValidationError) as exc_info: Range(max=1)(2) assert exc_info.value.messages == \ Range.default_error_messages['max'].format(max=1)
def test_matching_max_value(self): with not_raises(ValidationError): Range(max=1)(1) with not_raises(ValidationError): Range(max=1)(0)
def test_customzing_min_error_message(self): message = 'Value {data} should be at least {min}' with raises(ValidationError) as exc_info: Range(min=1, error_messages={'min': message})(0) assert exc_info.value.messages == message.format(data=0, min=1)
def test_raising_ValidationError_when_matching_min_value_and_given_value_is_less( self): with raises(ValidationError) as exc_info: Range(min=1)(0) assert exc_info.value.messages == \ Range.default_error_messages['min'].format(min=1)
def test_customzing_range_error_message(self): message = 'Value {data} should be between {min} and {max}' with raises(ValidationError) as exc_info: Range(min=1, max=5, error_messages={'range': message})(0) assert exc_info.value.messages == message.format(data=0, min=1, max=5)