validators: Improve error messages for check_capped_string.

This commit is contained in:
Tim Abbott 2018-04-30 10:06:42 -07:00
parent 8729c9001d
commit 976e61d687
3 changed files with 5 additions and 5 deletions

View File

@ -59,7 +59,7 @@ def check_capped_string(max_length: int) -> Callable[[str, object], Optional[str
if not isinstance(val, str):
return _('%s is not a string') % (var_name,)
if len(val) >= max_length:
return _("{var_name} is longer than {max_length}.".format(
return _("{var_name} is too long (limit: {max_length} characters).".format(
var_name=var_name, max_length=max_length))
return None
return validator

View File

@ -40,7 +40,7 @@ class CustomProfileFieldTest(ZulipTestCase):
data["hint"] = "*" * 81
data["field_type"] = CustomProfileField.SHORT_TEXT
result = self.client_post("/json/realm/profile_fields", info=data)
msg = "hint is longer than 80."
msg = "hint is too long (limit: 80 characters)."
self.assert_json_error(result, msg)
data["name"] = "Phone"
@ -162,7 +162,7 @@ class CustomProfileFieldTest(ZulipTestCase):
info={'name': 'New phone number',
'hint': '*' * 81,
'field_type': CustomProfileField.SHORT_TEXT})
msg = "hint is longer than 80."
msg = "hint is too long (limit: 80 characters)."
self.assert_json_error(result, msg)
result = self.client_patch(
@ -251,7 +251,7 @@ class CustomProfileDataTest(ZulipTestCase):
})
self.assert_json_error(
result,
u"value[{}] is longer than 50.".format(field.id))
u"value[{}] is too long (limit: 50 characters).".format(field.id))
def test_update_profile_data(self) -> None:
self.login(self.example_email("iago"))

View File

@ -572,7 +572,7 @@ class ValidatorTestCase(TestCase):
self.assertEqual(check_short_string('x', x), None)
x = 'x' * 201
self.assertEqual(check_short_string('x', x), 'x is longer than 50.')
self.assertEqual(check_short_string('x', x), "x is too long (limit: 50 characters).")
x = 4
self.assertEqual(check_short_string('x', x), 'x is not a string')