コード例 #1
0
ファイル: __init__.py プロジェクト: onap/optf-has
def string_or_dict(_object, *args):
    """Validator - Must be Basestring or Dictionary"""
    error_msg = 'not of type dictionary or string'

    if isinstance(_object, six.string_types):
        return
    if isinstance(_object, dict):
        return
    raise exceptions.Invalid('dict or basestring type', pair='value',
                             msg=None, reason=error_msg, *args)
コード例 #2
0
 def test_full_message_for_callable_with_value(self):
     error = exceptions.Invalid(foo, ['foo', 'bar', 'baz'], pair='value')
     result = error.__str__()
     assert "-> foo -> bar -> baz  did not pass validation against callable: foo" == result
コード例 #3
0
 def test_full_message_for_value(self):
     error = exceptions.Invalid('3', ['foo', 'bar', 'baz'], pair='value')
     result = error.__str__()
     assert "-> foo -> bar -> baz  did not match '3'" == result
コード例 #4
0
 def test_full_message(self):
     error = exceptions.Invalid('3', ['foo', 'bar', 'baz'])
     result = error.__str__()
     assert "-> foo -> bar -> baz key did not match '3'" == result
コード例 #5
0
 def test_multiple_keys_in_format_path(self):
     error = exceptions.Invalid('schema', ['key', 'subkey', 'bar'])
     assert '-> key -> subkey -> bar' in error._format_path()
コード例 #6
0
 def test_include_the_key_in_str(self):
     error = exceptions.Invalid('key', ['path'])
     assert 'key' in error.__str__()
コード例 #7
0
 def test_include_the_key(self):
     error = exceptions.Invalid('key', ['foo', 'bar', 'key'])
     assert 'key' in error._format_path()