mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-09-03 20:52:56 -05:00
Internationalization for public errors
Currently, we throw many public exceptions without proper i18n. Wrap natural-language error messages in _() so they can be translated. In the service plugin, raise NotFound errors using handle_not_found helper so the error message contains the offending service. Use ScriptError instead of NotFoundError in bindinstance install. https://fedorahosted.org/freeipa/ticket/1953
This commit is contained in:
committed by
Martin Kosek
parent
4f03aed5e6
commit
a95eaeac8e
@@ -200,44 +200,44 @@ class test_jsonserver(PluginTester):
|
||||
# Test with invalid JSON-data:
|
||||
e = raises(errors.JSONError, o.unmarshal, 'this wont work')
|
||||
assert isinstance(e.error, ValueError)
|
||||
assert str(e.error) == 'No JSON object could be decoded'
|
||||
assert unicode(e.error) == 'No JSON object could be decoded'
|
||||
|
||||
# Test with non-dict type:
|
||||
e = raises(errors.JSONError, o.unmarshal, json.dumps([1, 2, 3]))
|
||||
assert str(e.error) == 'Request must be a dict'
|
||||
assert unicode(e.error) == 'Request must be a dict'
|
||||
|
||||
params = [[1, 2], dict(three=3, four=4)]
|
||||
# Test with missing method:
|
||||
d = dict(params=params, id=18)
|
||||
e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
|
||||
assert str(e.error) == 'Request is missing "method"'
|
||||
assert unicode(e.error) == 'Request is missing "method"'
|
||||
|
||||
# Test with missing params:
|
||||
d = dict(method='echo', id=18)
|
||||
e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
|
||||
assert str(e.error) == 'Request is missing "params"'
|
||||
assert unicode(e.error) == 'Request is missing "params"'
|
||||
|
||||
# Test with non-list params:
|
||||
for p in ('hello', dict(args=tuple(), options=dict())):
|
||||
d = dict(method='echo', id=18, params=p)
|
||||
e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
|
||||
assert str(e.error) == 'params must be a list'
|
||||
assert unicode(e.error) == 'params must be a list'
|
||||
|
||||
# Test with other than 2 params:
|
||||
for p in ([], [tuple()], [None, dict(), tuple()]):
|
||||
d = dict(method='echo', id=18, params=p)
|
||||
e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
|
||||
assert str(e.error) == 'params must contain [args, options]'
|
||||
assert unicode(e.error) == 'params must contain [args, options]'
|
||||
|
||||
# Test when args is not a list:
|
||||
d = dict(method='echo', id=18, params=['args', dict()])
|
||||
e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
|
||||
assert str(e.error) == 'params[0] (aka args) must be a list'
|
||||
assert unicode(e.error) == 'params[0] (aka args) must be a list'
|
||||
|
||||
# Test when options is not a dict:
|
||||
d = dict(method='echo', id=18, params=[('hello', 'world'), 'options'])
|
||||
e = raises(errors.JSONError, o.unmarshal, json.dumps(d))
|
||||
assert str(e.error) == 'params[1] (aka options) must be a dict'
|
||||
assert unicode(e.error) == 'params[1] (aka options) must be a dict'
|
||||
|
||||
# Test with valid values:
|
||||
args = [u'jdoe']
|
||||
|
||||
@@ -69,14 +69,16 @@ class test_service(Declarative):
|
||||
dict(
|
||||
desc='Try to update non-existent %r' % service1,
|
||||
command=('service_mod', [service1], dict(usercertificate=servercert)),
|
||||
expected=errors.NotFound(reason='no such entry'),
|
||||
expected=errors.NotFound(
|
||||
reason=u'%s: service not found' % service1),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Try to delete non-existent %r' % service1,
|
||||
command=('service_del', [service1], {}),
|
||||
expected=errors.NotFound(reason='no such entry'),
|
||||
expected=errors.NotFound(
|
||||
reason=u'%s: service not found' % service1),
|
||||
),
|
||||
|
||||
|
||||
@@ -457,14 +459,16 @@ class test_service(Declarative):
|
||||
dict(
|
||||
desc='Try to update non-existent %r' % service1,
|
||||
command=('service_mod', [service1], dict(usercertificate=servercert)),
|
||||
expected=errors.NotFound(reason='no such entry'),
|
||||
expected=errors.NotFound(
|
||||
reason=u'%s: service not found' % service1),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Try to delete non-existent %r' % service1,
|
||||
command=('service_del', [service1], {}),
|
||||
expected=errors.NotFound(reason='no such entry'),
|
||||
expected=errors.NotFound(
|
||||
reason=u'%s: service not found' % service1),
|
||||
),
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user