mirror of https://github.com/zulip/zulip.git
validators: Improve error messages for check_capped_string.
This commit is contained in:
parent
8729c9001d
commit
976e61d687
|
@ -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
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue