本文整理汇总了Python中notario.validate函数的典型用法代码示例。如果您正苦于以下问题:Python validate函数的具体用法?Python validate怎么用?Python validate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_nested_raises_nested_invalid
def test_nested_raises_nested_invalid(self):
data = {'a': [{'a': ['a']}, {'b': 'c'}]}
nested_schema = iterables.MultiIterable(('a', ['b']), ('b', 'c'))
schema = ('a', iterables.AllItems(nested_schema))
with raises(Invalid) as exc:
validate(data, schema)
assert exc.value.reason == 'expected a list but got dict'
开发者ID:alfredodeza,项目名称:notario,代码行数:7,代码来源:test_functional.py
示例2: test_all_items_fail
def test_all_items_fail(self):
def fail(value): raise AssertionError
data = {'a': 'some string'}
schema = ('a', chainable.AnyIn(types.boolean, fail))
with raises(Invalid) as exc:
validate(data, schema)
assert exc.value.args[0] == '-> a did not pass validation against callable: AnyIn'
开发者ID:coxmediagroup,项目名称:notario,代码行数:7,代码来源:test_functional.py
示例3: test_one_item_fails
def test_one_item_fails(self):
data = {'a': 'some string'}
schema = ('a', chainable.AllIn(types.string, types.boolean))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert '-> a -> some string did not pass validation against callable: AllIn -> boolean' in error
开发者ID:alfredodeza,项目名称:notario,代码行数:7,代码来源:test_functional.py
示例4: test_all_objects_fail_non_callable
def test_all_objects_fail_non_callable(self):
data = {'a': {'a': 1, 'b': 1, 'c': 1}}
schema = ('a', recursive.AllObjects((types.string, 2)))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert '-> a -> a -> 1 did not match 2' in error
开发者ID:alfredodeza,项目名称:notario,代码行数:7,代码来源:test_functional.py
示例5: test_all_items_fail_length
def test_all_items_fail_length(self):
data = {"a": [{"a": 2}, {"b": {"a": "b"}}]}
schema = ("a", iterables.AllItems((types.string, 2)))
with raises(SchemaError) as exc:
validate(data, schema)
error = exc.value.args[0]
assert "-> a -> b has less items in schema than in data" in error
开发者ID:alfredodeza,项目名称:notario,代码行数:7,代码来源:test_functional.py
示例6: wrapped
def wrapped(*args, **kwargs):
request.validation_error = None
if request.method in ('POST', 'PUT'):
try:
body = request.body.decode()
if not body:
raise ValueError('No JSON object could be decoded')
data = json.loads(body)
notario.validate(data, schema)
except (Invalid, ValueError) as error:
# TODO: It would be nice if we could have a sane default
# here where we set the response body instead of requiring
# a handler
request.validation_error = error
if handler:
redirect_to_handler(error, handler)
# a controller can say `handler=False` to signal they don't
# want to delegate, not even to the fallback
if handler is None:
headers = {'Content-Type': 'application/json'}
raise JSONValidationException(
detail=error,
headers=headers
)
return f(*args, **kwargs)
开发者ID:alfredodeza,项目名称:pecan-notario,代码行数:27,代码来源:decorator.py
示例7: test_multi_pair_non_nested_third_key
def test_multi_pair_non_nested_third_key(self):
data = {'a': 'a', 'b':'b', 'c':'c', 'd':'d'}
schema = (('a', 'a'), ('b', 'b'), ('f', 'c'), ('d', 'a'))
with raises(Invalid) as exc:
validate(data, schema)
assert exc.value.args[0] == "-> c key did not match 'f'"
开发者ID:coxmediagroup,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例8: test_multi_pair_non_nested_second
def test_multi_pair_non_nested_second(self):
data = {'a': 'a', 'b':'b', 'c':'c', 'd':'d'}
schema = (('a', 'a'), ('b', 'a'), ('c', 'c'), ('d', 'd'))
with raises(Invalid) as exc:
validate(data, schema)
assert exc.value.args[0] == "-> b -> b did not match 'a'"
开发者ID:coxmediagroup,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例9: test_all_objects_fail
def test_all_objects_fail(self):
data = {'a': {'a': 1, 'b': 'a string', 'c': 3}}
schema = ('a', recursive.AllObjects((types.string, types.integer)))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert '-> a -> b -> a string did not pass validation against callable: integer' in error
assert 'not of type int' in error
开发者ID:alfredodeza,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例10: test_any_item_with_dictionaries
def test_any_item_with_dictionaries(self):
data = {'a': [{'a': 1}, {'b': 2}]}
schema = ('a', iterables.AnyItem(('c', 4)))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert "-> a -> list[] did not contain any valid items matching ('c', 4)" in error
开发者ID:alfredodeza,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例11: test_any_items_fail
def test_any_items_fail(self):
data = {'a': [1, 2, 3, 4, 5]}
schema = ('a', iterables.AnyItem(types.string))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert '-> a -> list[] did not contain any valid items against callable: string' in error
开发者ID:alfredodeza,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例12: test_all_objects_fail_length
def test_all_objects_fail_length(self):
data = {"a": {"a": 2, "b": {"a": "b"}}}
schema = ("a", recursive.AllObjects((types.string, 2)))
with raises(SchemaError) as exc:
validate(data, schema)
error = exc.value.args[0]
assert "-> a -> b has less items in schema than in data" in error
开发者ID:alfredodeza,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例13: test_all_items_fail_non_callable
def test_all_items_fail_non_callable(self):
data = {'a': [1, 2, '3', 4, 5]}
schema = ('a', iterables.AllItems('foo'))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert "-> a -> list[0] item did not match 'foo'" in error
开发者ID:alfredodeza,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例14: test_any_objects_fail_non_callable
def test_any_objects_fail_non_callable(self):
data = {"a": {"a": 1, "b": 4, "c": 3}}
schema = ("a", recursive.AnyObject(("a", "a")))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert "-> a did not contain any valid objects against callable: AnyObject" in error
开发者ID:alfredodeza,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例15: test_any_items_fail_non_callable
def test_any_items_fail_non_callable(self):
data = {'a': [1, 2, 3, 4, 5]}
schema = ('a', iterables.AnyItem('foo'))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert "-> a -> list[] did not contain any valid items matching 'foo'" in error
开发者ID:alfredodeza,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例16: test_no_pollution_from_previous_traversing_all_items
def test_no_pollution_from_previous_traversing_all_items(self):
data = {"a": {"a": 1, "b": 2}, "b": {"c": 1, "d": 2}, "c": ["e", 1, "f", 2]}
schema = (("a", (("a", 1), ("b", 2))), ("b", (("c", 1), ("d", 2))), ("c", iterables.AllItems(types.string)))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert "not of type string" in error
assert "-> c -> list[1] item did not pass validation against callable: string" in error
开发者ID:alfredodeza,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例17: test_all_items_fail
def test_all_items_fail(self):
data = {'a': [1, 2, '3', 4, 5]}
schema = ('a', iterables.AllItems(types.integer))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert 'not of type int' in error
assert '-> a -> list[2] item did not pass validation against callable: integer' in error
开发者ID:alfredodeza,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例18: test_most_simple_validation
def test_most_simple_validation(self):
data = {'a': 'a'}
schema = (('a', 'b'))
with raises(Invalid) as exc:
validate(data, schema)
assert exc.value.args[0] == "-> a -> a did not match 'b'"
开发者ID:coxmediagroup,项目名称:notario,代码行数:8,代码来源:test_functional.py
示例19: test_multi_pair_non_nested_first
def test_multi_pair_non_nested_first(self):
data = {'a': 'a', 'b':'b', 'c':'c', 'd':'d'}
schema = (('a', 'b'), ('b', 'b'), ('c', 'c'), ('d', 'd'))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert "-> a -> a did not match 'b'" in error
开发者ID:alfredodeza,项目名称:notario,代码行数:9,代码来源:test_functional.py
示例20: test_key_is_empty_string
def test_key_is_empty_string(self):
data = {'a': ''}
schema = (('a', 'b'))
with raises(Invalid) as exc:
validate(data, schema)
error = exc.value.args[0]
assert "-> a -> '' did not match 'b'" in error
开发者ID:alfredodeza,项目名称:notario,代码行数:9,代码来源:test_functional.py
注:本文中的notario.validate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论