本文整理汇总了Python中colander.SchemaNode方法的典型用法代码示例。如果您正苦于以下问题:Python colander.SchemaNode方法的具体用法?Python colander.SchemaNode怎么用?Python colander.SchemaNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colander
的用法示例。
在下文中一共展示了colander.SchemaNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_required
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_required(self):
class Mapping(colander.MappingSchema):
foo = colander.SchemaNode(colander.String())
node = Mapping()
ret = convert(node)
self.assertDictEqual(ret, {
'type': 'object',
'properties': {
'foo': {
'title': 'Foo',
'type': 'string'
}
},
'required': ['foo']
})
示例2: test_not_required
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_not_required(self):
class Mapping(colander.MappingSchema):
foo = colander.SchemaNode(colander.String(),
missing=colander.drop)
node = Mapping()
ret = convert(node)
self.assertDictEqual(ret, {
'type': 'object',
'properties': {
'foo': {
'title': 'Foo',
'type': 'string'
}
},
})
示例3: from_path
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def from_path(self, path):
"""
Create a list of Swagger path params from a cornice service path.
:type path: string
:rtype: list
"""
path_components = path.split('/')
param_names = [comp[1:-1] for comp in path_components
if comp.startswith('{') and comp.endswith('}')]
params = []
for name in param_names:
param_schema = colander.SchemaNode(colander.String(), name=name)
param = self.parameter_converter('path', param_schema)
if self.ref:
param = self._ref(param)
params.append(param)
return params
示例4: create
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def create():
require.dataset.create()
dataset = request_data()
data = validate_dataset(dataset)
if Dataset.by_name(data['name']) is not None:
raise Invalid(SchemaNode(String(), name='name'),
_("A dataset with this identifer already exists!"))
dataset = Dataset({'dataset': data, 'model': {}})
dataset.managers.append(current_user)
db.session.add(dataset)
db.session.commit()
return view(dataset.name)
示例5: define_date_node
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def define_date_node(schema):
schema['vote'] = colander.SchemaNode(
colander.DateTime(),
widget=deform.widget.DateTimeInputWidget(),
validator=colander.Range(min=datetime.datetime.now(tz=pytz.UTC),
min_err=_('${val} is earlier than earliest datetime ${min}')),
title=_('Date')
)
示例6: test_path
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_path(self):
node = colander.SchemaNode(colander.String(), name='foo')
ret = convert_parameter('path', node)
self.assertDictEqual(ret, {
'in': 'path',
'name': 'foo',
'type': 'string',
'required': True,
})
示例7: test_query
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_query(self):
node = colander.SchemaNode(colander.String(), name='bar')
ret = convert_parameter('querystring', node)
self.assertDictEqual(ret, {
'in': 'query',
'name': 'bar',
'type': 'string',
'required': True,
})
示例8: test_query_array
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_query_array(self):
class MyArray(colander.SequenceSchema):
values = colander.SchemaNode(colander.String())
node = MyArray(name='bar')
ret = convert_parameter('querystring', node)
self.assertDictEqual(ret, {
'in': 'query',
'name': 'bar',
'type': 'array',
'items': {'type': 'string'},
'required': True,
})
示例9: test_header
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_header(self):
node = colander.SchemaNode(colander.String(), name='meh')
ret = convert_parameter('headers', node)
self.assertDictEqual(ret, {
'in': 'header',
'name': 'meh',
'type': 'string',
'required': True,
})
示例10: test_body_array
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_body_array(self):
class MyArray(colander.SequenceSchema):
values = colander.SchemaNode(colander.String())
node = MyArray(name='bla')
ret = convert_parameter('body', node)
self.assertDictEqual(ret, {
'in': 'body',
'name': 'bla',
'required': True,
'schema': convert_schema(MyArray(title='MyArray')),
})
示例11: test_supports_description
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_supports_description(self):
node = colander.SchemaNode(colander.String(), name='bar', description='tyred')
ret = convert_parameter('querystring', node)
self.assertDictEqual(ret, {
'in': 'query',
'name': 'bar',
'type': 'string',
'required': True,
'description': 'tyred',
})
示例12: test_raise_no_such_converter_on_invalid_location
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_raise_no_such_converter_on_invalid_location(self):
node = colander.SchemaNode(colander.String(), name='foo')
self.assertRaises(NoSuchConverter, convert_parameter, 'aaa', node)
示例13: test_validate_all
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_validate_all(self):
node = colander.SchemaNode(colander.String(),
validator=colander.All(
colander.Length(12, 42),
colander.Regex(r'foo*bar')
))
ret = convert(node)
self.assertDictEqual(ret, {
'type': 'string',
'pattern': 'foo*bar',
'maxLength': 42,
'minLength': 12,
})
示例14: test_support_custom_converters
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_support_custom_converters(self):
node = colander.SchemaNode(AnyType())
custom_converters = {AnyType: AnyTypeConverter}
converter = TypeConversionDispatcher(custom_converters)
ret = converter(node)
self.assertEquals(ret, {})
示例15: test_support_default_converter
# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_support_default_converter(self):
node = colander.SchemaNode(AnyType())
converter = TypeConversionDispatcher(default_converter=AnyTypeConverter)
ret = converter(node)
self.assertEquals(ret, {})