本文整理汇总了Python中txaws.server.schema.Schema.extend方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.extend方法的具体用法?Python Schema.extend怎么用?Python Schema.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txaws.server.schema.Schema
的用法示例。
在下文中一共展示了Schema.extend方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extend_errors
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extend [as 别名]
def test_extend_errors(self):
"""
Errors can be extended with L{Schema.extend}.
"""
schema = Schema(parameters=[], errors=[APIError])
schema2 = schema.extend(errors=[ZeroDivisionError])
self.assertEqual(set([APIError, ZeroDivisionError]), schema2.errors)
示例2: test_extend_maintains_existing_attributes
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extend [as 别名]
def test_extend_maintains_existing_attributes(self):
"""
If additional schema attributes aren't passed to L{Schema.extend}, they
stay the same.
"""
result = {'id': Integer(), 'name': Unicode(), 'data': RawStr()}
errors = [APIError]
schema = Schema(
name="GetStuff",
doc="""Get the stuff.""",
parameters=[Integer("id")],
result=result,
errors=errors)
schema2 = schema.extend(parameters=[Unicode("scope")])
self.assertEqual("GetStuff", schema2.name)
self.assertEqual("Get the stuff.", schema2.doc)
self.assertEqual(result, schema2.result)
self.assertEqual(set(errors), schema2.errors)
arguments, _ = schema2.extract({'id': '5', 'scope': u'foo'})
self.assertEqual(5, arguments.id)
self.assertEqual(u'foo', arguments.scope)
示例3: test_extend_with_additional_schema_attributes
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extend [as 别名]
def test_extend_with_additional_schema_attributes(self):
"""
The additional schema attributes can be passed to L{Schema.extend}.
"""
result = {'id': Integer(), 'name': Unicode(), 'data': RawStr()}
errors = [APIError]
schema = Schema(
name="GetStuff",
parameters=[Integer("id")])
schema2 = schema.extend(
name="GetStuff2",
doc="Get stuff 2",
parameters=[Unicode("scope")],
result=result,
errors=errors)
self.assertEqual("GetStuff2", schema2.name)
self.assertEqual("Get stuff 2", schema2.doc)
self.assertEqual(result, schema2.result)
self.assertEqual(set(errors), schema2.errors)
arguments, _ = schema2.extract({'id': '5', 'scope': u'foo'})
self.assertEqual(5, arguments.id)
self.assertEqual(u'foo', arguments.scope)
示例4: test_add_single_extra_schema_item
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extend [as 别名]
def test_add_single_extra_schema_item(self):
"""New Parameters can be added to the Schema."""
schema = Schema(Unicode("name"))
schema = schema.extend(Unicode("computer"))
arguments, _ = schema.extract({"name": "value", "computer": "testing"})
self.assertEqual(u"value", arguments.name)
self.assertEqual("testing", arguments.computer)
示例5: test_extend_maintains_parameter_order
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extend [as 别名]
def test_extend_maintains_parameter_order(self):
"""
Extending a schema with additional parameters puts the new parameters
at the end.
"""
schema = Schema(parameters=[Unicode("name"), Unicode("value")])
schema2 = schema.extend(parameters=[Integer("foo"), Unicode("index")])
self.assertEqual(["name", "value", "foo", "index"],
[p.name for p in schema2.get_parameters()])
示例6: test_add_extra_schema_items
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extend [as 别名]
def test_add_extra_schema_items(self):
"""A list of new Parameters can be added to the Schema."""
schema = Schema(Unicode("name"))
schema = schema.extend(Unicode("computer"), Integer("count"))
arguments, _ = schema.extract({"name": "value", "computer": "testing",
"count": "5"})
self.assertEqual(u"value", arguments.name)
self.assertEqual("testing", arguments.computer)
self.assertEqual(5, arguments.count)
示例7: test_extend_result
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extend [as 别名]
def test_extend_result(self):
"""
Result fields can also be extended with L{Schema.extend}.
"""
schema = Schema(result={'name': Unicode()})
schema2 = schema.extend(
result={'id': Integer()})
result_structure = Structure(fields=schema2.result)
self.assertEqual(
{'name': u'foo', 'id': 5},
result_structure.coerce({'name': u'foo', 'id': '5'}))